set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
clear_to_color( screen, makecol( 255, 255, 255));
putpixel( screen, 5, 5, makecol( 128, 200, 23));
circle( screen, 20, 20, 10, makecol( 255, 0, 0));
circlefill( screen, 50, 50, 25, makecol( 0,255, 0));
rect( screen, 70, 70, 90, 90, makecol( 0, 0, 255));
rectfill( screen, 100, 100, 120, 120, makecol( 12, 34, 200));
line( screen, 130, 130, 150, 150, makecol( 255, 0, 0));
line( screen, 130, 130, 170, 130, makecol( 255, 0, 0));
line( screen, 170, 130, 150, 150, makecol( 255, 0, 0));
floodfill( screen, 140, 135, makecol( 255, 255, 0));
triangle( screen, 200, 200, 200, 220, 220, 210, makecol( 213, 79, 40));
This program will change the background color to white and draw several shapes on the screen. Lets break down the code.
"clear_to_color( screen, makecol( 255, 255, 255));" is used to clear any bitmap specified in the first parameter to the color in the second. We will get more into bitmaps in a later lesson, just use screen for now.
All the functions used to draw here take the bitmap to draw to as the first parameter. putpixel() takes four parameters, the second and third define the x and y coordinates. The fourth the color of the pixel. A pixel is the smallest component in an image, what you see on your monitor is a bunch of different color pixels, the size of the pixel depends on the resolution you set with set_gfx_mode().
circle() and circlefill() both draw circles, the difference is that circlefill() will fill in the circle with the color specified in the last parameter while circle() simply draws the outline. The second and third parameters specify the position. The fourth defins the radius of the circle.
rect() and rectfill() draw rectangles which start at the point defined by the second and third parameters and end at the point defined by the fourth and fith parameters. The difference between rect() and rectfill() is the same as the two circle functions.
line() draws a line of the color specified in the last parameter starting at the point defined by the second and third parameter and ending at the point defined by the fourth and fith.
floodfill() works like the "Paint Bucket" tool found in most image editing software. It will fill an area starting at the point defined by the second and third pixel with the color specified in the fourth.
triangle() draws a colored in triangle, there is no trianglefill(). The three points of the triangle are defined by second through sixth parameters. The color is defined by the last parameter.