Post by B+ on May 11, 2018 14:47:13 GMT
I am trying to draw a filled rectangle at any angle from point x, y upper left corner of rectangle.
I have tried 3 methods and this JB Turtle Method draws the fastest but is completely wrong at certain angles.
Example code shows a white frame where the Rectangle is supposed to go and it does often work but is also often way off???
Is this a bug? Is there a fix?
I have tried 3 methods and this JB Turtle Method draws the fastest but is completely wrong at certain angles.
Example code shows a white frame where the Rectangle is supposed to go and it does often work but is also often way off???
'Turtle Method bug.txt for JB v2 B+ 2018-05-11
' Errors occur at certain angles drawing an angled Rectangle using a JB Turtle method
' But it is faster than 2 other methods I've tested, so I am interested if there is a fix?
global xmax, ymax, pi
xmax = 1200
ymax = 700
pi = acs(-1)
nomainwin
WindowWidth = xmax + 8
WindowHeight = ymax + 32
UpperLeftX = 100
UpperLeftY = 20
open " *** Turtle Method Bug for Angled Rectangles *** " for graphics_nsb_nf as #gr
#gr "setfocus"
#gr "trapclose quit"
#gr "when leftButtonUp lButtonUp"
#gr "when characterInput charIn"
#gr "down"
#gr "size 2"
#gr "backcolor black"
while 1
scan 'test drawing a filled rectangle at an angle
for a = 0 to 360 step 10
#gr "cls"
#gr "fill black"
#gr "color white"
call drawRect a, 600, 350, 300, 100
#gr "place 20 40";";|angle: ";a
#gr "color blue"
call drawfilledrectangle a, 600, 350, 300, 100
#gr "color white"
call drawRect a, 600, 350, 300, 100
call pause 1000
next
wend
wait
' procedures
sub lButtonUp H$, mx, my
call quit H$
end sub
sub charIn H$, c$
call quit H$
end sub
sub quit H$
close #gr
end
end sub
sub pause mil 'tsh version has scan built-in
t0 = time$("ms")
while time$("ms") < t0 + mil : scan : wend
end sub
sub drawRect a, x, y, w, h
ra = a * pi/180
x1 = x + w * cos(ra)
y1 = y + w * sin(ra)
x2 = x + h * cos(ra + pi/2)
y2 = y + h * sin(ra + pi/2)
x3 = x2 + w * cos(ra)
y3 = y2 + w * sin(ra)
#gr "line ";x;" ";y;" ";x1;" ";y1
#gr "line ";x1;" ";y1;" ";x3;" ";y3
#gr "line ";x3;" ";y3;" ";x2;" ";y2
#gr "line ";x2;" ";y2;" ";x;" ";y
end sub
sub drawfilledrectangle a, x, y, w, h
#gr "place ";x;" ";y
#gr "north"
#gr "turn 90"
#gr "turn ";a
for i = 1 to h 'draw bigger and bigger rectangles
#gr "go ";w
#gr "turn 90"
#gr "go ";i
#gr "turn 90"
#gr "go ";w
#gr "turn 90"
#gr "go ";i
#gr "turn 90"
next
end sub
Is this a bug? Is there a fix?