Post by B+ on Jun 18, 2018 3:54:55 GMT
Using one graphics sub to draw lines in two graphics boxes:
'string art.txt for JB v2.0 bplus 2018-06-17 from:
' string art mod mga.bas SmallBASIC 0.12.2 [B+=MGA] 2016-03-08
' orig ? S Shaw, 2013 by way of Johnno on SB forum
global XMAX, YMAX, PI, dta, scale, cx, cy, handle$
XMAX = 1000 '<======================================== actual drawing space needed
YMAX = 500 '<======================================== actual drawing space needed
PI = acs(-1)
nomainwin
WindowWidth = XMAX + 8
WindowHeight = YMAX + 32
UpperLeftX = (1200 - XMAX) / 2 'or delete if XMAX is 1200 or above
UpperLeftY = (700 - YMAX) / 2 'or delete if YMAX is 700 or above
graphicbox #m.gb1, 2, 2, 496, 496
graphicbox #m.gb2, 502, 2, 496, 496
open "Variable handle demo with String Art, click left or right box..." for graphics_nsb_nf as #m
#m "setfocus"
#m "trapclose quit"
#m.gb1 "when leftButtonUp lButtonUp"
#m.gb2 "when leftButtonUp lButtonUp"
#m "when characterInput charIn"
#m.gb1 "down"
#m.gb2 "down"
dim ab(29,1)
for i = 0 to 29
read a, b
ab(i, 0) = a
ab(i, 1) = b
'if i = 29 then notice str$(ab(i, 0))+", "+str$(ab(i, 1))
next
' 30 nice a,b combos
data 11,7 , 6,3 , 12,9 , 4,2 , 2,9 , 3,4 , 12,3, 9,3 , 7,6 , 5,5
data 13,1 , 7,3 , 9,11 , 10,3, 7,1 , 1,9 , 9,2 , 3,8 , 8,10, 2,4
data 8,5 , 10,7, 27,9 , 2,3 , 3,4 , 4,10, 1,3 , 9,5 , 6,9 ,22,1
scale = 248
cy = 496/2
cx = 496/2
wait
sub quit H$
close #m
end
end sub
sub lButtonUp H$, mx, my 'must have handle and mouse x,y
handle$ = H$
a = ab(dta, 0) : b = ab(dta, 1)
'notice str$(a)+", "+str$(b)+", "+str$(cx)+", "+str$(cy)+", "+str$(scale)
#handle$ "cls"
for i = 0 to 360
t = i * PI / 180.0
x = cx + scale * cos(t) : y = cy + scale * sin(t)
x1 = cx + scale * cos(a * t) : y1 = cy + scale * sin(b * t)
call lyne x, y, x1, y1
next
dta = dta + 1
if dta > 29 then dta = 0
end sub
sub charIn H$, c$
call quit H$
end sub
sub lyne x0, y0, x1, y1
if handle$ = "#m.gb1" then #handle$ "color red" else #handle$ "color blue"
#handle$ "line ";x0;" ";y0;" ";x1;" ";y1
end sub