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

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
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

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

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4380
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
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:

Offline nkk_kan

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

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17376
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
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:

Offline mind

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

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
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:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
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:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1289
  • Karma: 466
    • View Profile
    • my stuff
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:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
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:

Offline Optimus

  • DBF Aficionado
  • ******
  • Posts: 2452
  • Karma: 128
    • View Profile
    • Optimouse Demo Site
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:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
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:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4380
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
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:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
That's much more like it :)

Jim
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17376
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Much nicer :)
Shockwave ^ Codigos
Challenge Trophies Won: