60 lines
1.6 KiB
Text
60 lines
1.6 KiB
Text
include c:\cxpl\codes;
|
|
|
|
proc Flood(X, Y, C, C0); \Fill an area of color C0 with color C
|
|
int X, Y, \seed coordinate (where to start)
|
|
C, C0; \color to fill with and color to replace
|
|
def S=8000; \size of queue (must be an even number)
|
|
int Q(S), \queue (FIFO)
|
|
F, E; \fill and empty indexes
|
|
|
|
proc EnQ(X, Y); \Enqueue coordinate
|
|
int X, Y;
|
|
[Q(F):= X;
|
|
F:= F+1;
|
|
Q(F):= Y;
|
|
F:= F+1;
|
|
if F >= S then F:= 0;
|
|
]; \EnQ
|
|
|
|
proc DeQ; \Dequeue coordinate
|
|
[X:= Q(E);
|
|
E:= E+1;
|
|
Y:= Q(E);
|
|
E:= E+1;
|
|
if E >= S then E:= 0;
|
|
]; \DeQ
|
|
|
|
[F:= 0; E:= 0;
|
|
EnQ(X, Y);
|
|
while E # F do
|
|
[DeQ;
|
|
if ReadPix(X, Y) = C0 then
|
|
[Point(X, Y, C);
|
|
EnQ(X+1, Y); \enqueue adjacent pixels
|
|
EnQ(X-1, Y);
|
|
EnQ(X, Y+1);
|
|
EnQ(X, Y-1);
|
|
];
|
|
];
|
|
]; \Flood
|
|
|
|
def Size = 30.0;
|
|
int X, Y;
|
|
real Ang, Dist;
|
|
[SetVid($101); \set 640x480 graphics with 256 colors
|
|
|
|
Ang:= 0.0; \draw some flower petals
|
|
repeat Dist:= Size*(Cos(Ang*3.0) - 1.0);
|
|
X:= fix(Dist*Cos(Ang));
|
|
Y:= fix(Dist*Sin(Ang));
|
|
Point(X+320, 240-Y, $F);
|
|
Ang:= Ang + 0.001; \draw dots close together to prevent leaks
|
|
until Ang >= 2.0*3.14159;
|
|
|
|
Flood(330, 240, $2A, 0); \color the petals
|
|
Flood(310, 230, $2C, 0);
|
|
Flood(310, 250, $2E, 0);
|
|
|
|
if ChIn(1) then []; \wait for keystroke
|
|
SetVid(3); \restore normal text mode
|
|
]
|