array : how big ?
Post by bluatigro on Feb 17th, 2015, 12:35pm
error :
- number to big in line 0
Code:
dim h( 128 , 128 )
call hil 0,0,128,128,128
nomainwin
a$ = rgb$( 0 , 0 , 0 )
b$ = rgb$( 255 , 255 , 255 )
open "terain" for graphics as #m
#m "trapclose [quit]"
for x = 0 to 128
for y = 0 to 128
#m "color " ; color.mix$( a$ , h(x,y) , b$ )
#m "goto ";x;" ";y
#m "down"
#m "set ";x;" ";y
#m "up"
next y
next x
wait
[quit]
close #m
end
sub hil a , b , c , d , t
if abs( a - c ) < 1 then exit sub
h( a , (b+d)/2 ) = ( h( a , b ) + h( a , d ) ) / 2 + rnd(0)* t
h( c , (b+d)/2 ) = ( h( c , b ) + h( c , d ) ) / 2 + rnd(0)* t
h( (a+c)/2 , b ) = ( h( a , b ) + h( c , b ) ) / 2 + rnd(0)* t
h( (a+c)/2 , d ) = ( h( a , d ) + h( c , d ) ) / 2 + rnd(0)* t
h((a+c)/2,(b+d)/2)=(h(a,b)+h(a,d)+h(c,b)+h(c,d))/4 + rnd(0)* t
call hil a , b , (a+c)/2 , (b+d)/2 , t/2
call hil (a+c)/2 , b , c , (b+d)/2 , t/2
call hil a , (b+d)/2 , (a+c)/2 , d , t/2
call hil (a+c)/2 , (b+d)/2 , c , d , t/2
end sub
function rgb$( r , g , b )
''create a color-object$
r = r and 255
g = g and 255
b = b and 255
rgb$ = str$( r ); " " ; g * 256 ; " " ; b * 256 ^ 2
end function
function color.red( clr$ )
''get red part of color-object$
color.red = val( word$( clr$ , 1 ) )
end function
function color.green( clr$ )
''get green part of color-object$
color.green = val( word$( clr$ , 2 ) )
end function
function color.blue( clr$ )
''get blue part of color-object$
color.blue = val( word$( clr$ , 3 ) )
end function
function color.mix$( kl1$ , f , kl2$ )
''mix 2 color-object$ into 1 new
r1 = color.red( kl1$ )
g1 = color.green( kl1$ )
b1 = color.blue( kl1$ )
r2 = color.red( kl2$ )
g2 = color.green( kl2$ )
b2 = color.blue( kl2$ )
r = r1 + f * ( r2 - r1 )
g = g1 + f * ( g2 - g1 )
b = b1 + f * ( b2 - b1 )
color.mix$ = rgb$( r , g , b )
end function
function rainbow$( deg )
rainbow$ = rgb$( sin( rad( deg ) ) * 127 + 128 _
, sin( rad( deg + 120 ) ) * 127 + 128 _
, sin( rad( deg - 120 ) ) * 127 + 128 )
end function
Re: array : how big ?
Post by Richard Russell on Feb 17th, 2015, 12:53pm
on Feb 17th, 2015, 12:35pm, bluatigro wrote:error : - number too big in line 0 |
|
Not surprising! The graphics color command expects three parameters in the range 0 to 255; this is what you are sending:
Code:
Fix that, and the error will go away.
If you can't see your mistake, it's here:
Code: rgb$ = str$( r ); " " ; g * 256 ; " " ; b * 256 ^ 2
which needs to be changed to:
Code: rgb$ = str$( r ); " " ; g ; " " ; b
Richard.
Re: array : how big ?
Post by bluatigro on Feb 18th, 2015, 09:40am
thanks for help
i shoot have seen that myself
error :
- the output isnt clowdy | plasma like
Code:
dim h( 128 , 128 )
h(0,0)=rnd(0)*255
h(0,128)=rnd(0)*255
h(128,0)=rnd(0)*255
h(128,128)=rnd(0)*255
call hil 0,0,128,128,128
global pi
pi = atn( 1 ) * 4
nomainwin
a$ = rgb$( 0 , 0 , 0 )
b$ = rgb$( 255 , 255 , 255 )
open "terain" for graphics as #m
#m "trapclose [quit]"
for x = 0 to 128
for y = 0 to 128
#m "color " ; rainbow$( h(x,y) * 360 / 255 )
#m "goto " ; x ; " " ; y
#m "down"
#m "set " ; x ; " " ; y
#m "up"
next y
next x
wait
[quit]
close #m
end
sub hil a , b , c , d , t
if abs( a - c ) < 1 then exit sub
h( a , (b+d)/2 ) = ( h( a , b ) + h( a , d ) ) / 2 + rnd(0)* t
h( c , (b+d)/2 ) = ( h( c , b ) + h( c , d ) ) / 2 + rnd(0)* t
h( (a+c)/2 , b ) = ( h( a , b ) + h( c , b ) ) / 2 + rnd(0)* t
h( (a+c)/2 , d ) = ( h( a , d ) + h( c , d ) ) / 2 + rnd(0)* t
h((a+c)/2,(b+d)/2)=(h(a,b)+h(a,d)+h(c,b)+h(c,d))/4 + rnd(0)* t
call hil a , b , (a+c)/2 , (b+d)/2 , t/2
call hil (a+c)/2 , b , c , (b+d)/2 , t/2
call hil a , (b+d)/2 , (a+c)/2 , d , t/2
call hil (a+c)/2 , (b+d)/2 , c , d , t/2
end sub
function rgb$( r , g , b )
''create a color-object$
r = r and 255
g = g and 255
b = b and 255
rgb$ = str$( r ) ; " " ; g ; " " ; b
end function
function color.red( clr$ )
''get red part of color-object$
color.red = val( word$( clr$ , 1 ) )
end function
function color.green( clr$ )
''get green part of color-object$
color.green = val( word$( clr$ , 2 ) )
end function
function color.blue( clr$ )
''get blue part of color-object$
color.blue = val( word$( clr$ , 3 ) )
end function
function color.mix$( kl1$ , f , kl2$ )
''mix 2 color-object$ into 1 new
r1 = color.red( kl1$ )
g1 = color.green( kl1$ )
b1 = color.blue( kl1$ )
r2 = color.red( kl2$ )
g2 = color.green( kl2$ )
b2 = color.blue( kl2$ )
r = r1 + f * ( r2 - r1 )
g = g1 + f * ( g2 - g1 )
b = b1 + f * ( b2 - b1 )
color.mix$ = rgb$( r , g , b )
end function
function rainbow$( deg )
rainbow$ = rgb$( sin( rad( deg ) ) * 127 + 128 _
, sin( rad( deg + 120 ) ) * 127 + 128 _
, sin( rad( deg - 120 ) ) * 127 + 128 )
end function
function rad( deg )
rad = deg * pi / 180
end function
Re: array : how big ?
Post by bluatigro on Feb 20th, 2015, 09:19am
update :
- i got the tile problem fixed
- i took a my old freebasic program
and rebild it into LB
error :
- hill$() gives a black and white landscape
- so i used Rainbow$() as color sceme
WARNING :
- this wil take several minutes
Code:
global pi , black$ , white$ , gray$ , green$ , blue$
pi = atn( 1 ) * 4
black$ = rgb$( 0 , 0 , 0 )
white$ = rgb$( 255 , 255 , 255 )
gray$ = rgb$( 127 , 127 , 127 )
green$ = rgb$( 0 , 255 , 0 )
blue$ = rgb$( 0 , 0 , 255 )
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
dim h( winx , winx )
h( 0 , 0 ) = dice( 2 * pi )
h( winx , 0 ) = dice( 2 * pi )
h( 0 , winy ) = dice( 2 * pi )
h( winx , winy ) = dice( 2 * pi )
call lino 0 , 0 , winx , winy , 2 * pi
nomainwin
open "terain" for graphics as #m
#m "fill black"
for x = 1 to winx
for y = 0 to winy
#m "color " ; rainbow$( h( x , y ) )
#m "down"
#m "line " ; x ; " " ; y - h( x , y ) * 50 _
; " " ; x ; " " ; y - h( x , y ) * 50 - 10
#m "up"
next y
next x
wait
function dice( x )
dice = rnd( 0 ) * x - x / 2
end function
sub lino x1 , y1 , x2 , y2 , q
if abs( x1 - x2 ) < 1 then exit sub
mx = ( x1 + x2 ) / 2
my = ( y1 + y2 ) / 2
h1 = ( h( x1 , y1 ) + h( x2 , y1 ) ) / 2 + dice( q )
h2 = ( h( x1 , y2 ) + h( x2 , y2 ) ) / 2 + dice( q )
h3 = ( h( x1 , y1 ) + h( x1 , y2 ) ) / 2 + dice( q )
h4 = ( h( x2 , y1 ) + h( x2 , y2 ) ) / 2 + dice( q )
h5 = ( h( x1 , y1 ) + h( x2 , y1 ) _
+ h( x1 , y2 ) + h( x2 , y2 ) ) / 4 + dice( q )
if h( mx , y1 )= 0 then h( mx , y1 ) = h1
if h( mx , y2 )= 0 then h( mx , y2 ) = h2
if h( x1 , my )= 0 then h( x1 , my ) = h3
if h( x2 , my )= 0 then h( x2 , my ) = h4
if h( mx , my )= 0 then h( mx , my ) = h5
call lino x1 , y1 , mx , my , q / 2
call lino x1 , my , mx , y2 , q / 2
call lino mx , y1 , x2 , my , q / 2
call lino mx , my , x2 , y2 , q / 2
end sub
function rainbow$( x )
r = sin( x ) * 127 + 128
g = sin( x + pi * 2 / 3 ) * 127 + 128
b = sin( x - pi * 2 / 3 ) * 127 + 128
rainbow$ = rgb$( r , g , b )
end function
function hill$( x )
x = x + 2
uit$ = white$
if x < 0 then uit$ = black$
if x < 1 then uit$ = mix$( black$ , x , blue$ )
if x < 2 then uit$ = mix$( blue$ , x - 1 , green$ )
if x < 3 then uit$ = mix$( green$ , x - 2 , gray$ )
if x < 4 then uit$ = mix$( gray$ , x - 3 , white$ )
hill$ = uit$
end function
function mix$( kla$ , f , klb$ )
ra = val( word$( kla$ , 1 ) )
ga = val( word$( kla$ , 2 ) )
ba = val( word$( kla$ , 3 ) )
rb = val( word$( klb$ , 1 ) )
gb = val( word$( klb$ , 2 ) )
bb = val( word$( klb$ , 3 ) )
r = ra + ( rb - ra ) * f
g = ga + ( gb - ga ) * f
b = ba + ( bb - ba ) * f
mix$ = rgb$( r , g , b )
end function
function shade$( kl$ , f )
r = val( word$( kl$ , 1 ) )
g = val( word$( kl$ , 2 ) )
b = val( word$( kl$ , 3 ) )
r = r * f
g = g * f
b = b * f
shade$ = rgb$( r , g , b )
end function
function rgb$( r , g , b )
r = r and 255
g = g and 255
b = b and 255
rgb$ = str$( r ) ; " " ; g ; " " ; b
end function