Post by bluatigro on Apr 14, 2018 5:00:40 GMT -5
this is example on how to do OOP in LB
if you want to do this yourself :
create a globel object
create a constructor-sub
create operator-sub's and function's :
al property's in paramerters
do math
use constructor-sub for creating object
rem :
you may use your one covention's for naming sub's and function's
but for readebilety use myne
if you want to do this yourself :
create a globel object
create a constructor-sub
create operator-sub's and function's :
al property's in paramerters
do math
use constructor-sub for creating object
rem :
you may use your one covention's for naming sub's and function's
but for readebilety use myne
''bluatigro 16 apr 2018
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , pi
''create global object for output of OOP sub's
''string's are posible too
global complex.r , complex.i
winx = WindowWidth
winy = WindowHeight
pi = atn( 1 ) * 4
nomainwin
prompt "X = " ; x$
prompt "Y = " ; y$
prompt "D = " ; d$
mx = val( x$ )
my = val( y$ )
d = val( d$ )
open "madelbrot oop" for graphics as #m
#m "trapclose [quit]"
#m "font 30 bold"
#m "goto 10 30"
#m "\ X = " ; mx
#m "goto 10 100"
#m "\ Y = " ; my
#m "goto 10 170"
#m "\ D = " ; d
for a = -100 to 100
for b = -100 to 100
scan
aa = a / 50 * d + mx
bb = b / 50 * d + my
tel = 0
x = aa
y = bb
while tel < 50 and complex.length( x , y ) < 50
tel = tel + 1
call complex.mul x,y , x,y
call complex.add complex.r,complex.i , aa,bb
x = complex.r
y = complex.i
wend
if tel >= 50 then
#m "color black"
else
#m "color " ; rainbow$( tel * 5 )
end if
#m "goto " ; winx / 2 + a ; " " ; winy / 2 + b
#m "down"
#m "set " ; winx / 2 + a ; " " ; winy / 2 + b
#m "up"
next b
next a
notice "ready !!"
wait
[quit]
close #m
end
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
function rainbow$( deg )
r = sin( rad( deg ) ) * 127 + 128
g = sin( rad( deg - 120 ) ) * 127 + 128
b = sin( rad( deg + 120 ) ) * 127 + 128
rainbow$ = rgb$( r , g , b )
end function
function rad( deg )
rad = deg * pi / 180
end function
sub complex a , b
''constructor :
''create output object
complex.r = a
complex.i = b
end sub
''example OOP sub's
sub complex.add a1 , b1 , a2 , b2
call complex a1 + a2 , b1 + b2
end sub
sub complex.sub a1 , b1 , a2 , b2
call complex a1 - a2 , b1 - b2
end sub
sub complex.mul a1 , b1 , a2 , b2
call complex a1 * a2 - b1 * b2 , a1 * b2 + a2 * b1
end sub
sub complex.div a1 , b1 , a2 , b2
q = a2 * a2 + b2 * b2
call complex ( a1 * a2 + b1 * b2 ) / q _
, ( a2 * b1 - a1 * b2 ) / q
end sub
function complex.length( a , b )
complex.length = sqr( a^2 + b^2 )
end function
sub complex.sqr a1 , b1
q = complex.length( a1 , b1 )
a = sqr( ( a1 + q ) / 2 )
b = 2 * a
b = b1 / b
call complex a , b
end sub
sub complex.ln a1 , b1
call complex log( complex.length( a1 , b1 ) ) _
, atn( b1 / a1 )
end sub
sub complex.exp a1 , b1
call complex exp( a1 ) * cos( b1 ) _
, exp( a1 ) * sin( b1 )
end sub