|
Post by B+ on Jun 12, 2018 23:22:50 GMT
I just noticed something odd with Aquarium code I posted earlier.
This works:
' =============================== here is setup for a variable window handle Global h$ '<<<< this makes my handle variable available to subs and functions as well as main code h$ = "#gr" '<<<< this is the one and only window open here but is sample of usage with the sub aline ' ===================== see the sub aline and notice all calls to aline had to include a handle variable
... 'water gradient fill for i=0 to ymax call ink 0,0,255-(i/ymax)*255 call aline h$, 0,i,xmax,i next
... sub aline hdl$, x0,y0,x1,y1 #hdl$ "line ";x0;" ";y0;" ";x1;" ";y1 end sub
but if I set h$ = "gr"
it does not work.
#hdl$
very peculiar.
|
|
|
Post by Rod on Jun 13, 2018 6:57:20 GMT
The # is a command telling the interpreter to use the following variable as a “handle” pointing to a resource like a graphics window.. it can be a literal like “gb.1” or a handle variable which must include the #. So “#gb.1” as a variable h$.
In this case since “gb.1” is in any event a globally available resource there is no need to code a handle variable or indeed pass global info to a sub. Habit and style says you want to but we have what we have, a mix of local and global resources. If there were more than one graphic resource then the handle variable is perfect. But you must follow the rules creating the variable and include the #
|
|
|
Post by B+ on Jun 13, 2018 14:11:13 GMT
Ah, so the # symbol signals the interpreter. Thanks
|
|
|
Post by bluatigro on Jun 13, 2018 17:18:11 GMT
so we have to use
global handle$ handle$ = "#m"
or has handle$ to start whit # ?
|
|
|
Post by bluatigro on Jun 13, 2018 17:43:39 GMT
update : next step
error : a white screen
'' bluatigro 11 jun 2018 '' LB 5 sim WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , backcolor$ , color$ , lb5.size global orange$ , handle$ orange$ = "255 127 0" winx = WindowWidth winy = WindowHeight nomainwin open "LB 5 sim" for graphics as #m #m "trapclose [quit]" handle$ = "#m" call backcolor orange$ call color "black" call size 7 call triangle 50 , 50 , 200 , 50 , 150 , 300 wait [quit] close #m end sub backcolor kl$ backcolor$ = kl$ print handle$ , "backcolor " ; kl$ end sub sub box x , y , filled print handle$ , "down" if filled then print handle$ , "boxfilled " ; x ; " " ; y else print handle$ , "box " ; x ; " " ; y end if print handle$ , "up" end sub sub circle r , filled print handle$ , "down" if filled then print handle$ , "circlefilled " ; r else print handle$ , "circle " ; r end if print handle$ , "up" end sub sub color kl$ color$ = kl$ print handle$ , "color " ; kl$ end sub sub lino x1 , y1 , x2 , y2 print handle$ , "down" print handle$ , "line " ; x1 ; " " ; y1 ; " " ; x2 ; " " ; y2 print handle$ , "up" end sub sub pie x , y , a , b , filled print handle$ , "down " if filled then print handle$ , "piefilled " ; x ; " " ; y ; " " ; a ; " " ; b else print handle$ , "pie " ; x ; " " ; y ; " " ; a ; " " ; b end if print handle$ , "up" end sub sub pixel x , y print handle$ , "goto " ; x ; " " ; y print handle$ , "down" print handle$ , "set " ; x ; " "; y print handle$ , "up" end sub sub place x , y print handle$ , "goto " ; x ; " " ; y end sub sub size i lb5.size = i print handle$ , "size " ; i end sub sub text txt$ print handle$ , "down" print handle$ , "\" ; txt$ print handle$ , "up" end sub sub triangle x1 , y1 , x2 , y2 , x3 , y3 if y1 = y2 then y1 = y1 - .1 if y2 = y3 then y3 = y3 + .1 if y1 = y3 then y3 = y3 + .1 if y1 > y3 then h = y1 y1 = y3 y3 = h h = x1 x1 = x3 x3 = h end if if y1 > y2 then h = y1 y1 = y2 y2 = h h = x1 x1 = x2 x2 = h end if if y2 > y3 then h = y2 y2 = y3 y3 = h h = x2 x2 = x3 x3 = h end if print handle$ , "color " ; backcolor$ print handle$ , "size 1" for i = y1 to y3 a = x1 + ( x3 - x1 ) * (i-y1) / ( y3 - y1 ) if i < y2 then b = x1 + ( x2 - x1 ) * (i-y1) / ( y2 - y1 ) else b = x2 + ( x3 - x2 ) * (i-y2) / ( y3 - y2 ) end if if abs( a - b ) > 1 then call lino int( a ) , i , int( b ) , i end if next i print handle$ , "size " ; lb5.size print handle$ , "color " ; color$ call lino x1 , y1 , x2 , y2 call lino x3 , y3 , x2 , y2 call lino x1 , y1 , x3 , y3 end sub
|
|
|
Post by tsh73 on Jun 13, 2018 19:45:08 GMT
handle$ should start with #, as in "#m"
But to use it as a handle - not as a string variable - you should prepend # in front of it: so
print #handle$ , "color " ; color$
(replace all print handle$ for print #handle$ - 30 matches )
|
|
|
Post by bluatigro on Jun 14, 2018 5:32:43 GMT
this does not work as expected
we are running out of options
'' bluatigro 15 jun 2018 '' LB 5 sim WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , backcolor$ , color$ , lb5.size global orange$ , #handle$ orange$ = "255 127 0" winx = WindowWidth winy = WindowHeight nomainwin open "LB 5 sim" for graphics as #m #m "trapclose [quit]" #handle$ = "#m" call backcolor orange$ call color "black" call size 7 call triangle 50 , 50 , 200 , 50 , 150 , 300 wait [quit] close #m end sub backcolor kl$ backcolor$ = kl$ print #handle$ , "backcolor " ; kl$ end sub sub box x , y , filled print #handle$ , "down" if filled then print #handle$ , "boxfilled " ; x ; " " ; y else print #handle$ , "box " ; x ; " " ; y end if print #handle$ , "up" end sub sub circle r , filled print #handle$ , "down" if filled then print #handle$ , "circlefilled " ; r else print #handle$ , "circle " ; r end if print #handle$ , "up" end sub sub color kl$ color$ = kl$ print #handle$ , "color " ; kl$ end sub sub lino x1 , y1 , x2 , y2 print #handle$ , "down" print #handle$ , "line " ; x1 ; " " ; y1 ; " " ; x2 ; " " ; y2 print #handle$ , "up" end sub sub pie x , y , a , b , filled print #handle$ , "down " if filled then print #handle$ , "piefilled " ; x ; " " ; y ; " " ; a ; " " ; b else print #handle$ , "pie " ; x ; " " ; y ; " " ; a ; " " ; b end if print #handle$ , "up" end sub sub pixel x , y print #handle$ , "goto " ; x ; " " ; y print #handle$ , "down" print #handle$ , "set " ; x ; " "; y print #handle$ , "up" end sub sub place x , y print #handle$ , "goto " ; x ; " " ; y end sub sub size i lb5.size = i print #handle$ , "size " ; i end sub sub text txt$ print #handle$ , "down" print #handle$ , "\" ; txt$ print #handle$ , "up" end sub sub triangle x1 , y1 , x2 , y2 , x3 , y3 if y1 = y2 then y1 = y1 - .1 if y2 = y3 then y3 = y3 + .1 if y1 = y3 then y3 = y3 + .1 if y1 > y3 then h = y1 y1 = y3 y3 = h h = x1 x1 = x3 x3 = h end if if y1 > y2 then h = y1 y1 = y2 y2 = h h = x1 x1 = x2 x2 = h end if if y2 > y3 then h = y2 y2 = y3 y3 = h h = x2 x2 = x3 x3 = h end if print #handle$ , "color " ; backcolor$ print #handle$ , "size 1" for i = y1 to y3 a = x1 + ( x3 - x1 ) * (i-y1) / ( y3 - y1 ) if i < y2 then b = x1 + ( x2 - x1 ) * (i-y1) / ( y2 - y1 ) else b = x2 + ( x3 - x2 ) * (i-y2) / ( y3 - y2 ) end if if abs( a - b ) > 1 then call lino int( a ) , i , int( b ) , i end if next i print #handle$ , "size " ; lb5.size print #handle$ , "color " ; color$ call lino x1 , y1 , x2 , y2 call lino x3 , y3 , x2 , y2 call lino x1 , y1 , x3 , y3 end sub
|
|
|
Post by Rod on Jun 14, 2018 7:05:43 GMT
The # is confusing you. When you create the handle variable you must include # so handle$=“#m” note no # in front of handle$
When you use handle$ invariable in a sub you must also prepend the usual # so print #handle$
It works you just need to get the syntax right.
|
|
|
Post by B+ on Jun 14, 2018 12:40:42 GMT
'' bluatigro 15 jun 2018 '' LB 5 sim WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , backcolor$ , color$ , lb5.size global orange$ , handle$ '<<<<<<<<<<<<<<<<<<<<<< # NOT needed when declaring the variable global orange$ = "255 127 0" winx = WindowWidth winy = WindowHeight nomainwin open "LB 5 sim" for graphics as #m #m "trapclose [quit]" ' #handle$ = "#m" '<<<<<<<<<<<<<<<<<<<<<< # NOT needed when setting the variable handle$ = "#m" call backcolor orange$ call color "black" call size 7 call triangle 50 , 50 , 200 , 50 , 150 , 300 wait [quit] close #m end sub backcolor kl$ backcolor$ = kl$ print #handle$ , "backcolor " ; kl$ '<<<<<<<<<<<<< correct # needed when commanding the interpreter end sub sub box x , y , filled print #handle$ , "down" if filled then print #handle$ , "boxfilled " ; x ; " " ; y else print #handle$ , "box " ; x ; " " ; y end if print #handle$ , "up" end sub sub circle r , filled print #handle$ , "down" if filled then print #handle$ , "circlefilled " ; r else print #handle$ , "circle " ; r end if print #handle$ , "up" end sub sub color kl$ color$ = kl$ print #handle$ , "color " ; kl$ end sub sub lino x1 , y1 , x2 , y2 print #handle$ , "down" print #handle$ , "line " ; x1 ; " " ; y1 ; " " ; x2 ; " " ; y2 print #handle$ , "up" end sub sub pie x , y , a , b , filled print #handle$ , "down " if filled then print #handle$ , "piefilled " ; x ; " " ; y ; " " ; a ; " " ; b else print #handle$ , "pie " ; x ; " " ; y ; " " ; a ; " " ; b end if print #handle$ , "up" end sub sub pixel x , y print #handle$ , "goto " ; x ; " " ; y print #handle$ , "down" print #handle$ , "set " ; x ; " "; y print #handle$ , "up" end sub sub place x , y print #handle$ , "goto " ; x ; " " ; y end sub sub size i lb5.size = i print #handle$ , "size " ; i end sub sub text txt$ print #handle$ , "down" print #handle$ , "\" ; txt$ print #handle$ , "up" end sub sub triangle x1 , y1 , x2 , y2 , x3 , y3 if y1 = y2 then y1 = y1 - .1 if y2 = y3 then y3 = y3 + .1 if y1 = y3 then y3 = y3 + .1 if y1 > y3 then h = y1 y1 = y3 y3 = h h = x1 x1 = x3 x3 = h end if if y1 > y2 then h = y1 y1 = y2 y2 = h h = x1 x1 = x2 x2 = h end if if y2 > y3 then h = y2 y2 = y3 y3 = h h = x2 x2 = x3 x3 = h end if print #handle$ , "color " ; backcolor$ print #handle$ , "size 1" for i = y1 to y3 a = x1 + ( x3 - x1 ) * (i-y1) / ( y3 - y1 ) if i < y2 then b = x1 + ( x2 - x1 ) * (i-y1) / ( y2 - y1 ) else b = x2 + ( x3 - x2 ) * (i-y2) / ( y3 - y2 ) end if if abs( a - b ) > 1 then call lino int( a ) , i , int( b ) , i end if next i print #handle$ , "size " ; lb5.size print #handle$ , "color " ; color$ call lino x1 , y1 , x2 , y2 call lino x3 , y3 , x2 , y2 call lino x1 , y1 , x3 , y3 end sub
I do like how you removed handle$ from parameters needed to call sub.
|
|
|
Post by Gordon R on Jun 14, 2018 17:07:12 GMT
Hmmm nice exercise, but ....
LB5 uses functions like:
#m color("black")
#m color(bl$)
#m color(
#m color(200,30,245)
#m "color black"
#m "color 200 30 245"
#m "color "; 200+(255*30+(255*255+245))
in the same listing !!!!
Gordon
|
|
|
Post by tsh73 on Jun 15, 2018 21:07:59 GMT
Gordon, You almost make that sound like a bad thing ;p
|
|
|
Post by bluatigro on Jun 16, 2018 4:01:16 GMT
update : finely it works !!
'' bluatigro 16 jun 2018 '' LB 5 sim WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , backcolor$ , color$ , lb5.size global orange$ , handle$ , pi , pi180 , true , false orange$ = "255 127 0" winx = WindowWidth winy = WindowHeight pi = atn( 1 ) * 4 pi180 = pi / 180 false = 0 true = not( false ) nomainwin open "LB 5 sim" for graphics as #m #m "trapclose [quit]" handle$ = "#m" call backcolor orange$ call color "black" call size 7 call triangle 50 , 50 , 200 , 50 , 150 , 300 , true call size 2 for i = 0 to 360 x = sin( i * pi180 ) * 100 y = cos( i * pi180 ) * 100 call color rainbow$( i ) call lino 400 , 300 , 400 + x , 300 + y next i wait [quit] close #m end function rainbow$( deg ) r = sin( deg * pi180 ) * 127 + 128 g = sin( ( deg - 120 ) * pi180 ) * 127 + 128 b = sin( ( deg + 120 ) * pi180 ) * 127 + 128 rainbow$ = rgb$( r , g , b ) end function function rgb$( r , g , b ) r = int( r ) and 255 g = int( g ) and 255 b = int( b ) and 255 rgb$ = str$( r ) ; " " ; g ; " " ; b end function sub backcolor kl$ backcolor$ = kl$ print #handle$ , "backcolor " ; kl$ end sub sub box x , y , filled print #handle$ , "down" if filled then print #handle$ , "boxfilled " ; x ; " " ; y else print #handle$ , "box " ; x ; " " ; y end if print #handle$ , "up" end sub sub circle r , filled print #handle$ , "down" if filled then print #handle$ , "circlefilled " ; r else print #handle$ , "circle " ; r end if print #handle$ , "up" end sub sub color kl$ color$ = kl$ print #handle$ , "color " ; kl$ end sub sub lino x1 , y1 , x2 , y2 print #handle$ , "down" print #handle$ , "line " ; x1 ; " " ; y1 ; " " ; x2 ; " " ; y2 print #handle$ , "up" end sub sub pie x , y , a , b , filled print #handle$ , "down " if filled then print #handle$ , "piefilled " ; x ; " " ; y ; " " ; a ; " " ; b else print #handle$ , "pie " ; x ; " " ; y ; " " ; a ; " " ; b end if print #handle$ , "up" end sub sub pixel x , y print #handle$ , "goto " ; x ; " " ; y print #handle$ , "down" print #handle$ , "set " ; x ; " "; y print #handle$ , "up" end sub sub place x , y print #handle$ , "goto " ; x ; " " ; y end sub sub size i lb5.size = i print #handle$ , "size " ; i end sub sub text txt$ print #handle$ , "down" print #handle$ , "\" ; txt$ print #handle$ , "up" end sub sub triangle x1 , y1 , x2 , y2 , x3 , y3 , filled if filled then if y1 = y2 then y1 = y1 - .1 if y2 = y3 then y3 = y3 + .1 if y1 = y3 then y3 = y3 + .1 if y1 > y3 then h = y1 y1 = y3 y3 = h h = x1 x1 = x3 x3 = h end if if y1 > y2 then h = y1 y1 = y2 y2 = h h = x1 x1 = x2 x2 = h end if if y2 > y3 then h = y2 y2 = y3 y3 = h h = x2 x2 = x3 x3 = h end if print #handle$ , "color " ; backcolor$ print #handle$ , "size 1" for i = y1 to y3 a = x1 + ( x3 - x1 ) * (i-y1) / ( y3 - y1 ) if i < y2 then b = x1 + ( x2 - x1 ) * (i-y1) / ( y2 - y1 ) else b = x2 + ( x3 - x2 ) * (i-y2) / ( y3 - y2 ) end if if abs( a - b ) > 1 then call lino int( a ) , i , int( b ) , i end if next i end if print #handle$ , "size " ; lb5.size print #handle$ , "color " ; color$ call lino x1 , y1 , x2 , y2 call lino x3 , y3 , x2 , y2 call lino x1 , y1 , x3 , y3 end sub
|
|
|
Post by B+ on Jun 16, 2018 13:55:36 GMT
Next we need a demo showing how all this comes in really handy, multiple graphics boxes or graphics windows... using only one set of graphics or other generic subs. Maybe then Gordon R will get it. ;D (Of course I don't get what "LB5" is supposed to be at the JB forum.)
Speaking of things out of place:
sub place x , y print #handle$ , "goto " ; x ; " " ; y end sub
Nut tea! specially with all the ups and downs in some of the other subs B-/
|
|
|
Post by Gordon R on Jun 16, 2018 16:56:47 GMT
Gordon, You almost make that sound like a bad thing ;p no .... I just wanted to point out that I was thinking in term of open "LB 5 sim" for graphics as #m
#m "trapclose [quit]"
handle$ = "#m"
print lino(20,40,260,180)
wait
function lino(a,b,c,d)
call lino a,b,c,d
end function
sub lino x1 , y1 , x2 , y2
handle$ = "#m"
#handle$ "down"
#handle$ "line " ; x1 ; " " ; y1 ; " " ; x2 ; " " ; y2
#handle$ "up"
end sub
[quit]
close #m
end
Gordon
|
|