Post by bluatigro on Nov 21, 2018 4:53:20 GMT -5
this is the start many [blocks] of reusable code
as preperation on a set loadeble module's
so we can build code faster
every [block] starts whit whitch other [blocks] it needs
may be extended with more [blocks]
example :
[math].bas
''bluatigro 21 nov 2018
''math block
[math]
global pi , golden.ratio , true , false
pi = atn( 1 ) * 4
golden.ratio = ( sqr( 5 ) - 1 ) / 2
false = 0
true = not( false )
return
function range( l , h )
range = rnd(0) * ( h - l ) + l
end function
function iif( bool , t , f )
uit = f
if bool then uit = t
iif = uit
end function
function rad( deg )
''from degrees to radians
rad = deg * pi / 180
end function
sub rotate byref k , byref l , deg
s = sin( rad( deg ) )
c = cos( rad( deg ) )
hk = k * c - l * s
hl = k * s + l * c
k = hk
l = hl
end sub
example 2 :
''bluatigro 21 nov 2018
''color block
''needs math block
[color]
global black , red , green , yellow
global blue , magenta , cyan , white
global pink , orange , gray , purple
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 )
pink = rgb( 255 , 127 , 127 )
orange = rgb( 255 , 127 , 0 )
gray = rgb( 127 , 127 , 127 )
purple = rgb( 127 , 0 , 127 )
return
sub setcolor kl
r = int( kl and 255 )
g = int( kl / 256 ) and 255
b = int( kl / 256 / 256 ) and 255
print #m , "backcolor " ; r ;" "; g ; " "; b
print #m , "color " ; r ; " " ; g ; " " ; b
end sub
function rgb( r , g , b )
rgb = ( int( r ) and 255 ) _
+ ( int( g ) and 255 ) * 256 _
+ ( int( b ) and 255 ) * 256 * 256
end function
function rainbow( x )
r = sin( rad( x ) ) * 127 + 128
g = sin( rad( x - 120 ) ) * 127 + 128
b = sin( rad( x + 120 ) ) * 127 + 128
rainbow = rgb( r , g , b )
end function
function mix( kl1 , f , kl2 )
r1 = int( kl1 and 255 )
g1 = int( kl1 / 256 ) and 255
b1 = int( kl1 / 256 / 256 ) and 255
r2 = int( kl2 and 255 )
g2 = int( kl2 / 256 ) and 255
b2 = int( kl2 / 256 / 256 ) and 255
r = r1 + ( r2 - r1 ) * f
g = g1 + ( g2 - g1 ) * f
b = b1 + ( b2 - b1 ) * f
mix = rgb( r , g , b )
end function