|
Post by bluatigro on Jul 8, 2020 6:37:59 GMT -5
i tryed some graphics lb5 351 detects a error in rgb() what is not good at 'r=r and 255' ?
'' bluatigro 8 jul 2020 '' sphere 1.0 lb5 351
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winw , winh , height winw = WindowWidth winh = WindowHeight global black , red , green , yellow global blue , magenta , cyan , white black = rgb( 0 , 0 , 0 ) red = rgb( 255 , 0 , 0 ) green = rgb( 0 , 255 , 0 ) yellow = rgb( 255 , 255 , 0 ) blue = rgb( 0 , 0 , 255 ) magenta = rgb( 255 , 0 , 255 ) cyan = rgb( 0 , 255 , 255 ) white = rgb( 255 , 255 , 255 ) open "spheres 1.0" for graphics as #m #m "trapclose [quit]" for height = 0 to winh call sphere 0,50,0 , 50 , red next height wait [quit] close #m end ''color math function rgb( r , g , b ) r = r and 255 g = g and 255 b = b and 255 rgb = r + g * 256 + b * 256 * 256 end function function mix( kl1 , f , kl2 ) r1 = int( kl1 ) and 255 g1 = int( kl1 / 256 ) and 255 b1 = int( kl1 / 256 ^ 2 ) and 255 r2 = int( kl2 ) and 255 g2 = int( kl2 / 256 ) and 255 b2 = int( kl2 / 256 ^ 2 ) and 255 r = r1 + ( r2 - r1 ) * f g = g1 + ( g2 - g1 ) * f b = b1 + ( b2 - b1 ) * f mix = rgb( r , g , b ) end function sub sphere x,y,z , d , kl if abs( height - z ) < d then dd = sqr( d * d - ( height - z ) ^ 2 ) kl = mix( kl , ( height - z ) / d , black ) r = int( kl ) and 255 g = int( kl / 256 ) and 255 b = int( kl / 256 ^ 2 ) and 255 #m "color " ; r ; " " ; g ; " " ; b #m "backcolor " ; r ; " " ; g ; " " ; b #m "goto " ; x ; " " ; winh * 5 / 6 - height - z / 4 #m "down" #m "ellipsefilled " ; d ; " " ; d / 4 #m "up" end if end sub
|
|
|
Post by Gordon Rahman on Jul 9, 2020 9:51:55 GMT -5
I don't know why. But r isn't a integer after the first listing run?
r = 50
print 600 print print 600 and 255 print 88 and 255 print 0 and 255 r = r and 255 print r print "ok"
print print 600 print 600/256 print int(600/256) print int(600/256)*256 print 600 - int(600/256)*256 print 600 mod 256 print 88 mod 256 print "ok"
print print 600 'print ((600/256) and 255) gives an "error" print (int(600/256) and 255) 'gives NO "error" print "ok?"
This code runs at LB4 and LB5 (build 351) exactly the same ... with the same Error if you don't use r = int(r) and 255
r must be an integer.
Gordon
|
|
|
Post by Rod on Jul 9, 2020 11:29:15 GMT -5
Well you can still AND a float
print print 600 x=600/256 print x and 255 'works print (600/256) and 255 'does not work print (int(600/256) and 255) 'gives NO "error" print "ok?"
|
|
|
Post by Gordon Rahman on Jul 9, 2020 13:12:24 GMT -5
Well you can still AND a float print print 600 x=600/256 print x and 255 'works print (600/256) and 255 'does not work print (int(600/256) and 255) 'gives NO "error" print "ok?"
Rod, you're right. I should have said that print (600/256) and 255 will give an error in LB5 and LB4 print x and 255 works fine even if x is a float. print (int(600/256) and 255) gives no error. print int(600/256) and 255 is errorfree too. As print 600/256 and 255 also gives an error, my advice to Bluatigro is to use the int() to be sure. Gordon
|
|
|
Post by Gordon Rahman on Jul 9, 2020 16:25:10 GMT -5
LB5 has it's pen down automatically at the start. So now place .. needs a pen up.
'' bluatigro 8 jul 2020 '' sphere 1.0 lb5 351 nomainwin WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winw , winh , height winw = WindowWidth winh = WindowHeight global black , red , green , yellow global blue , magenta , cyan , white black = rgb( 0 , 0 , 0 ) red = rgb( 255 , 0 , 0 ) green = rgb( 0 , 255 , 0 ) yellow = rgb( 255 , 255 , 0 ) blue = rgb( 0 , 0 , 255 ) magenta = rgb( 255 , 0 , 255 ) cyan = rgb( 0 , 255 , 255 ) white = rgb( 255 , 255 , 255 ) open "spheres 1.0" for graphics as #m #m "trapclose [quit]" for height = 0 to winh call sphere 1400,850,200 , 150 , red next height wait [quit] close #m end ''color math function rgb( r , g , b ) r = int(r) and 255 g = int(g) and 255 b = int(b) and 255 rgb = r + g * 256 + b * 256 * 256 end function function mix( kl1 , f , kl2 ) r1 = int( kl1 ) and 255 g1 = int( kl1 / 256 ) and 255 b1 = int( kl1 / 256 ^ 2 ) and 255 r2 = int( kl2 ) and 255 g2 = int( kl2 / 256 ) and 255 b2 = int( kl2 / 256 ^ 2 ) and 255 r = r1 + ( r2 - r1 ) * f g = g1 + ( g2 - g1 ) * f b = b1 + ( b2 - b1 ) * f mix = rgb( r , g , b ) end function sub sphere x,y,z , d , kl if abs( height - z ) < d then dd = sqr( d * d - ( height - z ) ^ 2 ) kl = mix( kl , ( height - z ) / d , black ) r = int( kl ) and 255 g = int( kl / 256 ) and 255 b = int( kl / 256 ^ 2 ) and 255 #m "color " ; r ; " " ; g ; " " ; b #m "backcolor " ; r ; " " ; g ; " " ; b #m "up" #m "goto " ; x ; " " ; winh * 5 / 6 - height - z / 4 #m "down" #m "ellipsefilled " ; d ; " " ; d / 4 end if end sub
Gordon
|
|
|
Post by bluatigro on Jul 11, 2020 6:40:02 GMT -5
@ gordon : that helped a litle no more syntacks error's
error : my screen has only a red line
'' bluatigro 11 jul 2020 '' sphere 1.0 lb5 351
WindowWidth = DisplayWidth WindowHeight = DisplayWidth global winw , winh , height winw = WindowWidth winh = WindowHeight global black , red , green , yellow global blue , magenta , cyan , white black = rgb( 0 , 0 , 0 ) red = rgb( 255 , 0 , 0 ) green = rgb( 0 , 255 , 0 ) yellow = rgb( 255 , 255 , 0 ) blue = rgb( 0 , 0 , 255 ) magenta = rgb( 255 , 0 , 255 ) cyan = rgb( 0 , 255 , 255 ) white = rgb( 255 , 255 , 255 ) open "spheres 1.0" for graphics as #m #m "trapclose [quit]" for height = 0 to winh call sphere 0,50,0 , 50 , red next height wait [quit] close #m end ''color math function rgb( r , g , b ) r = int( r ) and 255 g = int( g ) and 255 b = int( b ) and 255 rgb = r + g * 256 + b * 256 * 256 end function function mix( kl1 , f , kl2 ) r1 = int( kl1 ) and 255 g1 = int( kl1 / 256 ) and 255 b1 = int( kl1 / 256 ^ 2 ) and 255 r2 = int( kl2 ) and 255 g2 = int( kl2 / 256 ) and 255 b2 = int( kl2 / 256 ^ 2 ) and 255 r = r1 + ( r2 - r1 ) * f g = g1 + ( g2 - g1 ) * f b = b1 + ( b2 - b1 ) * f mix = rgb( r , g , b ) end function sub sphere x,y,z , d , kl if abs( height - y ) < d then dd = sqr( d * d - ( height - y ) ^ 2 ) * 2 kl = mix( kl , ( height - y ) / d / 2 + .5 , black ) r = int( kl ) and 255 g = int( kl / 256 ) and 255 b = int( kl / 256 ^ 2 ) and 255 #m "color " ; r ; " " ; g ; " " ; b #m "backcolor " ; r ; " " ; g ; " " ; b #m "goto " ; winw / 2 + x ; " " ; winh * 5 / 6 - height - z / 4 #m "down" #m "ellipsefilled " ; dd ; " " ; dd / 4 #m "up" end if end sub
|
|
|
Post by Gordon Rahman on Jul 11, 2020 12:01:02 GMT -5
Hi Bluatigro, Syntax error in line with WindowWidth ... should be WindowHeight
And you changed your sub sphere. And your parameters for your new sub just gives a blank screen. Ooops and you have to put the pen up ... before the #w "goto" otherwise LB5 will draw a line.
Gordon
|
|
|
Post by Carl Gundel on Jul 11, 2020 15:27:14 GMT -5
Hi Bluatigro, Syntax error in line with WindowWidth ... should be WindowHeight And you changed your sub sphere. And your parameters for your new sub just gives a blank screen. Ooops and you have to put the pen up ... before the #w "goto" otherwise LB5 will draw a line. Gordon Do you think we should change it to force the programmer to use down?
|
|
|
Post by Rod on Jul 11, 2020 15:56:00 GMT -5
Place should just place the drawing point without drawing anything. Goto Go etc are logo commands and should draw and respect pen up pen down. Not sure if place is a logo command but if it is it would be natural for it to place the pen and not draw to it. So it should ignore the pen status and just move the drawing point.
Pen down by default is welcome because many current drawing actions outside of logo are caught by this trap. Drawbmp for example. There should be no need for down prior to drawbmp.
Put up and down fairly into logo territory and just let all other drawing happen.
So up is absolutely required before logo drawing is stopped and down for it to restart. If it can be constrained to logo commands all the better because it has flummoxed s good few folks doing normal drawing.
|
|
|
Post by Gordon Rahman on Jul 11, 2020 18:24:01 GMT -5
Place should just place the drawing point without drawing anything. Goto Go etc are logo commands and should draw and respect pen up pen down. Not sure if place is a logo command but if it is it would be natural for it to place the pen and not draw to it. So it should ignore the pen status and just move the drawing point. Pen down by default is welcome because many current drawing actions outside of logo are caught by this trap. Drawbmp for example. There should be no need for down prior to drawbmp. Put up and down fairly into logo territory and just let all other drawing happen. So up is absolutely required before logo drawing is stopped and down for it to restart. If it can be constrained to logo commands all the better because it has flummoxed s good few folks doing normal drawing. My apologies to everyone. The confusion is that I said that place needs a pen up. Bluatigro used "goto" in stead of "place" (while the pen was (automatic) down). I corrected the listing by placing a "pen up" in stead of correcting the "goto". sub sphere x,y,z , d , kl if abs( height - z ) < d then dd = sqr( d * d - ( height - z ) ^ 2 ) kl = mix( kl , ( height - z ) / d , black ) r = int( kl ) and 255 g = int( kl / 256 ) and 255 b = int( kl / 256 ^ 2 ) and 255 #m "color " ; r ; " " ; g ; " " ; b #m "backcolor " ; r ; " " ; g ; " " ; b
#m "up" '<<<<<< added by me #m "goto " ; x ; " " ; winh * 5 / 6 - height - z / 4 #m "down" '<<<<<< added by me
#m "ellipsefilled " ; d ; " " ; d / 4 end if end sub I should have done it better. Not solving the problem but point to the mistake. So, to Carl, it's right as LB5 does it. Gordon
|
|
|
Post by Gordon Rahman on Jul 13, 2020 10:50:16 GMT -5
and to be complete....
place() works perfect in LB5 (as well as the LB4 style "place x y" does} But goto() is not yet implemented in LB5, while the old LB4 style "goto x y" already works great.
So I advice everybody to use place instead of (pen up, goto ,pen down) in LB4 and LB5
Gordon
|
|