Dark Bit Factory & Gravity

GENERAL => Challenges & Competitions => Topic started by: Pixel_Outlaw on May 12, 2008

Title: [PROCEDURAL] FINAL RELEASE Lindenmayer Nocturne
Post by: Pixel_Outlaw 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

This newest version is the final version, please try this one.

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
Import BRL.LinkedList

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
' the angle of spread
Global spread:Float = 45
' 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)
ListAddLast(old_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)
ListAddLast(temp_list, g)
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
' the angle of spread
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

Title: Re: [PROCEDURAL] Lindenmayer Nocturne
Post by: benny! on May 12, 2008
@PO:

Cool entry. Looks cyber romantic somehow. Like it!!!
Title: Re: [PROCEDURAL] Lindenmayer Nocturne
Post by: nkk_kan on May 12, 2008
Looking cool!
some colours and alpha would make it rock :P
Title: Re: [PROCEDURAL] Lindenmayer Nocturne
Post by: Shockwave 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.
Title: Re: [PROCEDURAL] Lindenmayer Nocturne
Post by: mind on May 12, 2008
as "simple" as it is, its pretty friggin awesome :) good work..
Title: Re: [PROCEDURAL] Lindenmayer Nocturne
Post by: rain_storm on May 12, 2008
Excellent looking tree its great that youve got in an entry given that your time is spread thin
Title: Re: [PROCEDURAL] Lindenmayer Nocturne
Post by: Clyde on May 12, 2008
Welldone Pixel Outlaw :)
Title: Re: [PROCEDURAL] Lindenmayer Nocturne
Post by: hellfire 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.
Title: Re: [PROCEDURAL] Lindenmayer Nocturne
Post by: Jim 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
Title: Re: [PROCEDURAL] Lindenmayer Nocturne
Post by: Optimus 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.
Title: Re: [PROCEDURAL] FINAL RELEASE Lindenmayer Nocturne
Post by: Pixel_Outlaw 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.
Title: Re: [PROCEDURAL] FINAL RELEASE Lindenmayer Nocturne
Post by: benny! on May 15, 2008
Looks damn beautiful - love it. Welcome to Cyberland!
Title: Re: [PROCEDURAL] FINAL RELEASE Lindenmayer Nocturne
Post by: Jim on May 15, 2008
That's much more like it :)

Jim
Title: Re: [PROCEDURAL] FINAL RELEASE Lindenmayer Nocturne
Post by: Shockwave on May 15, 2008
Much nicer :)