Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,87 @@
PROGRAM MYFILL_DEMO
!VAR SP%
!$INTEGER
CONST IMAGE_WIDTH=320,IMAGE_HEIGHT=200
DIM STACK[6000,1]
FUNCTION QUEUE_COUNT(X)
QUEUE_COUNT=SP
END FUNCTION
!$INCLUDE="PC.LIB"
PROCEDURE QUEUE_INIT
SP=0
END PROCEDURE
PROCEDURE QUEUE_POP(->XX,YY)
XX=STACK[SP,0]
YY=STACK[SP,1]
SP=SP-1
END PROCEDURE
PROCEDURE QUEUE_PUSH(XX,YY)
SP=SP+1
STACK[SP,0]=XX
STACK[SP,1]=YY
END PROCEDURE
PROCEDURE FLOOD_FILL(XSTART,YSTART,COLORE_PRIMA,COLORE_RIEMP)
LOCAL XEST,XWEST,YNORD,YSUD,X,Y
QUEUE_INIT
QUEUE_PUSH(XSTART,YSTART)
WHILE (QUEUE_COUNT(0)>0) DO
QUEUE_POP(->X,Y)
XWEST=X
XEST=X
IF Y>0 THEN
YNORD=Y-1
ELSE
YNORD=-1
END IF
IF Y<IMAGE_HEIGHT-1 THEN
YSUD=Y+1
ELSE
YSUD=-1
END IF
LOOP
POINT(XEST+1,Y->ZC%)
EXIT IF NOT((XEST<IMAGE_WIDTH-1) AND (ZC%=COLORE_PRIMA))
XEST=XEST+1
END LOOP
LOOP
POINT(XWEST-1,Y->ZC%)
EXIT IF NOT((XWEST>0) AND (ZC%=COLORE_PRIMA))
XWEST=XWEST-1
END LOOP
FOR X=XWEST TO XEST DO
PSET(X,Y,COLORE_RIEMP)
POINT(X,YNORD->ZC%)
IF YNORD>=0 AND ZC%=COLORE_PRIMA THEN
QUEUE_PUSH(X,YNORD)
END IF
POINT(X,YSUD->ZC%)
IF YSUD>=0 AND ZC%=COLORE_PRIMA THEN
QUEUE_PUSH(X,YSUD)
END IF
END FOR
END WHILE
END PROCEDURE ! Flood_Fill
BEGIN
SCREEN(1)
CIRCLE(100,100,75,2)
CIRCLE(120,120,20,2)
CIRCLE(80,80,15,2)
CIRCLE(120,80,10,2)
FLOOD_FILL(100,100,0,1)
END PROGRAM

View file

@ -0,0 +1,55 @@
' version 04-11-2016
' compile with: fbc -s console
' the flood_fill needs to know the boundries of the window/screen
' without them the routine start to check outside the window
' this leads to crashes (out of stack)
' the Line routine has clipping it will not draw outside the window
Sub flood_fill(x As Integer, y As Integer, target As UInteger, fill_color As UInteger)
Dim As Long x_max, y_max
ScreenInfo x_max, y_max
' 0, 0 is top left corner
If Point(x,y) <> target Then Exit Sub
Dim As Long l = x, r = x
While Point(l -1, y) = target AndAlso l -1 > -1
l = l -1
Wend
While Point(r +1, y) = target AndAlso r +1 < x_max
r = r +1
Wend
Line (l,y) - (r,y), fill_color
For x = l To r
If y +1 < y_max Then flood_fill(x, y +1, target, fill_color)
If y -1 > -1 Then flood_fill(x, y -1, target, fill_color)
Next
End Sub
' ------=< MAIN >=------
Dim As ULong i, col, x, y
ScreenRes 400, 400, 32
Randomize Timer
For i As ULong = 1 To 5
Circle(Rnd * 400 ,Rnd * 400), i * 40, Rnd * &hFFFFFF
Next
' hit a key to end or close window
Do
x = Rnd * 400
y = Rnd * 400
col = Point(x, y)
flood_fill(x, y, col, Rnd * &hFFFFFF )
Sleep 2000
If InKey <> "" OrElse InKey = Chr(255) + "k" Then End
Loop

View file

@ -0,0 +1 @@
img.floodFill(x, y, rgb(r,g,b))

View file

@ -0,0 +1,23 @@
function ff(sequence img, integer x, integer y, integer colour, integer target)
if x>=1 and x<=length(img)
and y>=1 and y<=length(img[x])
and img[x][y]=target then
img[x][y] = colour
img = ff(img,x-1,y,colour,target)
img = ff(img,x+1,y,colour,target)
img = ff(img,x,y-1,colour,target)
img = ff(img,x,y+1,colour,target)
end if
return img
end function
function FloodFill(sequence img, integer x, integer y, integer colour)
integer target = img[x][y]
return ff(img,x,y,colour,target)
end function
sequence img = read_ppm("Circle.ppm")
img = FloodFill(img, 200, 100, blue)
write_ppm("FloodIn.ppm",img)
img = FloodFill(img, 10, 10, green)
write_ppm("FloodOut.ppm",img)