langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,26 @@
fill: procedure (x, y, fill_color) recursive; /* 12 May 2010 */
declare (x, y) fixed binary;
declare fill_color bit (24) aligned;
if x <= lbound(image, 2) | x >= hbound(image, 2) then return;
if y <= lbound(image, 1) | y >= hbound(image, 1) then return;
pixel_color = image (x,y); /* Obtain the color of the current pixel. */
if pixel_color ^= area_color then return;
/* the pixel has already been filled with fill_color, */
/* or we are not within the area to be filled. */
image(x, y) = fill_color; /* color the desired area. */
pixel_color = image (x,y-1); /* Obtain the color of the pixel to the north. */
if pixel_color = area_color then call fill (x, y-1, fill_color);
pixel_color = image (x-1,y); /* Obtain the color of the pixel to the west. */
if pixel_color = area_color then call fill (x-1, y, fill_color);
pixel_color = image (x+1,y); /* Obtain the color of the pixel to the east. */
if pixel_color = area_color then call fill (x+1, y, fill_color);
pixel_color = image (x,y+1); /* Obtain the color of the pixel to the south. */
if pixel_color = area_color then call fill (x, y+1, fill_color);
end fill;

View file

@ -0,0 +1,7 @@
/* Fill the white area of the suggested image with red color. */
area_color = (24)'1'b;
call fill (125, 25, '000000000000000011111111'b );
/* Fill the center orb of the suggested image with green color. */
area_color = '0'b;
call fill (125, 125, '000000001111111100000000'b );

View file

@ -0,0 +1,2 @@
FillArea(0,0,-1,$ff)
; Fills an Area in red

View file

@ -0,0 +1,30 @@
Procedure Floodfill(x,y,new_color)
old_color = Point(x,y)
NewList stack.POINT()
AddElement(stack()):stack()\x = x : stack()\y = y
While(LastElement(stack()))
x = stack()\x : y = stack()\y
DeleteElement(stack())
If Point(x,y) = old_color
Plot(x, y, new_color)
AddElement(stack()):stack()\x = x : stack()\y = y +1
AddElement(stack()):stack()\x = x : stack()\y = y -1
AddElement(stack()):stack()\x = x +1 : stack()\y = y
AddElement(stack()):stack()\x = x -1 : stack()\y = y
EndIf
Wend
EndProcedure
If OpenWindow(0, 0, 0, 200, 200, "Floodfill Beispiel", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StartDrawing(WindowOutput(0))
Box(0, 0, 200, 200, RGB(255, 255, 255))
DrawingMode(#PB_2DDrawing_Outlined )
Circle(100, 100, 90, RGB(255 ,0,0)): Circle(120, 80, 30, RGB(255 ,0,0)): Circle(200,200, 70, RGB(255 ,0,0))
Floodfill(40,40,RGB(0 ,255,0))
StopDrawing()
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf

View file

@ -0,0 +1,60 @@
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
]