Recent

Author Topic: Fractal Tree Variation on TBgrabmp Done: Now working on OpenGL Version  (Read 239 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 696
Fractal Tree with Lines Variation on TBgrabmp


Variation in line thickness and colour.
Added randomness
Filter out branch sizes.
Save to opaque or transparent background.

Some nice trees can be made with this one.

Needed to reduce the attached png file sizes by reducing the size of each picture.

Also found an interesting Javascript variation here:
https://www.johnpaulryan.com/blog/2016/09/20/Fun-with-Fractal-Trees
Source:
https://www.johnpaulryan.com/documents/tree.txt
Rename that to index.html and open in a browser.
« Last Edit: October 03, 2024, 11:57:31 am by Boleeman »

Boleeman

  • Hero Member
  • *****
  • Posts: 696
Re: Fractal Tree Variation on TBgrabmp
« Reply #1 on: October 03, 2024, 09:59:18 am »
Actually I would like to see an OpenGL version of this one (like the attached png below), with rounded branches.

This is the Python Script that makes such a tree (fromm https://trinket.io/glowscript/d6813f0f82)

Would be nice to make a Lazarus OpenGL version.

Code: Pascal  [Select][+][-]
  1.  GlowScript 2.9 VPython
  2.  
  3. #this is the tree function
  4. def tree(limblen,r,a):
  5.   #theta is the "bend angle" for each branching
  6.   theta=30*pi/180
  7.   #short is the amount each branch decreases by
  8.   short=15 #this is the amount each branch is decreased by
  9.   fract=.75
  10.   #repeat the branching until the length is shorter than 5
  11.   if limblen>5:
  12.     #each branch is a cylinder
  13.     #a is a vector that points in the direction of the branch
  14.     tcolor=vector(100,42,42).hat
  15.     if limblen<10:
  16.       tcolor=color.green
  17.     cylinder(pos=r,axis=a*limblen, radius=0.15*limblen,
  18.     color=tcolor, texture=textures.rough)
  19.     #r is the position of the next branch
  20.     r=r+a*limblen
  21.     #rotate turns the pointing direction
  22.     a=rotate(a, angle=theta, axis=vector(0,0,1))
  23.     #here is the recursive magic
  24.     tree(limblen*fract,r,a)
  25.     #now you have to go back to where you were
  26.     a=rotate(a,angle=-2*theta,axis=vector(0,0,1))
  27.     #this does the otherside (also recursive)
  28.     tree(limblen*fract,r,a)
  29.     a=rotate(a,angle=theta,axis=vector(0,0,1))
  30.     r=r-limblen*a
  31.    
  32.  
  33. #this starts the tree with the starting branchlength = 75
  34. startingbranch=75
  35.  
  36. #this is the location of the base
  37. startingposition=vector(0,-75,0)
  38.  
  39. #this is the direction of the first branch (up)
  40. startingdirection=vector(0,1,0)
  41. tree(startingbranch,startingposition, startingdirection)
« Last Edit: October 03, 2024, 10:14:18 am by Boleeman »

Boleeman

  • Hero Member
  • *****
  • Posts: 696
Re: Fractal Tree Variation on TBgrabmp
« Reply #2 on: October 03, 2024, 11:40:28 am »
I had a go at converting the Python  version with cylinders for branches to Lazarus OpenGL but I am not seeing the OpenGL fractal Tree. Only scattered colours. What could be the fault ?

Perhaps the fault has to do with the projection I am using. I Don't Know:

glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluPerspective(45.0, OpenGLControl1.Width / OpenGLControl1.Height, 0.1, 500.0);
« Last Edit: October 03, 2024, 11:44:34 am by Boleeman »

 

TinyPortal © 2005-2018