turtle 2.0

General FreeBASIC programming questions.
bluatigro
Posts: 660
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: turtle 2.0

Post by bluatigro »

update :
les global var's

Code: Select all

''bluatigro 13 may 2017
''3d turtle graphics

#include "_open_gl_dbl.bas"

sub tree( i as integer , prog as string _
  , f as double , x as double , y as double , z as double )
  dim q as integer
  if i > 0 then
    for q = 1 to len( prog )
      select case mid( prog , q , 1 )
        case "f"
          setbox 0 , 1 , 0 , .3,1,.3
          cilinder 6 , .3*f , .3*f , 0 , 0
          gltranslated 0 , 2 , 0
        case "g"
          gltranslated 0 , 2 , 0
        case "["
          glpushmatrix
        case "]"
          glpopmatrix
        case "X"
          glrotated x , 1,0,0
        case "x"
          glrotated -x , 1,0,0 
        case "Y"
          glrotated y , 0,1,0
        case "y"
          glrotated -y , 0,1,0
        case "Z"
          glrotated z , 0,0,1
        case "z"
          glrotated -z , 0,0,1
        case "b"
          glscaled f,f,f
          tree i - 1 , prog , f,x,y,z
        case else
      end select
    next q
  end if
end sub 
dim as double angle
camara.z = 10
camara.y = 3
do
  glclear gl_color_buffer_bit or gl_depth_buffer_bit
  camara.use
  
  glrotated angle , 0,1,0
  tree 7 , "f[xyb]zXyb" , .7,45,80,0
 
  angle += 5
  sleep 40
  flip
loop while inkey = ""
bplus
Posts: 56
Joined: May 01, 2017 15:57

Re: turtle 2.0

Post by bplus »

Feedback, my results with blu's latest posts.
bluatigro wrote:update :
3D opengl trees

Code: Select all

''bluatigro 13 may 2017
''3d turtle graphics

#include "_open_gl_dbl.bas"   '<<<<<<<<<<<<< boing! error file not found, for giggles I tried commenting out, more errors of course!!!

Code: Select all

''bluatigro 11 feb 2017  '<<<<<<<<<<<<< this compiles no errors but on run 2 screens flash up and out and then done
''_open_gl_dbl.bas        '<<<<<<<<<<<<< I tried running this because this was commented out
That 2nd code file was humongous, probably NOT a Sunday afternoon puzzle to fix ;-))

OK where is "_open_gl_dbl.bas" ? The other two posts also use it.

Do I want to mess with it yet? I am graphics fan and trees are a favorite subject but...
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: turtle 2.0

Post by MrSwiss »

@bplus,

_open_gl_dbl.bas -- in bluatigro's first post, with OpenGL - code (go back to first page, in thread).
You'll need to #Include "_open_gl_dbl.bas" for the other code to run (it's calling stuff from it).

Put both .bas files in your "source" <DIR> ... (I hate typing too ... <lol>)
bplus
Posts: 56
Joined: May 01, 2017 15:57

Re: turtle 2.0

Post by bplus »

MrSwiss wrote:@bplus,

_open_gl_dbl.bas -- in bluatigro's first post, with OpenGL - code (go back to first page, in thread).
You'll need to #Include "_open_gl_dbl.bas" for the other code to run (it's calling stuff from it).

Put both .bas files in your "source" <DIR> ... (I hate typing too ... <lol>)
OK, now is _open_gl_dbl.bas also in with download of FB and I think we are treating this one a litle different than last we spoke about.
So this time, I do put a copy of _open_gl_dbl.bas in the same folder as the "source" = blu's code files I copied? (if I understand)

