# Programmatically drawing a “pencil” line or curve

If you look closely (scan it on a computer and zoon in) at a carbon pencil line you can see that there are differing shades of gray. I tried looking on the Internet for any kind of algorithm or statistical model for how that gray would be drawn programatically. Does anyone have information on this? Thanks a lot!!

I want to make drawings on a computer that look they were drawn with a pencil.

-
Can you provide a picture of what you are hoping to achieve? – ClassicThunder Feb 9 '12 at 21:52

Depending what tool you're using to draw the line to the screen will change the solution to this question, but the simplest method would be to have the intensity of line color be a function of its distance to the center of the line. Therefore you would have a black line that greys out at the edges.

The other form that you could be talking about was the fact that paper is not perfectly smooth, thus the pencil will be darker on the hills and lighter on the valleys (on a minute scale of course). To do this you could just apply a couple of layers of noise in different shades of grey over your black pencil lines.

The are further methods that come to mind, but they all depend on how you're actually planning on drawing to screen.

For further research you can look into how digital artists fake pencil effects and see if any of those methods translate well into a programmable method.

-

It sounds like you're looking to implement something similar to anti-aliasing on whatever lines you're drawing. The high overview of anti-aliasing is it aims to reduce the jagged edges we perceive on pixelated lines by shading the pixels surrounding the line, so that the line fades into the background color. The result will look very much like the pencil effect you're describing.

This article gives a very good explanation and sample implementation of anti-aliasing.

Hope this helps :)

-
Curious as to how you got anything about fixing jagged edges out of the question? – ClassicThunder Feb 9 '12 at 22:08
Nick mentioned the different shades of gray that are present in a close-up of a line drawn in pencil, which arise from different pressures that parts of the pencil tip exert on the paper. It's likely that the most pressure will be in the center (darker), and the pressure fades towards the outside of the line (lighter). This is exactly what anti-aliasing does. One could tweak the algorithm a bit to produce a slightly more accurate effect. – ktodisco Feb 9 '12 at 22:15
Visibly it might for a black object on a white background but that is not what an AA algorithm does. Your answer doesn't work for most other situations and the author never said he just wanted to grey the edges. Pressure implies he want the line's color variance to be impacted by length. – ClassicThunder Feb 9 '12 at 22:33
It may not be an exact solution, but it seems like a good starting point, since it produces a similar effect (and doesn't just have to be in grayscale). – ktodisco Feb 9 '12 at 22:41
I would add a paper texture (probably effecting contrast rather then lightness) with this method to more closely emulate paper – lochok Feb 10 '12 at 0:39