• 13
• 18
• 19
• 27
• 9

# look like drawn with a pen/pencil

This topic is 3834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I was browsing through the "image of the day" list and found this realy creative game called crayon physics. I was wondering, how does he/she(kumikana) made the output from the pen/pencil, i tried experimenting by my own, but it didnt looked anywhere near that.I couldnt find any patterns so i think its how its done. My current code for this is:
[source langg = "cpp"]

void initpoints(BITMAP* bitmap)
{

for(int i = 0; i <=5; i++)
putpixel(bitmap,rand()%bitmap->w-1,bitmap->h-1,makecol(rand()%70+80,rand() % 150 +105,rand()%70+80));
}

void drawpoints(BITMAP* buffer,int x, int y, int d)
{
if(inside(x,y,mapxoff,mapyoff,mapxoff+SCREEN_W,mapyoff+SCREEN_H))
{
x -= mapxoff;
y -=mapyoff;

draw_sprite(buffer,colorbitmaps[d],x,y);
}
}


(using allegro)

##### Share on other sites
He/She describes it in the bottom of the thread....

The method involves several textures each with random alpha values, the textures get overlapped with psuedo-random texture coordinates and a diffuse color. The outcome looks amazing, doesn't it?

Anyway, read more of the post as it is described in slightly more detail than I did above.

##### Share on other sites
I actualy thought of something along that line myself, but i thought id have had to make a "brush" for each color. In the folder he describes (that comes with the game)only contains one image(with a black brush) and a few bitmaps(for drawings, i suppose), how does he get all these nuances of ex. blue out from the nuances of black?

##### Share on other sites
Quote:
 Original post by MadsGustafI actualy thought of something along that line myself, but i thought id have had to make a "brush" for each color. In the folder he describes (that comes with the game)only contains one image(with a black brush) and a few bitmaps(for drawings, i suppose), how does he get all these nuances of ex. blue out from the nuances of black?

Black isn't a color, are you sure it isn't grey/white ?

Changing the nuance of a greyscale image is quite simple, your greyscale image generally only has one channel per pixel, lets call that one L, your target color is a normal RGB value,

Thus for each pixel you simply multiply L with R for the red channel, L*B for the blue, and L*G for the green.

##### Share on other sites
You could use vertex colours to tint the basic black/white mask easily, combined with blending so that overlapping colours merge correctly. You could even add some subtle random colour variation per brush to make things look less regular.

##### Share on other sites
Quote:
Original post by SimonForsman
Quote:
 Original post by MadsGustafI actualy thought of something along that line myself, but i thought id have had to make a "brush" for each color. In the folder he describes (that comes with the game)only contains one image(with a black brush) and a few bitmaps(for drawings, i suppose), how does he get all these nuances of ex. blue out from the nuances of black?

Black isn't a color, are you sure it isn't grey/white ?

Changing the nuance of a greyscale image is quite simple, your greyscale image generally only has one channel per pixel, lets call that one L, your target color is a normal RGB value,

Thus for each pixel you simply multiply L with R for the red channel, L*B for the blue, and L*G for the green.

Let me get this straight, ex:
int R = 255
int G = 10
int B = 20

then i index through the standard bitmap brush's pixels and do something along this line
putpixel(randombitmapbrush[0],curpixel.x,curpixely,makecol(255*curpixel.color,10*curpixel.color,20*curpixel.color)
what if the color im looking at is white(255,255,255)? then im getting a color above 255.

##### Share on other sites
Simply multiply the values, check if they're within the 0-255 range - if they're below, set them to 0, if they're above, set them to 255 - and then draw that pixel.

That is, if that particular putpixel function doesn't do that underwater already (which I don't know, I've never used Allegro).

##### Share on other sites
Quote:
 Original post by MadsGustafLet me get this straight, ex:int R = 255int G = 10int B = 20then i index through the standard bitmap brush's pixels and do something along this lineputpixel(randombitmapbrush[0],curpixel.x,curpixely,makecol(255*curpixel.color,10*curpixel.color,20*curpixel.color)

Your variable name indicates a misunderstanding.

The RGB value is the pixel color. What you are going to multiply/modulate it by is the desired intensity, which, for convenience sake, should be normalized to lie between 0.0 and 1.0. That way, the component value will never be over 255.

If the pixel is white (255,255,255) and the intensity is 50%, ie 0.5, then:
resulting_color = (255 * 0.5, 255 * 0.5, 255 * 0.5) = (128, 128, 128)when rounded up to nearest integer value. Which is a shade of gray. 
 0 
 Share this post Link to post Share on other sites 
 
 
 madsravn    100 madsravn    100 Member Member 100 47 posts Joined March 2007 Posted September 18, 2007 Whoa.. That picture is like.. AWESOME. In which thread does he describe how he made it? I'd like to see... 0 Share this post Link to post Share on other sites MadsGustaf    144 MadsGustaf    144 Member Member 144 339 posts Joined October 2006 Posted September 18, 2007 Quote:Original post by MadsGustafLet me get this straight, ex:int R = 255int G = 10int B = 20then i index through the standard bitmap brush's pixels and do something along this lineputpixel(randombitmapbrush[0],curpixel.x,curpixely,makecol(255*curpixel.color,10*curpixel.color,20*curpixel.color)Your variable name indicates a misunderstanding.The RGB value is the pixel color. What you are going to multiply/modulate it by is the desired intensity, which, for convenience sake, should be normalized to lie between 0.0 and 1.0. That way, the component value will never be over 255.If the pixel is white (255,255,255) and the intensity is 50%, ie 0.5, then:resulting_color = (255 * 0.5, 255 * 0.5, 255 * 0.5) = (128, 128, 128)when rounded up to nearest integer value. Which is a shade of gray.Sorry for probaly asking a dumb question,but im not very familiar with graphiclal programming.How can i get the intensity from the pixel(/or is it from the whole image) I know there probaly is a function for that in allegro, but i couldnt seem to find one. Do i get this information when i draw the image?MADSravn>:uh-uh! nice name you got there, fellow dane! :D 0 Share this post Link to post Share on other sites 
 Prev 1 2 Next Page 1 of 2   Sign in to follow this   Followers 0 
 Go To Topic Listing For Beginners Advertisement 
 GDNet Discord Chat All Activity Home Forums Community For Beginners look like drawn with a pen/pencil