### Author Topic: [PROCEDURAL] FINAL RELEASE Lindenmayer Nocturne  (Read 5698 times)

0 Members and 1 Guest are viewing this topic.

#### Pixel_Outlaw

• Pentium
• Posts: 1382
• Karma: 83
##### [PROCEDURAL] FINAL RELEASE Lindenmayer Nocturne
« on: May 12, 2008 »
I don't have much time on the forum lately but I did this tonight. It makes random trees and stars. Hope you like it.
I will work more if time permits. Good luck to everyone.

EDIT

Code if you dare read my unoptimized and heavily rushed handy work.

Code: [Select]
' Lindenmayer system explorer
' Ryan Burnside (Pixel_Outlaw) 2008
' sloppy and unoptimiezed Huzzah?

Strict

Framework BRL.GLMax2D
Import BRL.Random
Import BRL.Math

SeedRnd(MilliSecs())
' first we set aside an old list used just for drawing
Global old_list:TList = New TList
' now we set aside a new list which will be used to make new branches
Global new_list:TList = New TList
' set how many branches each branch generates
Global splits:Float = 3
' reduction of each generation
Global reduction:Float =.70

Global sub_angle:Float = spread / (splits - 1)

Function create_branch:branch(x:Float, y:Float, angle:Float, length:Float)
Local b:branch = New branch
b.x = x
b.y = y
b.length = length
b.angle = angle
b.x2 = b.x + Cos(b.angle) * b.length
b.y2 = b.y + Sin(b.angle) * b.length
Return b
End Function

Function spawn_new_generation()
Local temp_list:TList = New TList
' first branch each branch in the new list
For Local b:branch = EachIn(new_list)
' remove from new list and add to old list
ListRemove(new_list, b)

' create new branches from the length and angle of old

Local e:Int = Rand(0, 2)
Local sub_angle_a = spread / (splits - e)
Local start_angle:Float = b.angle - (spread / 2.0)
For Local i = 0 To splits - e
If Rand(0, 9)
Local g:branch = create_branch(b.x2, b.y2, start_angle + (i * sub_angle_a) + Rand(- 10, 10), b.length * reduction * Rand(70, 100) / 100)
EndIf
Next
Next
new_list = temp_list
End Function

Function draw_lists()
For Local a:branch = EachIn(old_list)
DrawLine(a.x, a.y, a.x2, a.y2)
Next
For Local b:branch = EachIn(new_list)
DrawLine(b.x, b.y, b.x2, b.y2)
Next

End Function

Function find_angle:Float(x:Float, y:Float, x2:Float, y2:Float)

Local direction:Float = ATan2(y - y2, x - x2) + 180

Return direction
End Function

Function find_distance:Float(x:Float, y:Float, x2:Float, y2:Float)
' returns distance between two points
' using c= sqr(a^2 + b^2)
Local x_dist = x - x2
Local y_dist = y - y2
Return Sqr((x_dist * x_dist) + (y_dist * y_dist))
EndFunction

' make a branch type
Type branch
Field x:Float, y:Float, x2:Float, y2:Float, angle:Float, length:Float
End Type

AppTitle="Lindenmayer Nocturne"
Graphics 640, 480
SetBlend(LIGHTBLEND)
SetAlpha(1)

Global timer:Int = 0

While 1

If Not timer
Cls
' goodnight moon
SetColor(255, 255, 255)
DrawOval(Rand(640), Rand(64, 128), 32, 32)
' draw ground
'draw ground
For Local i = 0 To 7
DrawLine(0, 240 + i * i, 640, 240 + i * i)
Next
'draw stars
For Local i = 0 To 16
Plot(Rand(0, 640), Rand(0, 240))
Next

' draw 10 trees of varying size
SetColor(100, 255, 200)
SetAlpha(.5)

For Local c:Int = 0 To 35
Local z:Float = Rand(0, 30)
ListAddLast(new_list, create_branch(Rand(640), 240 + (240 / z), 270, 212 / z))
For Local i = 0 To 6
spawn_new_generation
Next
draw_lists
ClearList(old_list)
ClearList(new_list)
Next

