I have been struggling to learn FB since March, I basically work in SmallBASIC (not MS, the one before that a total interpreter) and every now and then I get something I want to compile or really speed up. I have just finished an update to my Draw Strings routine and am toying with idea of building an editor for drawing fonts with draw strings for custom fonts. Then, I will definitely need speed.
Here is the current state of my Draw Strings routine which I need practice translating to FB. Drawing fonts will take some modified form of the subs but I can start learning with this so I am ready with it when I am ready on the SB end. Am I making sense?
Code: Select all
' Draw strings 2.bas SmallBASIC 0.12.9 (B+=MGA) 2017-05-06
'Deluxe draw strings.sdlbas [B+=MGA] 2017-01-03
'translated from:
'v2 turtle strings.bas SmallBASIC 0.12.2 [B+=MGA] 2016-04-04
'2017-05-08 fixes Box d and e for width and height
' test draw strings fixed for arc
'=================================================================
' Commands Set
'==================================================================
'Note all commands are a letter for function followed by number n
'commands pn -1 to 15, 0-15 are QB colors, -1 is pen up
'command xn set absolute screen coordinate for turtle x
'command yn set absolute screen coordinate for turtle y
'command gn move turtle relative to its current x position
' + n = right, -n = left (pneumonic g for go!)
'command hn move turtle relative to its current y position
' + n down?, -n up? depends which way the angle is set
' (pnuemonic h follows g like y follows x)
'command fn draws at current ta angle a distance of n
' (pnuemonic f is for forward use -n for back)
'command an sets angle or heading of turtle
' (pnuemonic a is for angle (degrees)
' 0 degrees is true North or 12 o'clock)
'command tn (turns) t=right n degrees when positive
' and turn left n degrees when negative
'v2 2016-04-05 the great and powerful repeat uses recursive sub
'command rn repeat drawstrings n amount of times
'command tv for setting a turtle var probably need another
'add 2 more commands for setting and incrementing the tv variable
'command sn will set tv at n value
'command in will increment tv with n value
'Deluxe draw strings 2017-01-03
' draw filled box current tx, ty is one corner
'command z for pen siZe radius to draw thick lines
'command dn sets box width
'command en sets box height
'command bn for Box color n = 0 - 15
'command un to set a circle radius
'command cn to draw a filled circle of color n = 0 - 15
'command jn to set the arc deg angle start
'command kn to set the arc deg angle end
'command ln draw arc color n = 0 - 15
'======================================================================
'turtle globals should you translate to another dialect
'common scale, tx, ty, tx2, ty2, tr, taStart, taStop, tc, ta, tv, tz
scale = 1
tx = 0 : ty = 0 ' x, y turtle position
tx2 = 0 : ty2 = 0 ' 2nd x,y for fill box or for ellipse width and height
taStart = 0 ' turtle arc Start
taStop = 0 ' turtle arc Stop
tc = 15 ' turtle color (QB colors 0 - 15 and -1 means pen up
ta = 0 ' turtle angle
tv = 0 ' new turtle increment var for changing tv
tz = 1 ' tz is tracking pen size
tr = 0 ' radius
'tests
'blue pentagon, line thickness 8
tt "z1p9x500y500a90z8"
tt "r5f300t-72"
locate 1, 1 : ? "Thick blue line pentagon, press any for next test."
pause
cls
'===================== Tomaaz/Johnno's turtle art
tt "z2"
for i = 1 to 2
tt "a0p12x110y300"
tt "r100f250t-198"
tt "a0p10x230y440"
tt "r10g2h2r18f-20p10t10f-20p-1t10"
tt "a0p6x350y550"
tt "s500r248i-2fvt90.5"
color 15
locate 1, 1
? "Scale: ";scale;
? " Turtle art from Johnno and Tomaaz,"
if i = 2 then ? " again with z (Pen size) set at 1."
? " press any to continue.."
pause
tt "z1"
scale = .75 'scale is used for tt drawing
cls
next
'== latest mods box bn, circle cn, arc ln <<< fixed
scale = 1
tt "z1a0p9x300y200d50e50r4b12p-1t-90f100"
tt "p9r4f-100t90"
tt "g-40h30p9a270r8f16.6t-45"
tt "p-1x600y275u50c14"
tt "p-1z2x600y275p12u30j40k140l12"
tt "p-1x585y270p12u5c9"
tt "p-1x615y270p12u5c9"
pause
sub tt(tstring)
local cmd, ds, i, c, d, tst, across, down, lngth, dx, dy, j, aa, stepper
tstring = ucase(tstring)
cmd = "" : ds = ""
for i = 1 to len(tstring)
c = mid(tstring, i, 1)
if c = "V" then ds = str(tv)
if instr("0123456789.-", c) then ds = ds + c
if instr("ABCDEFGHIJKLPRSTUXYZ", c) or i = len(tstring) then
'execute last cmd if one
if cmd <> "" then
d = val(ds)
select case cmd
case "G" : tx += d 'move relative to tx, ty
case "H" : ty += d
case "X" : tx = d 'move to absolute screen x, y
case "Y" : ty = d
case "D" : tx2 = d '2nd corner box relative to tx
case "E" : ty2 = d '2nd corner box relative to ty
case "J" : taStart = d 'arc start angle
case "K" : taStop = d 'arc stop angle
case "P" : tc = d 'pen to qb color, -1 no pen
case "Z" : tz = d 'pen size
case "A" : ta = d 'set angle
case "T" : ta += d 'change angle - = left, + = right
case "U" : tr = d 'set radius for circle (R used for repeat)
case "I" : tv += d 'increment variable
case "S" : tv = d 'set or reset variable
case "R" ' repeat calls out for another call to tt
tst = mid(tstring, i) ' this assumes the rest of the string
repete tst, d ' is the repeat part.
exit for
case "F" 'Forward d distance according to angle ta
across = scale * d * cos(rad(ta - 90))
down = scale * d * sin(rad(ta - 90))
if tc > -1 then
color tc
if tz <= 1 then
line tx, ty, tx + across, ty + down
else
lngth = ((across) ^ 2 + (down) ^ 2) ^ .5
if lngth then
dx = across / lngth : dy = down / lngth
for j = 0 to lngth
circle tx + dx * j, ty + dy * j, tz filled
next
end if
end if
end if
tx = tx + across : ty = ty + down 'update turtle position
case "B"
color d
rect tx - tx2/2, ty - ty2/2, tx + tx2/2, ty + ty2/2 filled
case "C"
color d
circle tx, ty, tr filled
case "L" 'arc ld u sets radius, j and k set start and end angle
if tc > -1 then
color d
stepper = 1 / (3 * pi * tr)
for aa = taStart to taStop step stepper
dx = tr * cos(rad(aa))
dy = tr * sin(rad(aa))
if tz < 1 then
pset tx + dx, ty + dy
else
circle tx + dx, ty + dy, tz filled
end if
next
end if
end select
ds = "" : cmd = "" 'reset for next build of ds and cmd
end if
cmd = c
end if
next
end sub
sub repete(tts, times)
local i
for i = 1 to times
tt tts
next
end sub
The languages are so similar "...should be easy" but I anticipate difficulties with FB's graphics options / methods...
EDIT: Removed link