Object Oriented Liberty BASIC?
Post by Richard Russell on Jun 8th, 2014, 09:39am
It's been suggested that it could be useful to add some simple OO (Object Oriented) features to LBB. That's certainly something I would be prepared to consider, but I'm not sure what the take-up would be. The impression I get is that a lot of LB programmers are quite 'old school' - too often I see programs that still use GOSUB! - and might find OO programming rather 'alien'.
If I were to go down that route I would expect to add the following keywords initially: CLASS, METHOD, NEW (or NEWOBJECT), DISCARD, INHERIT. They would support the fundamental operations necessary to create and manipulate objects. Note that it almost certainly wouldn't be practical to implement automatic object destruction when dropping out of 'scope'.
I would appreciate some feedback on this. Would you actually use such a feature if it was added?
Richard.
Re: Object Oriented Liberty BASIC?
Post by lancegary on Jun 8th, 2014, 10:17pm
Sounds a great idea though I would have to learn how to use them.
Thanks for the recent update as well.
Lance
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Jun 15th, 2014, 8:30pm
The conventional syntax for accessing an object method or field (member variable) would be to use a dot, such as object.method() or object.field, but the fact that a dot is a valid character in an LB identifier complicates things.
LB resolves the ambiguity in respect of structure members by adding the .struct suffix, and in principle it would be possible to adopt a similar syntax such as .object, but personally I think this is ugly.
So I am currently thinking that an OOP extension for LB could instead use the scope resolution operator ::, for example object::method() or object::field. In languages which use both the dot and :: notations there is a subtle difference in their meaning, but I am hoping that would only worry purists!
What do people think?
Richard.
Re: Object Oriented Liberty BASIC?
Post by lancegary on Jun 17th, 2014, 2:12pm
on Jun 15th, 2014, 8:30pm, Richard Russell wrote:The conventional syntax for accessing an object method or field (member variable) would be to use a dot, such as object.method() or object.field, but the fact that a dot is a valid character in an LB identifier complicates things.
LB resolves the ambiguity in respect of structure members by adding the .struct suffix, and in principle it would be possible to adopt a similar syntax such as .object, but personally I think this is ugly.
So I am currently thinking that an OOP extension for LB could instead use the scope resolution operator ::, for example object::method() or object::field. In languages which use both the dot and :: notations there is a subtle difference in their meaning, but I am hoping that would only worry purists!
What do people think?
Richard. |
|
I don't know enough to comment intelligently. The double colon is used in Fortran, I think. The subtle difference escapes me, however. They say beautiful aircraft fly well and mathematicians believe that all good maths is elegant or beautiful. So if the notation system seems elegant to you I'm sure it will be a pleasure for us to use.
Lance
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Jun 22nd, 2014, 7:38pm
The lack of feedback possibly indicates that people can't see the benefit in Object Oriented extensions to LBB. Here's an illustration (adapted from a Visual BASIC example) of how OOP features can be used simply to provide data structures which are otherwise not available in LB; in this case there are no 'methods' (subs or functions) in the classes:
Code: Dim person(10) As Person
person(9)::Name$(1) = "John"
person(9)::Name$(2) = "Smith"
person(9)::address1::Street$(1) = "10"
person(9)::address1::Street$(2) = "Royal Avenue"
person(9)::address1::City$ = "Beverly Hills"
person(9)::address1::Zip$ = "90210"
Print person(9)::Name$(1); " ";
Print person(9)::Name$(2)
Print person(9)::address1::Street$(1); " ";
Print person(9)::address1::Street$(2)
Print person(9)::address1::Zip$
Discard person()
End
Class Person
Dim Name$(2), address1 As Address
End Class
Class Address
Dim Street$(3), City$, Zip$
End Class
Richard.
Re: Object Oriented Liberty BASIC?
Post by Sean on Jun 23rd, 2014, 10:39am
I would love to have OOPS, but we (the lb'ers) were kept waiting and are still waiting I think we have moved on. Does BBC basic support OOPS? I have moved on to AutoIt and Lazarus myself.
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Jun 24th, 2014, 1:38pm
on Jun 23rd, 2014, 10:39am, Sean wrote:I would love to have OOPS, but we (the lb'ers) were kept waiting and are still waiting I think we have moved on. Does BBC basic support OOPS? I have moved on to AutoIt and Lazarus myself. |
|
I see. If you feel like that, why did you join this forum?
Richard.
Re: Object Oriented Liberty BASIC?
Post by Sean on Jun 24th, 2014, 2:34pm
To praise your work. LBB definitely is going into my toolkit.
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Jan 20th, 2015, 09:06am
i wood like it when
objects can be stored sepredly
in a *.bas
and can be added whit a 'import'
or 'include' comand
and i like to have operator overloading
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Jan 20th, 2015, 09:17am
on Jan 20th, 2015, 09:06am, bluatigro wrote:and can be added whit a 'import' or 'include' command |
|
LBB has an 'include command. It works in a similar fashion to LB Workshop's include command, except that in LBW the included code is appended to the program, whereas in LBB it is inserted where the include statement is:
http://www.lbbooster.com/lbb.html#directives
The command is only recognised if it starts in the first column; preceding whitespace is not accepted. Also, for compatibility with LBW, 'include is ignored if it is at the very start of the program:
Code:'ensure include is not the first line
'include mylib.bas
Edit:
Quote:and i like to have operator overloading |
|
Isn't 'operator overloading' useful only if the language has user-defined data types? Liberty BASIC doesn't (it has just numbers and strings).
Effectively there is already operator overloading to the extent that the + operator means different things for numbers and strings. Also, in LBB, some operators work on complete arrays:
Code:
Richard.
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Jan 20th, 2015, 11:11am
'include error ?
or wat else do i wrong ?
_math.bas Code:
''bluatigro 20 jan 2015 :
''_math.bas
global pi , golden.ratio
pi = atn( 1 ) * 4
golden.ratio = ( sqr( 5 ) - 1 ) / 2
global true , false
true = not( false )
end
function rad( deg )
rad = deg * pi / 180
end function
_color.bas Code:
'include _math.bas
''bluatigro 20 jan 2015 :
''_color.bas
global black$ , red$ , green$ , yellow$
global blue$ , magenta$ , cyan$ , white$
global gray$ , pink$ , purple$ , orange$
black$ = rgb$( 000 , 000 , 000 )
red$ = rgb$( 255 , 000 , 000 )
green$ = rgb$( 000 , 255 , 000 )
yellow$ = rgb$( 255 , 255 , 000 )
blue$ = rgb$( 000 , 000 , 255 )
magenta$ = rgb$( 255 , 000 , 255 )
cyan$ = rgb$( 000 , 255 , 255 )
white$ = rgb$( 255 , 255 , 255 )
gray$ = rgb$( 127 , 127 , 127 )
pink$ = rgb$( 255 , 127 , 127 )
purple$ = rgb$( 127 , 000 , 127 )
orange$ = rgb$( 255 , 127 , 000 )
end
function rgb$( r , g , b )
r = r and 255
g = g and 255
b = b and 255
rgb$ = str$( r ); " " ; g * 256 ; " " ; b * 256 ^ 2
end function
function red( clr$ )
red = val( word$( clr$ , 1 ) )
end function
function green( clr )
green = val( word$( clr$ , 2 ) )
end function
function blue( clr$ )
blue = val( word$( clr$ , 3 ) )
end function
function klmix$( kl1$ , f , kl2$ )
r1 = red( kl1$ )
g1 = green( kl1$ )
b1 = blue( kl1$ )
r2 = red( kl2$ )
g2 = green( kl2$ )
b2 = blue( kl2$ )
r = r1 + f * ( r2 - r1 )
g = g1 + f * ( g2 - g1 )
b = b1 + f * ( b2 - b1 )
klmix$ = 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
_sphere.bas Code:
'include _color.bas
''bluatigro 20 jan 1015
''_sphere.bas
WindowWidth = DisplayWitdh
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global height
sub sphere h$ , x , y , z , d , clr$
if abs( height - y ) < d then
dd = sqr( d ^ 2 - ( height - y ) ^ 2 + .001 ) * 2
kl$ = mix$( clr$ , .5 - ( height - y ) / d / 2 , black$ )
#h$ "goto " ; x + winx / 2 ;" "; winy / 2 - height - z / 4
#h$ "backcolor " ; kl$
#h$ "color" ; kl$
#h$ "down"
#h$ "ellipsefilled "; dd ;" "; dd / 4
#h$ "up"
end if
end sub
main Code:
'include "_sphere.bas"
nomainwin
open "sphere-test" for graphics as #m
#m "trapclose [quit]"
for height = 0-winy/2 to winy/2
call sphere #m , 0 , 0 , 0 , 50 , red$
next height
wait
[quit]
close #m
end
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Jan 20th, 2015, 11:24am
on Jan 20th, 2015, 11:11am, bluatigro wrote:
Nothing "wrong" exactly, but you are hoping that 'include can be 'nested', i.e. that one included file can include another file, etc. Unfortunately it doesn't work like that in LBB, you can only use 'include in your 'main program':
Code:nomainwin
open "sphere-test" for graphics as #m
#m "trapclose [quit]"
for height = 0-winy/2 to winy/2
call sphere #m , 0 , 0 , 0 , 50 , red$
next height
wait
[quit]
close #m
end
'include _sphere.bas
'include _math.bas
'include _color.bas
As far as I'm aware LB Workshop's include has the same limitation.
Richard
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Jan 20th, 2015, 2:06pm
i tryed this Code:
nomainwin
open "" for graphics as #m
#m "trapclose [quit]"
#m "fill black"
for height = 0-winy/2 to winy/2
call sphere 0 , 0 , 0 , 50 , red$
next height
wait
[quit]
close #m
end
'include _math.bas
'include _color.bas
'include _sphere.bas
Code:
''bluatigro 20 jan 1015
''_sphere.bas
WindowWidth = DisplayWitdh
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global height
sub sphere x , y , z , d , clr$
if abs( height - y ) < d then
dd = sqr( d ^ 2 - ( height - y ) ^ 2 + .001 ) * 2
kl$ = mix$( clr$ , .5 - ( height - y ) / d / 2 , black$ )
#m "goto " ; x + winx / 2 ;" "; winy / 2 - height - z / 4
#m "backcolor " ; kl$
#m "color" ; kl$
#m "down"
#m "ellipsefilled "; dd ;" "; dd / 4
#m "up"
end if
end sub
_math.bas and _color.bas are not changed
error :
- where is my red sphere
- the window isnt fulscreen
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Jan 20th, 2015, 4:42pm
on Jan 20th, 2015, 2:06pm, bluatigro wrote:- where is my red sphere - the window isnt fulscreen |
|
I think your problem is that the code is now in the wrong sequence. Your 'included' file _sphere.bas contains both initialisation code which must come before the 'open for graphics' (e.g. setting WindowWidth and WindowHeight) and code which must come after the open statement (e.g. sub sphere). That can't work!
You either need to transfer the initialisation code into the 'main program', or you need to split your included file into two parts (e.g. _sphereinit.bas and _spheresub.bas) so you can include them in different places:
Code:nomainwin
'include _sphereinit.bas
open "" for graphics as #m
#m "trapclose [quit]"
#m "fill black"
for height = 0-winy/2 to winy/2
call sphere 0 , 0 , 0 , 50 , red$
next height
wait
[quit]
close #m
end
'include _spheresub.bas
There's nothing 'magic' about 'include: the resulting 'merged' program must follow all the usual rules governing the order in which things are declared.
Richard.
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Jan 23rd, 2015, 11:30am
update :
- all global's are now in *_init.bas
error :
- same errors
Code:
'include _fullscreen_init.bas
'include _math_init.bas
'include _color_init.bas
'include _sphere_init.bas
nomainwin
open "" for graphics as #m
#m "trapclose [quit]"
#m "fill black"
for height = 0-winy/2 to winy/2
call sphere 0 , 0 , 0 , 50 , red$
next height
wait
[quit]
close #m
end
'include _math.bas
'include _color.bas
'include _sphere.bas
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Jan 23rd, 2015, 11:39am
on Jan 23rd, 2015, 11:30am, bluatigro wrote:all global's are now in *_init.bas same errors |
|
As documented, LBB ignores 'include directives at the very start of the program (this is to maximise compatibility with LB Workshop). If your code is exactly as you listed, that will be the explanation. Add at least one line before the first include:
Code:
' the first line must not be an include
'include _fullscreen_init.bas
'include _math_init.bas
'include _color_init.bas
'include _sphere_init.bas
nomainwin
open "" for graphics as #m
#m "trapclose [quit]"
#m "fill black"
for height = 0-winy/2 to winy/2
call sphere 0 , 0 , 0 , 50 , red$
next height
wait
[quit]
close #m
end
'include _math.bas
'include _color.bas
'include _sphere.bas
Richard.
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Jan 24th, 2015, 1:41pm
tryed Code:
''bluatigro 24 jan 2015
''sphere_test.bas
'include _fullscreen_init.bas
'include _math_init.bas
'include _color_init.bas
'include _sphere_init.bas
nomainwin
open "" for graphics as #m
#m "trapclose [quit]"
#m "fill " ; black$
for height = 0-winy/2 to winy/2
call sphere 0 , 0 , 0 , 50 , red$
next height
wait
[quit]
close #m
end
'include _math.bas
'include _color.bas
'include _sphere.bas
stil not working
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Jan 24th, 2015, 2:28pm
on Jan 24th, 2015, 1:41pm, bluatigro wrote:
This works perfectly for me:
_math_init.bas:
Code:global pi , golden.ratio
pi = atn( 1 ) * 4
golden.ratio = ( sqr( 5 ) - 1 ) / 2
global true , false
true = not( false )
_color_init.bas:
Code:global black$ , red$ , green$ , yellow$
global blue$ , magenta$ , cyan$ , white$
global gray$ , pink$ , purple$ , orange$
black$ = rgb$( 000 , 000 , 000 )
red$ = rgb$( 255 , 000 , 000 )
green$ = rgb$( 000 , 255 , 000 )
yellow$ = rgb$( 255 , 255 , 000 )
blue$ = rgb$( 000 , 000 , 255 )
magenta$ = rgb$( 255 , 000 , 255 )
cyan$ = rgb$( 000 , 255 , 255 )
white$ = rgb$( 255 , 255 , 255 )
gray$ = rgb$( 127 , 127 , 127 )
pink$ = rgb$( 255 , 127 , 127 )
purple$ = rgb$( 127 , 000 , 127 )
orange$ = rgb$( 255 , 127 , 000 )
_sphere_init.bas:
Code:WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global height
_math.bas:
Code:function rad( deg )
rad = deg * pi / 180
end function
_color.bas:
Code:function rgb$( r , g , b )
r = r and 255
g = g and 255
b = b and 255
rgb$ = str$( r ); " " ; g * 256 ; " " ; b * 256 ^ 2
end function
function red( clr$ )
red = val( word$( clr$ , 1 ) )
end function
function green( clr$ )
green = val( word$( clr$ , 2 ) )
end function
function blue( clr$ )
blue = val( word$( clr$ , 3 ) )
end function
function klmix$( kl1$ , f , kl2$ )
r1 = red( kl1$ )
g1 = green( kl1$ )
b1 = blue( kl1$ )
r2 = red( kl2$ )
g2 = green( kl2$ )
b2 = blue( kl2$ )
r = r1 + f * ( r2 - r1 )
g = g1 + f * ( g2 - g1 )
b = b1 + f * ( b2 - b1 )
klmix$ = 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
_sphere.bas:
Code:sub sphere h$, x , y , z , d , clr$
if abs( height - y ) < d then
dd = sqr( d ^ 2 - ( height - y ) ^ 2 + .001 ) * 2
kl$ = klmix$( clr$ , .5 - ( height - y ) / d / 2 , black$ )
#h$ "goto " ; x + winx / 2 ;" "; winy / 2 - height - z / 4
#h$ "backcolor " ; kl$
#h$ "color " ; kl$
#h$ "down"
#h$ "ellipsefilled "; dd ;" "; dd / 4
#h$ "up"
end if
end sub
Main Program:
Code:''bluatigro 24 jan 2015
''sphere_test.bas
'include _math_init.bas
'include _color_init.bas
'include _sphere_init.bas
nomainwin
open "" for graphics as #m
#m "trapclose [quit]"
#m "fill " ; black$
for height = 0-winy/2 to winy/2
call sphere "#m", 0 , 0 , 0 , 50 , red$
next height
wait
[quit]
close #m
end
'include _math.bas
'include _color.bas
'include _sphere.bas
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Jan 29th, 2015, 08:44am
update :
- _sphere.bas extended whit 'egg'
error ? :
- i got the same as you
- but i got a white screen whit nothing
_sphere.bas Code:
''bluatigro 29 jan 1015
''_sphere.bas
sub sphere x , y , z , d , clr$
if abs( height - y ) < d then
dd = sqr( d ^ 2 - ( height - y ) ^ 2 + .001 ) * 2
kl$ = color.mix$( clr$ , .5 - ( height - y ) / d / 2 , black$ )
#m "goto " ; x + winx / 2 ; " " ; winy / 2 - height - z / 4
#m "backcolor " ; kl$
#m "color" ; kl$
#m "down"
#m "ellipsefilled "; dd ;" "; dd / 4
#m "up"
end if
end sub
sub egg x1 , y1 , z1 , d1 , x2 , y2 , z2 , d2 , dm , kl$ , no
af = sqr( ( x1 - x2 ) ^ 2 _
+ ( y1 - y2 ) ^ 2 + ( z1 - z2 ) ^ 2 + 1 )
dx = ( x2 - x1 ) / af
dy = ( y2 - y1 ) / af
dz = ( z2 - z1 ) / af
dd = ( d2 - d1 ) / af
dh = ( d1 + d2 ) / 2
if no < 2 then no = af
if no > af then no = af
for i = 0 to af step af / no
call sphere x1 + dx * i _
, y1 + dy * i , z1 + dz * i _
, d1 + dd * i + sin( i * pi / af ) _
* ( dm - dh ) , kl$
next i
end sub
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Feb 6th, 2015, 10:17am
i tested the stuff in 1 file
i got a black screen whit nothing
Code:
''bluatigro 6 feb 2015
''sphere_test_2.bas
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global pi , golden.ratio
pi = atn( 1 ) * 4
golden.ratio = ( sqr( 5 ) - 1 ) / 2
global true , false
true = not( false )
global black$ , red$ , green$ , yellow$
global blue$ , magenta$ , cyan$ , white$
global gray$ , pink$ , purple$ , orange$
black$ = rgb$( 000 , 000 , 000 )
red$ = rgb$( 255 , 000 , 000 )
green$ = rgb$( 000 , 255 , 000 )
yellow$ = rgb$( 255 , 255 , 000 )
blue$ = rgb$( 000 , 000 , 255 )
magenta$ = rgb$( 255 , 000 , 255 )
cyan$ = rgb$( 000 , 255 , 255 )
white$ = rgb$( 255 , 255 , 255 )
gray$ = rgb$( 127 , 127 , 127 )
pink$ = rgb$( 255 , 127 , 127 )
purple$ = rgb$( 127 , 000 , 127 )
orange$ = rgb$( 255 , 127 , 000 )
global height
nomainwin
open "" for graphics as #m
#m "trapclose [quit]"
#m "fill " ; black$
for height = 0-winy/2 to winy/2
call sphere 0 , 0 , 0 , 50 , red$
next height
wait
[quit]
close #m
end
''math
function rad( deg )
rad = deg * pi / 180
end function
function range( l , h )
range = rnd(0) * ( h - l ) + l
end sub
function nr$( no , max )
nr$ = right$( "00000000" ; no , max )
end function
''color
function rgb$( r , g , b )
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$ )
color.red = val( word$( clr$ , 1 ) )
end function
function color.green( clr$ )
color.green = val( word$( clr$ , 2 ) )
end function
function color.blue( clr$ )
color.blue = val( word$( clr$ , 3 ) )
end function
function color.mix$( kl1$ , f , kl2$ )
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 )
klmix$ = 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
''sphere
sub sphere x , y , z , d , clr$
if abs( height - y ) < d then
dd = sqr( d ^ 2 - ( height - y ) ^ 2 + .001 ) * 2
kl$ = color.mix$( clr$ , .5 - ( height - y ) / d / 2 , black$ )
#m "goto " ; x + winx / 2 ; " " ; winy / 2 - height - z / 4
#m "backcolor " ; kl$
#m "color" ; kl$
#m "down"
#m "ellipsefilled "; dd ;" "; dd / 4
#m "up"
end if
end sub
sub egg x1 , y1 , z1 , d1 , x2 , y2 , z2 , d2 , dm , kl$ , no
af = sqr( ( x1 - x2 ) ^ 2 _
+ ( y1 - y2 ) ^ 2 + ( z1 - z2 ) ^ 2 + 1 )
dx = ( x2 - x1 ) / af
dy = ( y2 - y1 ) / af
dz = ( z2 - z1 ) / af
dd = ( d2 - d1 ) / af
dh = ( d1 + d2 ) / 2
if no < 2 then no = af
if no > af then no = af
for i = 0 to af step af / no
call sphere x1 + dx * i _
, y1 + dy * i , z1 + dz * i _
, d1 + dd * i + sin( i * pi / af ) _
* ( dm - dh ) , kl$
next i
end sub
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Feb 6th, 2015, 11:01am
on Feb 6th, 2015, 10:17am, bluatigro wrote:i got a black screen whit nothing |
|
Two mistakes:
Code:
klmix$ = rgb$( r , g , b )
should be:
color.mix$ = rgb$( r , g , b )
and:
Code:
#m "color" ; kl$
should be:
#m "color " ; kl$
Richard.
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Feb 6th, 2015, 12:36pm
@ richard :
- i changed the include *.bas to
error :
- i got a smal white screen
Code:
''bluatigro 6 feb 2015
''_color.bas
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
Code:
''bluatigro 6 feb 2015
''_sphere.bas
sub sphere x , y , z , d , clr$
if abs( height - y ) < d then
dd = sqr( d ^ 2 - ( height - y ) ^ 2 + .001 ) * 2
kl$ = color.mix$( clr$ , .5 - ( height - y ) / d / 2 , black$ )
#m "goto " ; x + winx / 2 ; " " ; winy / 2 - height - z / 4
#m "backcolor " ; kl$
#m "color " ; kl$
#m "down"
#m "ellipsefilled "; dd ; " " ; dd / 4
#m "up"
end if
end sub
sub egg x1 , y1 , z1 , d1 , x2 , y2 , z2 , d2 , dm , kl$ , no
af = sqr( ( x1 - x2 ) ^ 2 _
+ ( y1 - y2 ) ^ 2 + ( z1 - z2 ) ^ 2 + 1 )
dx = ( x2 - x1 ) / af
dy = ( y2 - y1 ) / af
dz = ( z2 - z1 ) / af
dd = ( d2 - d1 ) / af
dh = ( d1 + d2 ) / 2
if no < 2 then no = af
if no > af then no = af
for i = 0 to af step af / no
call sphere x1 + dx * i _
, y1 + dy * i , z1 + dz * i _
, d1 + dd * i + sin( i * pi / af ) _
* ( dm - dh ) , kl$
next i
end sub
Code:
''bluatigro 6 feb 2015
''sphere_test_2.bas
'include _fullscreen_init.bas
'include _math_init.bas
'include _color_init.bas
global height
nomainwin
open "" for graphics as #m
#m "trapclose [quit]"
#m "fill " ; black$
for height = 0-winy/2 to winy/2
call sphere 0 , 0 , 0 , 50 , red$
next height
wait
[quit]
close #m
end
'include _math.bas
'include _color.bas
'include _sphere.bas
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Feb 6th, 2015, 1:28pm
on Feb 6th, 2015, 12:36pm, bluatigro wrote:error : - i got a smal white screen |
|
The beta version of LBB you have contains File... Insert and File... Compare so I suggest you replace each 'include directive with the file itself, and then compare the merged result with the working version.
Generally, I would recommend only using 'include with modules that have been thoroughly tested and are known to work. Otherwise it's too difficult to debug a program using includes.
Richard.
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Feb 8th, 2015, 09:05am
in the begining it was 1 file
but i splitted it later
because i want to write in parts
so i dont have to write it twice or more
i want to extend this farder whit more parts
[ see 3d line cubes ]
and i can only post 10K here
in the future my files wil be bigger if i dont use include
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Feb 8th, 2015, 10:03am
@ richard :
- i tryed it
i got rid of al the errors
working Code:
''bluatigro 8 feb 2015
''sphere_test_3.bas
''bluatigro 8 feb 2015
''_fullscreen_init.bas
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
''bluatigro 8 feb 2015
''_math_init.bas
global pi , golden.ratio
pi = atn( 1 ) * 4
golden.ratio = ( sqr( 5 ) - 1 ) / 2
global true , false
true = not( false )
''bluatigro 8 feb 2015
''_color_init.bas
global black$ , red$ , green$ , yellow$
global blue$ , magenta$ , cyan$ , white$
global gray$ , pink$ , purple$ , orange$
black$ = rgb$( 000 , 000 , 000 )
red$ = rgb$( 255 , 000 , 000 )
green$ = rgb$( 000 , 255 , 000 )
yellow$ = rgb$( 255 , 255 , 000 )
blue$ = rgb$( 000 , 000 , 255 )
magenta$ = rgb$( 255 , 000 , 255 )
cyan$ = rgb$( 000 , 255 , 255 )
white$ = rgb$( 255 , 255 , 255 )
gray$ = rgb$( 127 , 127 , 127 )
pink$ = rgb$( 255 , 127 , 127 )
purple$ = rgb$( 127 , 000 , 127 )
orange$ = rgb$( 255 , 127 , 000 )
global height
nomainwin
open "" for graphics as #m
#m "trapclose [quit]"
#m "fill " ; black$
for height = 0-winy/2 to winy/2
call sphere 0 , 0 , 0 , 50 , red$
next height
wait
[quit]
close #m
end
''bluatigro 8 feb 2015
''_math.bas
function rad( deg )
''calculate radians outof degrees
rad = deg * pi / 180
end function
function range( low , high )
''get a random double between low and high
range = rnd(0) * ( high - low ) + low
end sub
function nr$( no , max )
''format a number into a string
nr$ = right$( "0000000000" ; no , max )
end function
''bluatigro 8 feb 2015
''_color.bas
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
''bluatigro 8 feb 2015
''_sphere.bas
sub sphere x , y , z , d , clr$
if abs( height - y ) < d then
dd = sqr( d ^ 2 - ( height - y ) ^ 2 + .001 ) * 2
kl$ = color.mix$( clr$ , .5 - ( height - y ) / d / 2 , black$ )
#m "goto " ; x + winx / 2 ; " " ; winy / 2 - height - z / 4
#m "backcolor " ; kl$
#m "color " ; kl$
#m "down"
#m "ellipsefilled "; dd ; " " ; dd / 4
#m "up"
end if
end sub
sub egg x1 , y1 , z1 , d1 , x2 , y2 , z2 , d2 , dm , kl$ , no
af = sqr( ( x1 - x2 ) ^ 2 _
+ ( y1 - y2 ) ^ 2 + ( z1 - z2 ) ^ 2 + 1 )
dx = ( x2 - x1 ) / af
dy = ( y2 - y1 ) / af
dz = ( z2 - z1 ) / af
dd = ( d2 - d1 ) / af
dh = ( d1 + d2 ) / 2
if no < 2 then no = af
if no > af then no = af
for i = 0 to af step af / no
call sphere x1 + dx * i _
, y1 + dy * i , z1 + dz * i _
, d1 + dd * i + sin( i * pi / af ) _
* ( dm - dh ) , kl$
next i
end sub
but when i split it it does not work . why ?
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Feb 8th, 2015, 10:10am
on Feb 8th, 2015, 10:03am, bluatigro wrote:@but when i split it it does not work . why ? |
|
I do not believe it. Splitting a program into multiple modules makes no difference; when you run it, it is the same program (apart from the line numbers).
I listed in an earlier post a fully working 'sphere' program split into multiple modules. If necessary go back to that:
http://lbb.conforums.com/index.cgi?board=general&action=display&num=1402220363&start=17
Richard.
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Feb 9th, 2015, 09:08am
@richard :
- done what you sugested
got same smal white screen
title : sphere_test.lbb.tmp
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Feb 14th, 2015, 11:43am
a try at OOP Code:
new p as t3d 255 , 3 , 6
new p1 as t3d 4 , 4 , 4
print p::toStr$()
print p1::toStr$()
''next line goes also wrong whit "!" in front
''p = p::add( p1 )
print p::toStr$()
discard p
discard p1
end
class t3d
dim x , y , z
sub t3d
x = 0
y = 0
z = 0
end sub
sub t3d nx , ny , nz
x = nx
y = ny
z = nz
end sub
function get.x
get.x = x
end function
function get.y
get.y = y
end function
function get.z
get.z = z
end function
! function add( a as t3d ) as t3d
new q as t3d x+a::get.x() , y+a::get.y() , z+a::get.z()
add = q
discard q
end function
function toStr$()
''this is now right
toStr$ = "( " + str$( this::get.x() ) _
+ " , " + str$( this::get.y() ) _
+ " , " + str$( this::get.z() ) + " )"
end function
end class
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Feb 28th, 2015, 3:06pm
i tryed this Code:
''bluatigro 14 feb 2015
''mod-test.bas
'include t3d.bas
print "now in mod test bas"
new a as t3d 1 , 2 , 3
print a::toStr$()
Code:
''bluatigro 14 feb 2015
''t3d.bas
new p as t3d 255 , 3 , 6
new p1 as t3d 4 , 4 , 4
print p::toStr$()
print p1::toStr$()
''next line goes also wrong whit "!" in front
''p = p::add( p1 )
print p::toStr$()
discard p
discard p1
end
class t3d
dim a , b , c
sub t3d
a = 0
b = 0
c = 0
end sub
sub t3d x , y , z
a = x
b = y
c = z
end sub
function x
x = a
end function
function y
y = b
end function
function z
z = c
end function
! FUNCTION add( d AS t3d ) AS t3d
new q as t3d a + d::x() , b + d::y() , c + d::z()
add = q
discard q
end function
function toStr$()
''this is now right
toStr$ = "( " + str$( this::x() ) _
+ " , " + str$( this::y() ) _
+ " , " + str$( this::z() ) + " )"
end function
end class
''t3d.bas
error :
- t3d.bas output corect
- mod test.bas only t3d.bas output
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Feb 28th, 2015, 3:29pm
on Feb 28th, 2015, 3:06pm, bluatigro wrote:- t3d.bas output corect - mod test.bas only t3d.bas output |
|
t3d.bas includes an END statement (and other code which must come after the main program) so, of course, anything following the 'include t3d.bas will not be executed:
Code: print "This is executed" ' this is in the included file
end ' this is in the included file
print "This isn't executed" ' this is in the base program
Sometimes I think the 'include directive has been misunderstood. It quite literally 'includes' the specified file at that point in the program; nothing 'clever' or 'magic' happens!
Richard.
Re: Object Oriented Liberty BASIC?
Post by bluatigro on Mar 1st, 2015, 08:47am
i tryed Code:
''bluatigro 14 feb 2015
''mod-test.bas
print "now in mod test"
new a as t3d 1 , 2 , 3
print a::toStr$()
end
'include t3d.bas
Code:
''bluatigro 14 feb 2015
''t3d.bas
class t3d
dim a , b , c
sub t3d
a = 0
b = 0
c = 0
end sub
sub t3d x , y , z
a = x
b = y
c = z
end sub
function x
x = a
end function
function y
y = b
end function
function z
z = c
end function
! FUNCTION add( d AS t3d ) AS t3d
new q as t3d a + d::x() , b + d::y() , c + d::z()
add = q
discard q
end function
function toStr$()
''this is now right
toStr$ = "( " + str$( this::x() ) _
+ " , " + str$( this::y() ) _
+ " , " + str$( this::z() ) + " )"
end function
end class
''t3d.bas
i got a 'mistake' in the include line
Re: Object Oriented Liberty BASIC?
Post by Richard Russell on Mar 1st, 2015, 09:06am
on Mar 1st, 2015, 08:47am, bluatigro wrote:i got a 'mistake' in the include line |
|
Presumably it's this line:
Code:! FUNCTION add( d AS t3d ) AS t3d
That starts with an exclamation mark, so LBB will assume it is BBC BASIC code and bypass the translator, but it's not BBC BASIC code (it's not LBB code either)!
As I've said before do not put code in an included file until it is thoroughly debugged! Because neither the debugger nor the run-time error reporting can tell you in which line an error occurs - they will both simply indicate the 'include line - it makes debugging included code very difficult.
First test it 'inline' as a conventional program, and only when you are very confident the module does what you want and is completely bug-free put it in a separate file. If it does subsequently fail, despite your care, put it back 'inline' to fix the problem.
Richard.