Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,37 @@
|
|||
PROGRAM BCircle
|
||||
|
||||
!$INCLUDE="PC.LIB"
|
||||
|
||||
PROCEDURE BCircle(cx%,cy%,r%)
|
||||
local f%,x%,y%,ddx%,ddy%
|
||||
f%=1-r% y%=r% ddy%=-2*r%
|
||||
PSET(cx%,cy%+r%,1)
|
||||
PSET(cx%,cy%-r%,1)
|
||||
PSET(cx%+r%,cy%,1)
|
||||
PSET(cx%-r%,cy%,1)
|
||||
WHILE x%<y% DO
|
||||
IF f%>=0 THEN
|
||||
y%=y%-1
|
||||
ddy%=ddy%+2
|
||||
f%=f%+ddy%
|
||||
END IF
|
||||
x%=x%+1
|
||||
ddx%=ddx%+2
|
||||
f%=f%+ddx%+1
|
||||
PSET(cx%+x%,cy%+y%,1)
|
||||
PSET(cx%-x%,cy%+y%,1)
|
||||
PSET(cx%+x%,cy%-y%,1)
|
||||
PSET(cx%-x%,cy%-y%,1)
|
||||
PSET(cx%+y%,cy%+x%,1)
|
||||
PSET(cx%-y%,cy%+x%,1)
|
||||
PSET(cx%+y%,cy%-x%,1)
|
||||
PSET(cx%-y%,cy%-x%,1)
|
||||
END WHILE
|
||||
END PROCEDURE
|
||||
|
||||
BEGIN
|
||||
SCREEN(1)
|
||||
! Draw circles
|
||||
BCircle(100,100,40)
|
||||
BCircle(100,100,80)
|
||||
END PROGRAM
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
' version 15-10-2016
|
||||
' compile with: fbc -s gui
|
||||
|
||||
' Variant with Integer-Based Arithmetic from Wikipedia page:
|
||||
' Midpoint circle algorithm
|
||||
Sub circle_(x0 As Integer, y0 As Integer , radius As Integer, Col As Integer)
|
||||
|
||||
Dim As Integer x = radius
|
||||
Dim As Integer y
|
||||
' Decision criterion divided by 2 evaluated at x=r, y=0
|
||||
Dim As Integer decisionOver2 = 1 - x
|
||||
|
||||
While(x >= y)
|
||||
PSet(x0 + x, y0 + y), col
|
||||
PSet(x0 - x, y0 + y), col
|
||||
PSet(x0 + x, y0 - y), col
|
||||
PSet(x0 - x, y0 - y), col
|
||||
PSet(x0 + y, y0 + x), col
|
||||
PSet(x0 - y, y0 + x), col
|
||||
PSet(x0 + y, y0 - x), col
|
||||
PSet(x0 - y, y0 - x), col
|
||||
y = y +1
|
||||
If decisionOver2 <= 0 Then
|
||||
decisionOver2 += y * 2 +1 ' Change in decision criterion for y -> y +1
|
||||
Else
|
||||
x = x -1
|
||||
decisionOver2 += (y - x) * 2 +1 ' Change for y -> y +1, x -> x -1
|
||||
End If
|
||||
Wend
|
||||
|
||||
End Sub
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
ScreenRes 600, 600, 32
|
||||
Dim As Integer w, h, depth
|
||||
Randomize Timer
|
||||
|
||||
ScreenInfo w, h
|
||||
|
||||
For i As Integer = 1 To 10
|
||||
circle_(Rnd * w, Rnd * h , Rnd * 200 , Int(Rnd *&hFFFFFF))
|
||||
Next
|
||||
|
||||
|
||||
'save screen to BMP file
|
||||
BSave "Name.BMP", 0
|
||||
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
WindowTitle "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
constant red = 0xff2020,
|
||||
yellow = 0xffdf20
|
||||
|
||||
function SetPx(sequence img, atom x, atom y, integer colour)
|
||||
if x>=1 and x<=length(img)
|
||||
and y>=1 and y<=length(img[x]) then
|
||||
img[x][y] = colour
|
||||
end if
|
||||
return img
|
||||
end function
|
||||
|
||||
function Circle(sequence img, atom x, atom y, atom r, integer colour)
|
||||
atom x1 = -r,
|
||||
y1 = 0,
|
||||
err = 2-2*r
|
||||
if r>=0 then
|
||||
-- Bresenham algorithm
|
||||
while 1 do
|
||||
img = SetPx(img, x-x1, y+y1, colour)
|
||||
img = SetPx(img, x-y1, y-x1, colour)
|
||||
img = SetPx(img, x+x1, y-y1, colour)
|
||||
img = SetPx(img, x+y1, y+x1, colour)
|
||||
r = err
|
||||
if r>x1 then
|
||||
x1 += 1
|
||||
err += x1*2 + 1
|
||||
end if
|
||||
if r<=y1 then
|
||||
y1 += 1
|
||||
err += y1*2 + 1
|
||||
end if
|
||||
if x1>=0 then exit end if
|
||||
end while
|
||||
end if
|
||||
return img
|
||||
end function
|
||||
|
||||
sequence img = new_image(400,300,yellow)
|
||||
img = Circle(img, 200, 150, 100, red)
|
||||
write_ppm("Circle.ppm",img)
|
||||
Loading…
Add table
Add a link
Reference in a new issue