Simple Paint
Simple Paint
program SimplePaint;
uses Types, QuickDraw, Events;
var
i, x, y, key, bsize, etypes: Integer;
mouse: Point;
r, tbar: Rect;
bsizes: array[1..3] of Rect;
colors: array[0..15] of Rect;
event: EventRecord;
{ Draw screen }
procedure drawScreen;
begin
{ Draw title bar }
clearScreen(black);
setSolidPenPat(white);
setRect(tbar, 0, 0, 319, 20);
paintRect(tbar);
{ Draw brush sizes }
setSolidPenPat(black);
for i := 1 to 3 do begin
setRect(bsizes[i], 5 + (i - 1) * 8, 5,
15 + (i - 1) * 8, 15);
setPenSize(i * 2, 1);
moveTo(i * 8, 5);
line(0, 9);
end;
penNormal;
{ Draw color bar }
for i := 0 to 15 do begin
setRect(colors[i], 35 + i * 10, 5,
45 + i * 10, 15);
setSolidPenPat(i);
paintRect(colors[i]);
setSolidPenPat(0);
frameRect(colors[i]);
end;
{ Draw title }
moveTo(205, 13);
setForeColor(9);
setBackColor(4);
drawString(' Simple Paint ');
setSolidPenPat(white);
end;
{ Draw dots }
procedure drawDots(x, y: Integer);
var
ox, oy, ix, iy: Integer;
size: Real;
begin
size := bsize;
while button(0) do begin
getMouse(mouse);
if not PtInRect(mouse, tbar) then begin
{ Paint dot }
ox := x;
oy := y;
x := trunc(mouse.h - bsize div 2);
y := trunc(mouse.v - bsize div 2);
setRect(r, x, y, x + bsize, y + bsize);
paintOval(r);
{ Paint connected dot }
if (ox <> x) or (oy <> y) then begin
size := bsize;
ix := (ox + x) div 2;
iy := (oy + y) div 2;
setRect(r, ix, iy, ix + bsize,
iy + bsize);
paintOval(r);
end
else begin
{ Enlarge paint area if pressed }
if (size < bsize * 2) then
size := size + 0.01;
setRect(r, x - trunc(size / 2),
y - trunc(size / 2), trunc(x + size),
trunc(y + size));
paintOval(r);
end;
end;
end;
end;
begin
graphics(320);
bsize := 3;
etypes := keyDownMask + mDownMask;
drawScreen;
while true do begin
if getNextEvent(etypes, event) then begin
case event.what of
{ Key down }
keyDownEvt: begin
key := event.message;
if key = 27 then halt
else if key = 32 then drawScreen;
end;
{ Mouse down }
mouseDownEvt: begin
mouse := event.where;
{ Set brush size }
for i := 1 to 3 do
if ptInRect(mouse, bsizes[i]) then
bsize := i * 3;
{ Set color }
for i := 0 to 15 do
if ptInRect(mouse, colors[i]) then
setSolidPenPat(i);
drawDots(mouse.h - bsize div 2,
mouse.v - bsize div 2);
end;
end;
end;
end;
end.
A simple painting program for kids. You can change the paint brush size and color. If you press the mouse button long enough, the paint brush size will slowly expand to double its size. Press space bar to clear the picture and ESC to quit the program.
This program teaches the use of procedure and event driven programming.
Dora Paint is special version of Simple Paint for Dora fans (special thanks to Mike Stephens for scanned images).
Dora Paint
Simple Paint has been ported to iPhone using GScript.
Simple Paint for iPhone is been featured in Apple web site and now available in Apple App Store!