Flip
timer = 1000
If KeyHit(KEY_ESCAPE)
End
End If
Else
timer:-1
End If
Wend

« Last Edit: May 14, 2008 by Pixel_Outlaw »
Challenge Trophies Won:

#### benny!

• Senior Member
• Posts: 4380
• Karma: 228
• in this place forever!
##### Re: [PROCEDURAL] Lindenmayer Nocturne
« Reply #1 on: May 12, 2008 »
@PO:

Cool entry. Looks cyber romantic somehow. Like it!!!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

#### nkk_kan

• C= 64
• Posts: 32
• Karma: 4
• poisoning the world with goodness
##### Re: [PROCEDURAL] Lindenmayer Nocturne
« Reply #2 on: May 12, 2008 »
Looking cool!
some colours and alpha would make it rock

#### Shockwave

• good/evil
• Founder Member
• Posts: 17376
• Karma: 497
• evil/good
##### Re: [PROCEDURAL] Lindenmayer Nocturne
« Reply #3 on: May 12, 2008 »
I'd love to see these trees waving around in the breeze so much

What you've made there looks nice in a vib-ribbon style! Thanks for supporting the comp, I know you don't have a lot of time.
Shockwave ^ Codigos
Challenge Trophies Won:

#### mind

• Texture-San
• Posts: 2324
• Karma: 85
##### Re: [PROCEDURAL] Lindenmayer Nocturne
« Reply #4 on: May 12, 2008 »
as "simple" as it is, its pretty friggin awesome good work..
Challenge Trophies Won:

#### rain_storm

• Here comes the Rain
• Posts: 3088
• Karma: 182
• Rain never hurt nobody
##### Re: [PROCEDURAL] Lindenmayer Nocturne
« Reply #5 on: May 12, 2008 »
Excellent looking tree its great that youve got in an entry given that your time is spread thin

Challenge Trophies Won:

#### Clyde

• A Little Fuzzy Wuzzy
• Posts: 7271
• Karma: 71
##### Re: [PROCEDURAL] Lindenmayer Nocturne
« Reply #6 on: May 12, 2008 »
Welldone Pixel Outlaw
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

#### hellfire

• Pentium
• Posts: 1289
• Karma: 466
##### Re: [PROCEDURAL] Lindenmayer Nocturne
« Reply #7 on: May 13, 2008 »
simplistic but stylish!
I really like that it gives a different tree on each run.
As I mysteriously got anti-aliasing, I guess this is OpenGL?
A bit of animation would be just wonderful.
Challenge Trophies Won:

#### Jim

• Founder Member
• Posts: 5301
• Karma: 402
##### Re: [PROCEDURAL] Lindenmayer Nocturne
« Reply #8 on: May 13, 2008 »
There're so many places to go with this algorithm - colours, randomisation of the angles, twig lengths, number of branches, etc. etc.  Good demo, with loads of potential.

Jim
Challenge Trophies Won:

#### Optimus

• Posts: 2452
• Karma: 128
##### Re: [PROCEDURAL] Lindenmayer Nocturne
« Reply #9 on: May 14, 2008 »
I like it. Maybe too simple and not animated but it's a minimalistic b&w screen that reminds me of a feeling retro.
Challenge Trophies Won:

#### Pixel_Outlaw

• Pentium
• Posts: 1382
• Karma: 83
##### Re: [PROCEDURAL] FINAL RELEASE Lindenmayer Nocturne
« Reply #10 on: May 14, 2008 »
Just made a final release with some free time I had today. Please replace the old version with this. It makes more natural trees and a whole forest of em.
Challenge Trophies Won:

#### benny!

• Senior Member
• Posts: 4380
• Karma: 228
• in this place forever!
##### Re: [PROCEDURAL] FINAL RELEASE Lindenmayer Nocturne
« Reply #11 on: May 15, 2008 »
Looks damn beautiful - love it. Welcome to Cyberland!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

#### Jim

• Founder Member
• Posts: 5301
• Karma: 402
##### Re: [PROCEDURAL] FINAL RELEASE Lindenmayer Nocturne
« Reply #12 on: May 15, 2008 »
That's much more like it

Jim
Challenge Trophies Won:

#### Shockwave

• good/evil
• Founder Member