Post by B+ on May 21, 2018 15:20:52 GMT
A sample of the shorthand I've developed for drawing, same idea as old Basic Draw string$.
Here is the code for the main event:
the rest is just setup (that can be reused over and over for many other purposes).
It says:
r440 = repeat 440 times
x600y350 = Set x, y to 600, 350
p-1 = Turn off pen (pen is off when below 0)
t127.5 = Turn 127.5 degrees from current angle setting, this creates spiral when the radius ever increases (or decreases)
i1 = increment internal variable (z) by +1
fz = go forward z amount (if pen had color loaded it would draw lines)
p990 = set the pen color at 990 (full red 9, and full green 9, no blue) makes yellow
d30 = draw a filled circle with radius 30 (d comes after c for circle)
p900 = set the pen color at 900 (highest red)
c30 = circle radius 30 (at same x, y from forward move)
Here is the code for the main event:
call drawString "r440x600y350p-1t127.5i1fzp990d30p900c30"
the rest is just setup (that can be reused over and over for many other purposes).
It says:
r440 = repeat 440 times
x600y350 = Set x, y to 600, 350
p-1 = Turn off pen (pen is off when below 0)
t127.5 = Turn 127.5 degrees from current angle setting, this creates spiral when the radius ever increases (or decreases)
i1 = increment internal variable (z) by +1
fz = go forward z amount (if pen had color loaded it would draw lines)
p990 = set the pen color at 990 (full red 9, and full green 9, no blue) makes yellow
d30 = draw a filled circle with radius 30 (d comes after c for circle)
p900 = set the pen color at 900 (highest red)
c30 = circle radius 30 (at same x, y from forward move)
' spiral.txt for JB v2 B+ 2018-05-21
'from
'DrawString Tester Sampler.txt for JB v2 B+ 2018-05-11, 2018-05-18 finish angled tiles challenge
global xmax, ymax, pi, sz, goON, tx, ty, ta, tc$, tz, tv, tw, th
xmax = 1200
ymax = 700
pi = acs(-1)
nomainwin
WindowWidth = xmax + 8
WindowHeight = ymax + 32
UpperLeftX = 100
UpperLeftY = 20
open " *** Spiral - Sample post 2018-05-21 *** " for graphics_nsb_nf as #gr
#gr "setfocus"
#gr "trapclose quit"
#gr "when leftButtonUp lButtonUp"
#gr "when characterInput charIn"
#gr "down"
#gr "color white"
#gr "fill black"
sz = 1
#gr "size ";sz 'drawing rectangle fills needs a fatter line
cx = xmax/2 : cy = ymax/2
Homer$ = "JP-1A0S0X";cx;"Y";cy 'erase screen, pen off = -1, 0 out Angle, x, y at center of screen
call drawString "r440x600y350p-1t127.5i1fzp990d30p900c30" '<<<< noted above
call wait4Spacebar
call drawString Homer$;"x";450;"y";250;"h";200;"w";300;"p002mu";20;"v";20;"h";160;"w";260;"p039b"
call label "999", "002", 550, 350, "That's All Folks!"
wait
' procedures this window controls
sub lButtonUp H$, mx, my 'must have handle and mouse x,y
call quit H$ '<=== H$ global window handle
end sub
sub charIn H$, c$
if asc(c$) = 32 then
goON = 1 - goON
else
call quit H$
end if
end sub
sub wait4Spacebar 'when pause is just too rigid a time to wait
call label "999", "002", 20, 40, "press spacebar to continue..."
goON = 0
while goON = 0
scan
wend
end sub
sub quit H$
close #gr
end
end sub
'drawing procedures for testing and sampling
sub drawString tstring$ 'can't use E????
'global tx, ty, ta, tc, tv
tstring$ = upper$(tstring$);" " 'needed in case tstring$ end with command
cmd$ = "" : ds$ = ""
for i = 1 to len(tstring$)
c$ = mid$(tstring$, i, 1)
if c$ = "Z" then ds$ = str$(tz) 'Z is a varaible set with S or incremented with I
if instr("0123456789.-", c$) then ds$ = ds$ + c$
if instr("RXYPATCDFHWLBMJISUV", c$) or i = len(tstring$) then
'execute last cmd if one
if cmd$ <> "" then
d = val(ds$)
select case cmd$
case "R" 'repeat a drawstring d times
tst$ = mid$(tstring$, i)
call repete tst$, d
exit sub
case "X" : tx = d 'hard x
case "Y" : ty = d 'hard y
case "P" : tc$ = ds$ 'reset color
if val(tc$) >= 0 then call RGB tc$
case "A" : ta = d 'hard angle
case "T" : ta = ta + d 'mod angle
case "C" : #gr "place ";tx;" ";ty;"; circle ";d
case "D" : #gr "place ";tx;" ";ty;"; circlefilled ";d
case "F" 'this draws a line!!!! forward d = distance ( from current x, y at angle)
across = d * cos(pi/180 * ta - pi/2)
down = d * sin(pi/180 * ta - pi/2)
if val(tc$) > -1 then
#gr "line ";tx;" ";ty;" ";tx + across;" ";ty + down
end if
'#gr "line ";tx;" ";ty;" ";tx + across;" ";ty + down
tx = tx + across : ty = ty + down
case "H" : th = d 'h for height
case "W" : tw = d 'w for width
case "L" : #gr "line ";tx;" ";ty;" ";tx+tw;" ";ty+th
case "B"
if d = 0 then
#gr "place ";tx;" ";ty;";box ";tx+tw;" ";ty+th
else
call drawRect ta, tx, ty, tw, th
end if
case "M"
if d = 0 then 'normal rectangle a = 0
#gr "place ";tx;" ";ty;";boxfilled ";tx+tw;" ";ty+th
else
call dfrt ta, tx, ty, tw, th
end if
case "J" : #gr "cls;fill black" 'e (for erase) doesn't work
case "I" : tz = tz + d 'increment variable
case "S" : tz = d 'set variable
case "U" : tx = tx + d 'mod x step
case "V" : ty = ty + d 'mod y step
end select
ds$ = "" : cmd$ = ""
end if
cmd$ = c$
end if
next
end sub
sub repete tts$, times
for i = 1 to times
call drawString tts$
next
end sub
' handy supplemental procedures ==============================================
sub pause mil 'tsh version has scan built-in
t0 = time$("ms")
while time$("ms") < t0 + mil : scan : wend
end sub
sub label fColor$, bColor$, x, y, text$
call fRGB fColor$
call bRGB bColor$
#gr "place ";x;" ";y;";\";text$
end sub
sub fRGB s3$ 'foreground New Color System 1000 colors with 3 digits!!!!!!!!!!!!!!!!
l = len(s3$)
if l then r = 28 * val(mid$(s3$, 1, 1)) + 3
if l>=2 then g = 28 * val(mid$(s3$, 2, 1)) + 3
if l>=3 then b = 28 * val(mid$(s3$, 3, 1)) + 3
#gr "color ";r;" ";g;" ";b
end sub
sub bRGB s3$ 'background New Color System 1000 colors with 3 digits!!!!!!!!!!!!!!!!
l = len(s3$)
if l then r = 28 * val(mid$(s3$, 1, 1)) + 3
if l>=2 then g = 28 * val(mid$(s3$, 2, 1)) + 3
if l>=3 then b = 28 * val(mid$(s3$, 3, 1)) + 3
#gr "backcolor ";r;" ";g;" ";b
end sub
sub RGB s3$ ' New Color System 1000 colors with 3 digits!!!!!!!!!!!!!!!!
l = len(s3$)
if l then r = 28 * val(mid$(s3$, 1, 1)) + 3
if l>=2 then g = 28 * val(mid$(s3$, 2, 1)) + 3
if l>=3 then b = 28 * val(mid$(s3$, 3, 1)) + 3
#gr "color ";r;" ";g;" ";b
#gr "backcolor ";r;" ";g;" ";b
tc$ = s3$ 'update turtle with color?
end sub
sub drawRect a, x, y, w, h 'draw a rectangle frame at a given angle
#gr "size 2"
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
#gr "size ";sz
end sub
'draw string commands use this turtle method command mn where n = 1
sub dfrt a, x, y, w, h '(d)raw (f)illed (r)ectangle at given angle (t)urtle method
#gr "size 2;north;turn 180;turn ";a
for i = 1 to h 'draw *part of* bigger and bigger rectangles, tsh fixed and cut 1/2 drawing
#gr "place ";x;" ";y;";go ";i;";turn -90;go ";w;";turn 90"
next
#gr "size 1"
end sub