I've made it easier for those who have trouble reading the code:
Code:
// Paint program - (c) 2005 by Claus Nielsen
bmap PAPER = <paper.bmp>;
bmap YELLOW = <color.bmp>;
bmap BLUE = <color.bmp>;
bmap BLACK = <color.bmp>;
bmap WHITE = <color.bmp>;
bmap RED = <color.bmp>;
bmap GREEN = <color.bmp>;
bmap CYAN = <color.bmp>;
bmap cursor = <arrow.pcx>;
bmap slider_bg = <slider_bg.bmp>;
bmap slider = <slider.bmp>;
var D3DCOLOR[3];
var BRUSHSIZE = 10;
var BRUSHDETAIL = 5;
var video_mode = 7;
var video_depth = 32;
var video_screen = 2;
font arial_font = "arial",0,18;
panel paper_pan
{
bmap = PAPER;
pos_x = 0;
pos_y = 20;
flags = visible,refresh;
layer = 1;
}
text desc1
{
font = arial_font;
pos_x = 295;
pos_y = 1;
string = "Detail:";
layer = 4;
flags = visible;
red = 1;
green = 1;
blue = 1;
}
text desc2
{
font = arial_font;
pos_x = 410;
pos_y = 1;
string = "Size:";
layer = 4;
flags = visible;
red = 1;
green = 1;
blue = 1;
}
function NewColor(but, pan)
{
if(but == 1) {temp.red = 255; temp.green = 255; temp.blue = 0; }
if(but == 2) {temp.red = 0; temp.green = 0; temp.blue = 255;}
if(but == 3) {temp.red = 1; temp.green = 1; temp.blue = 1; }
if(but == 4) {temp.red = 255; temp.green = 255; temp.blue = 255;}
if(but == 5) {temp.red = 255; temp.green = 0; temp.blue = 0; }
if(but == 6) {temp.red = 0; temp.green = 255; temp.blue = 0; }
if(but == 7) {temp.red = 0; temp.green = 255; temp.blue = 255;}
vec_set(D3DCOLOR, temp);
}
panel color_buts
{
pos_x = 5;
pos_y = 1;
button = 0, 0, YELLOW, YELLOW, YELLOW, NewColor, null, null;
button = 18, 0, BLUE, BLUE, BLUE, NewColor, null, null;
button = 36, 0, BLACK, BLACK, BLACK, NewColor, null, null;
button = 54, 0, WHITE, WHITE, WHITE, NewColor, null, null;
button = 72, 0, RED, RED, RED, NewColor, null, null;
button = 90, 0, GREEN, GREEN, GREEN, NewColor, null, null;
button = 108, 0, CYAN, CYAN, CYAN, NewColor, null, null;
flags = visible;
layer = 2;
}
panel detail_slider
{
bmap = slider_bg;
pos_x = 350;
pos_y = 1;
layer = 3;
flags = visible;
hslider = 0,0,50,slider,1,120,BRUSHDETAIL;
}
panel brush_slider
{
bmap = slider_bg;
pos_x = 455;
pos_y = 1;
layer = 3;
flags = visible;
hslider = 0,0,50,slider,1,120,BRUSHSIZE;
}
function COLORIMG(_BMAP,&_D3DCOLOR)
{
var D3DFORMAT;
var D3DPIXEL ;
var i; var k;
D3DFORMAT = bmap_lock(_BMAP,0);
D3DPIXEL = pixel_for_vec(_D3DCOLOR,100,D3DFORMAT);
while(i < bmap_height(_BMAP))
{
k = 0;
while(k < bmap_width(_BMAP))
{
pixel_to_bmap(_BMAP,k,i,D3DPIXEL);
k += 1;
}
i += 1;
}
bmap_unlock(_BMAP);
}
function main()
{
var D3DFORMAT;
var D3DPIXEL;
var i;
var vi;
var 2DPOS[2];
vec_set(screen_color, vector(204, 204, 204));
vec_set(D3DCOLOR, vector( 1, 1, 1));
temp.red = 255; temp.green = 255; temp.blue = 0;
COLORIMG(YELLOW, temp);
temp.red = 0; temp.green = 0; temp.blue = 255;
COLORIMG(BLUE, temp);
temp.red = 1; temp.green = 1; temp.blue = 1;
COLORIMG(BLACK, temp);
temp.red = 255; temp.green = 0; temp.blue = 0;
COLORIMG(RED, temp);
temp.red = 0; temp.green = 255; temp.blue = 0;
COLORIMG(GREEN, temp);
temp.red = 0; temp.green = 255; temp.blue = 255;
COLORIMG(CYAN, temp);
mouse_map = cursor;
mouse_mode = 2;
while(1)
{
mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;
if (mouse_left &&
(mouse_pos.x > paper_pan.pos_x &&
mouse_pos.x < paper_pan.pos_x + bmap_width(paper_pan.bmap)) &&
(mouse_pos.y > paper_pan.pos_y &&
mouse_pos.y < paper_pan.pos_y + bmap_height(paper_pan.bmap)))
{
// Prepare for drawing
D3DFORMAT = bmap_lock(PAPER, 0);
// Create the pixel to draw with
D3DPIXEL = pixel_for_vec(D3DCOLOR, 100, D3DFORMAT);
// Drawing position
2DPOS.x = mouse_pos.x - paper_pan.pos_x;
2DPOS.y = mouse_pos.y - paper_pan.pos_y;
// Draw the pixel onto the bitmap
pixel_to_bmap(PAPER, 2DPOS.x, 2DPOS.y, D3DPIXEL);
// Use a circled brush
i = 1;
while(i < BRUSHSIZE)
{
vi = 0;
while(vi < 360)
{
if((2DPOS.x + int(fcos(vi,i)) > 0 &&
2DPOS.x + int(fcos(vi,i)) < bmap_width(paper_pan.bmap))&&
(2DPOS.y + int(fsin(vi,i)) > 0 &&
2DPOS.y + int(fsin(vi,i)) <
bmap_height(paper_pan.bmap)))
{
pixel_to_bmap(
PAPER,
2DPOS.x + int(fcos(vi,i)),
2DPOS.y + int(fsin(vi,i)),
D3DPIXEL);
}
vi += BRUSHDETAIL;
}
i += 1;
}
// Unlock the bitmap
bmap_unlock(PAPER);
}
wait(0.1);
}
}
I hope I made it easier for you all to read the code.