And I got another interesting func.
xShift,yShift = rotate(angle)
function rotate(a)
return math.cos(a / 180 * math.pi), - math.sin(a / 180 * math.pi)
end
minus flippin' Y axis (because on screen we have it increasing in down direction)
can be used for determination of coordinates after turning on some angle. Try this to understand what I mean:
Code:
-----"main.fba"-----
local angle = 0
function onmainloop()
if 0<mousedown()then quit()end
clear(0,0,0)
line(100-3, 100, 100+3, 100, 0,127,0)-- assign
line(100, 100-3, 100, 100+3, 0,127,0)-- center
angle = angle + 1
x,y = rotate(50, angle)
x, y = 100+x, 100+y
line(x-3, y, x+3, y, 127,0,0)-- here's
line(x, y-3, x, y+3, 127,0,0)-- target
end
function rotate(r, a) -- added radius of rotation 'r'
return math.cos(a * math.pi / 180) * r, - math.sin( a * math.pi / 180) * r
end
-----end-----
allso x and y can be added.
ARC function
Based on rotate()
please add it to Fba!
arc(xc, yc, r, sa, ea, R,G,B)
xc, yc - center
sa, ea - starting angle, ending angle
Code:
-----"main.fba"-----
function onmainloop()
if 0<mousedown()then quit()end
clear(0,0,0)
line(100-3, 100, 100+3, 100, 0,127,0)-- assign
line(100, 100-3, 100, 100+3, 0,127,0)-- center
arc(100, 100, 50, 0, mousey(), 127,0,0)
print(10, 40, "Got ARC start angle: 0 deg; end: " .. mousey() .. " deg; radius 50 pix.", 0,0,127)
end
function arc(xc, yc, r, sa, ea, R,G,B)
for angle = sa,ea,57/r do
point(xc + math.cos(angle * math.pi / 180) * r, yc - math.sin(angle * math.pi / 180) * r, R,G,B)
end
end
-----end-----
in this way can be implemented sector() cluster() chord() with help of poly() and filled versions of them like in fillpoly().