I apologize for all the questions and maybe things are too simple that I should be learning from manual.
It is just quicker to get to the essence of the question and NOT have to wade through (read) a pile of manuals. (I do like reading a little better than typing but not that much better, specially when I want to see blu's trees (I think they are trees)).

But, sometimes you run into a person who doesn't mind these questions and enjoys helping another get started. I hope I have ;-))
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: turtle 2.0

Post by MrSwiss »

bplus wrote:OK, now is _open_gl_dbl.bas also in with download of FB
No, it isn't ...
It's code, made by bluatigro, to "extend" FB's *native* stuff.
(similar to: a external lib, just as *source*, uncompiled)
bplus wrote:So this time, I do put a copy of _open_gl_dbl.bas in the same folder as the "source" = blu's code files I copied? (if I understand)
Last time was: fbgfx.bi -- not ???.bas -- different, isn't it?
bplus
Posts: 56
Joined: May 01, 2017 15:57

Re: turtle 2.0

Post by bplus »

MrSwiss wrote:
bplus wrote:OK, now is _open_gl_dbl.bas also in with download of FB
No, it isn't ...
It's code, made by bluatigro, to "extend" FB's *native* stuff.
(similar to: a external lib, just as *source*, uncompiled)
bplus wrote:So this time, I do put a copy of _open_gl_dbl.bas in the same folder as the "source" = blu's code files I copied? (if I understand)
Last time was: fbgfx.bi -- not ???.bas -- different, isn't it?
OHHHH, yeah, it is a .bas file probably that humongous thing was it! That is why that line, it's name, was commented.
It flashes a couple of screens because it was not intended to be run alone but to be called up like in a multiple file project.

So I should rename that humongous file _open_gl_dbl.bas, and with that change all the others should work (in the same folder).

Many thanks, if that is it.

Wait... that (humongous thing) might be compiled to speed things up?
bplus
Posts: 56
Joined: May 01, 2017 15:57

Re: turtle 2.0

Post by bplus »

That was it. Thanks again MrSwiss

To bluatigro, they get better and better! Dare I hope to see leaves some day?
bluatigro
Posts: 660
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: turtle 2.0

Post by bluatigro »

update :
in color whit leaves

Code: Select all

''bluatigro 13 may 2017
''3d turtle graphics

#include "_open_gl_dbl.bas"

sub tree( i as integer , prog as string _
  , f as double , x as double , y as double , z as double )
  dim q as integer
  if i > 0 then
    for q = 1 to len( prog )
      select case mid( prog , q , 1 )
        case "f"  ''draw trunk or twig and move pen
          material.diffuse = orange
          setmaterial gl_front , material
          setbox 0 , 1 , 0 , .3,1,.3
          cilinder 6 , .3*f , .3*f , 0 , 0
          gltranslated 0 , 2 , 0
        case "l"  ''draw leaf
          material.diffuse = green
          setmaterial gl_front , material
          glpushmatrix
            glscaled .5,.5,.5
            setpoint 0 , 0 , 0 , 0
            setpoint 1 , 1 , 0 , 1
            setpoint 2 , 3 , 0 , 0
            setpoint 3 , 1 , 0 , -1
            quad 0 , 1 , 2 , 3
          glpopmatrix
        case "g"  ''move pen
          gltranslated 0 , 2 , 0
        case "["  ''store x,y,z
          glpushmatrix
        case "]"  ''read x,y,z
          glpopmatrix
        case "X"
          glrotated x , 1,0,0
        case "x"
          glrotated -x , 1,0,0 
        case "Y"
          glrotated y , 0,1,0
        case "y"
          glrotated -y , 0,1,0
        case "Z"
          glrotated z , 0,0,1
        case "z"
          glrotated -z , 0,0,1
        case "b"  ''draw hole tree smaler
          glscaled f,f,f
          tree i - 1 , prog , f,x,y,z
        case else
      end select
    next q
  end if
end sub 
dim as double angle
camara.z = 10
camara.y = 3
do
  glclear gl_color_buffer_bit or gl_depth_buffer_bit
  camara.use
  
  glrotated angle , 0,1,0
  tree 7 , "f[xyblylylyl]zXyblylylyl" , .7,45,80,0
 
  angle += 5
  sleep 40
  flip
loop while inkey = ""
bluatigro
Posts: 660
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: turtle 2.0

Post by bluatigro »

update :
i think you wil like this : flowers

Code: Select all

''bluatigro 13 may 2017
''3d turtle graphics

#include "_open_gl_dbl.bas"

sub tree( i as integer , prog as string _
  , f as double , x as double , y as double , z as double )
  dim as integer q , t
  if i > 0 then
    for q = 1 to len( prog )
      select case mid( prog , q , 1 )
        case "f"  ''draw trunk or twig and move pen
          material.diffuse = orange
          setmaterial gl_front , material
          setbox 0 , 1 , 0 , .3,1,.3
          cilinder 6 , .3*f , .3*f , 0 , 0
          gltranslated 0 , 2 , 0
        case "l"  ''draw leaf
          material.diffuse = green
          setmaterial gl_front_and_back , material
          glpushmatrix
            glscaled .5,.5,.5
            setpoint 0 , 0 , 0 , 0
            setpoint 1 , 1 , 0 , 1
            setpoint 2 , 3 , 0 , 0
            setpoint 3 , 1 , 0 , -1
            quad 0 , 1 , 2 , 3
          glpopmatrix
        case "h"  ''draw a flower
          material.diffuse = white
          setmaterial gl_front_and_back , material
          for t = 0 to 4
          glpushmatrix
            glscaled .5,.5,.5
            glrotated 72 * t , 0 , 1 , 0
            setpoint 0 , 0 , 0 , 0
            setpoint 1 , 1 , 1 , 1
            setpoint 2 , 3 , 3 , 0
            setpoint 3 , 1 , 1 , -1
            quad 0 , 1 , 2 , 3
          glpopmatrix
          next t
        case "g"  ''move pen
          gltranslated 0 , 2 , 0
        case "["  ''store x,y,z
          glpushmatrix
        case "]"  ''read x,y,z
          glpopmatrix
        case "X"
          glrotated x , 1,0,0
        case "x"
          glrotated -x , 1,0,0 
        case "Y"
          glrotated y , 0,1,0
        case "y"
          glrotated -y , 0,1,0
        case "Z"
          glrotated z , 0,0,1
        case "z"
          glrotated -z , 0,0,1
        case "b"  ''draw hole tree smaler
          glscaled f,f,f
          tree i - 1 , prog , f,x,y,z
        case else
      end select
    next q
  end if
end sub 
dim as double angle
camara.z = 10
camara.y = 3
do
  glclear gl_color_buffer_bit or gl_depth_buffer_bit
  camara.use
  
  glrotated angle , 0,1,0
  tree 5 , "f[[xyblylylylh]Xyblylylylh]yblylylylh" , .7,60,80,30
 
  angle += 5
  sleep 40
  flip
loop while inkey = ""
bplus
Posts: 56
Joined: May 01, 2017 15:57

Re: turtle 2.0

Post by bplus »

Hi Bluatigro,

Yes, very nice!

Beeware, flowers attract B's ;-))
bluatigro
Posts: 660
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: turtle 2.0

Post by bluatigro »

licence :
you may use this code in your projects
you wil add my name to the credits
you shal NOT clame this as your own work


instructions :
by sub tree i , prog , f , x , y , z
keep i low [ 1 ... 7 ]
keep f between 0 and 1
if you write your own prog take care of matching [ and ]

please report nice tree's in this tread
bluatigro
Posts: 660
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: turtle 2.0

Post by bluatigro »

update :
L operator added [ draw set of leaves ]

more example tree's

i have no idea how many diferend tree's you can make whit this

Code: Select all

''bluatigro 13 may 2017
''3d turtle graphics

#include "_open_gl_dbl.bas"

sub tree( i as integer , prog as string _
  , f as double , x as double , y as double , z as double )
  dim as integer q , t
  if i > 0 then
    for q = 1 to len( prog )
      select case mid( prog , q , 1 )
        case "f"  ''draw trunk or twig and move pen
          material.diffuse = orange
          setmaterial gl_front , material
          setbox 0 , 1 , 0 , .3,1,.3
          cilinder 6 , .3*f , .3*f , 0 , 0
          gltranslated 0 , 2 , 0
        case "l"  ''draw leaf
          material.diffuse = green
          setmaterial gl_front_and_back , material
          glpushmatrix
            glscaled .5,.5,.5
            setpoint 0 , 0 , 0 , 0
            setpoint 1 , 1 , 0 , 1
            setpoint 2 , 3 , 0 , 0
            setpoint 3 , 1 , 0 , -1
            quad 0 , 1 , 2 , 3
          glpopmatrix
        case "L"  ''draw set of leaves
          material.diffuse = green
          setmaterial gl_front_and_back , material
          for t = 0 to 5
            glpushmatrix
              glrotated 72 * t , 0,1,0
              glscaled .5,.5,.5
              setpoint 0 , 0 , 0 , 0
              setpoint 1 , 1 , 0 , 1
              setpoint 2 , 3 , 0 , 0
              setpoint 3 , 1 , 0 , -1
              quad 0 , 1 , 2 , 3
            glpopmatrix
          next t
        case "h"  ''draw a flower
          material.diffuse = white
          setmaterial gl_front_and_back , material
          for t = 0 to 4
          glpushmatrix
            glscaled .5,.5,.5
            glrotated 72 * t , 0 , 1 , 0
            setpoint 0 , 0 , 0 , 0
            setpoint 1 , 1 , 1 , 1
            setpoint 2 , 3 , 3 , 0
            setpoint 3 , 1 , 1 , -1
            quad 0 , 1 , 2 , 3
          glpopmatrix
          next t
        case "g"  ''move pen
          gltranslated 0 , 2 , 0
        case "["  ''store x,y,z
          glpushmatrix
        case "]"  ''read x,y,z
          glpopmatrix
        case "X"
          glrotated x , 1,0,0
        case "x"
          glrotated -x , 1,0,0 
        case "Y"
          glrotated y , 0,1,0
        case "y"
          glrotated -y , 0,1,0
        case "Z"
          glrotated z , 0,0,1
        case "z"
          glrotated -z , 0,0,1
        case "b"  ''draw hole tree smaler
          glscaled f,f,f
          tree i - 1 , prog , f,x,y,z
        case else
      end select
    next q
  end if
end sub 
dim as double angle
dim as integer state
camara.z = 10
camara.y = 3
do
  glclear gl_color_buffer_bit or gl_depth_buffer_bit
  camara.use
  
  glrotated angle , 0,1,0
  if state = 0 then
    tree 5 , "f[xybLh]XybLh" , .7,45,90,30
  end if
  if state = 1 then
    tree 5 , "f[[xzybh]Xzybh]zybh" , 0.7,60,90,10
  end if
  if state = 2 then
    tree 4 , "f[[[[xb]Xb]zb]Zb]yb" , 0.7,70,45,70
  end if
  
  angle = ( angle + 5 ) mod 360
  if angle = 0 then 
    state = ( state + 1 ) mod 3 
  end if
  sleep 40
  flip
loop while inkey = ""
bluatigro
Posts: 660
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: turtle 2.0

Post by bluatigro »

update :
just for fun color for flowers is free

Code: Select all

''bluatigro 13 may 2017
''3d turtle graphics

#include "_open_gl_dbl.bas"

sub tree( i as integer , prog as string _
  , f as double , x as double , y as double _
  , z as double , kl as sng4d )
  dim as integer q , t
  if i > 0 then
    for q = 1 to len( prog )
      select case mid( prog , q , 1 )
        case "f"  ''draw trunk or twig and move pen
          material.diffuse = orange
          setmaterial gl_front , material
          setbox 0 , 1 , 0 , .3,1,.3
          cilinder 6 , .3 * f , .3 * f , 0 , 0
          gltranslated 0 , 2 , 0
        case "l"  ''draw leaf
          material.diffuse = green
          setmaterial gl_front_and_back , material
          glpushmatrix
            glscaled .5,.5,.5
            setpoint 0 , 0 , 0 , 0
            setpoint 1 , 1 , 0 , 1
            setpoint 2 , 3 , 0 , 0
            setpoint 3 , 1 , 0 , -1
            quad 0 , 1 , 2 , 3
          glpopmatrix
        case "L"  ''draw set of leaves
          material.diffuse = green
          setmaterial gl_front_and_back , material
          for t = 0 to 5
            glpushmatrix
              glrotated 72 * t , 0,1,0
              glscaled .5,.5,.5
              setpoint 0 , 0 , 0 , 0
              setpoint 1 , 1 , 0 , 1
              setpoint 2 , 3 , 0 , 0
              setpoint 3 , 1 , 0 , -1
              quad 0 , 1 , 2 , 3
            glpopmatrix
          next t
        case "h"  ''draw a flower
          material.diffuse = kl
          setmaterial gl_front_and_back , material
          for t = 0 to 4
          glpushmatrix
            glscaled .5,.5,.5
            glrotated 72 * t , 0 , 1 , 0
            setpoint 0 , 0 , 0 , 0
            setpoint 1 , 1 , 1 , 1
            setpoint 2 , 3 , 3 , 0
            setpoint 3 , 1 , 1 , -1
            quad 0 , 1 , 2 , 3
          glpopmatrix
          next t
        case "g"  ''move pen
          gltranslated 0 , 2 , 0
        case "["  ''store x,y,z
          glpushmatrix
        case "]"  ''read x,y,z
          glpopmatrix
        case "X"
          glrotated x , 1,0,0
        case "x"
          glrotated -x , 1,0,0 
        case "Y"
          glrotated y , 0,1,0
        case "y"
          glrotated -y , 0,1,0
        case "Z"
          glrotated z , 0,0,1
        case "z"
          glrotated -z , 0,0,1
        case "b"  ''draw hole tree smaler
          glscaled f,f,f
          tree i - 1 , prog , f,x,y,z,kl
        case else
      end select
    next q
  end if
end sub 
dim as double angle
dim as integer state
camara.z = 10
camara.y = 3
do
  glclear gl_color_buffer_bit or gl_depth_buffer_bit
  camara.use
  
  glrotated angle , 0,1,0
  if state = 0 then
    tree 5 , "f[xybLh]XybLh" _
    , .7,45,90,30,rainbow(angle)
  end if
  if state = 1 then
    tree 5 , "f[[xzybh]Xzybh]zybh" _
    , 0.7,60,90,10,rainbow(angle)
  end if
  if state = 2 then
    tree 3 , "f[[[[xbLh]XbLh]zbLh]ZbLh]ybLh" _
    , 0.7,70,45,70,rainbow(angle)
  end if
  
  angle = ( angle + 3 ) mod 360
  if angle = 0 then 
    state = ( state + 1 ) mod 3 
  end if
  sleep 40
  flip
loop while inkey = ""
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: turtle 2.0

Post by thesanman112 »

I played with the code by adding tree value higher, it seems to really kill the speed, i would think you should be able to render a tree with a lot more branches faster, it could be my laptop, but maybe there is something in your code that is slowing it down??
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: turtle 2.0

Post by thesanman112 »

there use to be someone in this forum that was an open-gl guru, they would likely know exactly whats making it run so slow, it could be something really simple like an array being used for a GL call.
Post Reply