Retrogamecoding(.org) > Examples
TriangleFill for PulsarLua
(1/1)
Rick3137:
Here's an example of a simple Fill function for equilateral triangles that I came up with to use in another program.
function TriangleFill(x1,y1,d) -- x1,y1 is the bottom left point
d2 = d/2
dx = 1
dy = math.tan(math.pi/3)
x2 = x1 + d
y2 = y1
x3 = x2 + d
while x1 < x2
do
line( x1,y1,x2,y2)
line( x2,y2,x3,y2)
x1 = x1 + .5
y1 = y1 - dy/2
y2 = y1
x3 = x3 - .5
end
end
------------ START OF PROGRAM ---------------
win = openwindow ("Hexagon",-1,-1,1000,700)
setactivewindow (win)
textsize(2)
backcolor (0,0,0,255)
color (0,0,255,255)
TriangleFill(100,600,200)
drawtext("Press any key to exit ..",0,0)
sync()
key=inkey()
closewindow(win) -- This ends the program.
closeapplication()
Rick3137:
Silly me, Pulsarlua already has a filltriangle command.
--- Code: --- ------------ START OF PROGRAM ---------------
win = openwindow ("filltriangle",-1,-1,1000,700)
setactivewindow (win)
textsize(2)
backcolor (0,0,0,255)
color (0,0,255,255)
filltriangle(100,600,300,600,300,200)
drawtext("Press any key to exit ..",0,0)
sync()
key=inkey()
closewindow(win) -- This ends the program.
closeapplication()
--- End code ---
Cybermonkey:
;D
Navigation
[0] Message Index
Go to full version