MERRY CHRISTMAS everyone! :)
Just had a funny idea about making a procedural tree for my little painter. I sometimes make little test routines outside to check if an idea works. This time it was too freaking funny and somehow cool to just keep it hidden.
...for a more elaborate version:
HAPPY TREES (happy_trees.zip)
Have fun and happy holidays!
Just had a funny idea about making a procedural tree for my little painter. I sometimes make little test routines outside to check if an idea works. This time it was too freaking funny and somehow cool to just keep it hidden.
...for a more elaborate version:
HAPPY TREES (happy_trees.zip)
SuperStrict '=======================================================' 'magic procedural forest - www.Taron.de (christmas 2008)' '=======================================================' Framework brl.d3d7Max2D Import brl.random SetGraphicsDriver D3D7Max2DDriver() Graphics 800,600,0,60 SeedRnd MilliSecs() Global brush:TPixmap = CreatePixmap(100,100,PF_RGBA8888) For Local y:Float = 0 Until 100 For Local x:Float = 0 Until 100 Local a:Int = 0 Local ix:Float = x-50 Local iy:Float = y-50 Local dot:Float = ix*ix + iy*iy If dot Then dot = Sqr(dot) If dot >50.0 Then dot = 50 dot:*5.1 a = 255-dot ix = x-20 iy = y-40 dot = ix*ix + iy*iy If dot Then dot = Sqr(dot) If dot >100.0 Then dot = 100.0 If dot <0 Then dot = 0.0 Local col:Int = (100-dot)*2 brush.WritePixel(x,y,col|col Shl 8|col Shl 16|a Shl 24) Next Next Type branch Global list:TList = CreateList() Field x:Float Field y:Float Field dx:Float Field dy:Float Field size:Float Field img:TImage = LoadImage(brush) Method grow() SetScale size^2,size^2 DrawImage(img,x,y) x:+dx*size y:+dy*size size:*(0.97+Rnd(0,0.04)) dx:+Rnd(-0.85,0.85) dy:+Rnd(-0.5,0.5) If Rnd(0,10)<-0.1+(1.0-size) And size > 0.3 Then Create(list,x,y,Rnd(-1.0,1.0),dy,size) If size<0.1 Then list.Remove(Self) End Method Function Create:branch(list:TList, x:Int, y:Int, dx:Int, dy:Int, size:Float) Local b:branch = New branch b.x = x b.y = y b.dx = dx b.dy = dy b.size = size b.img = LoadImage(brush) ListAddLast list,b Return b End Function End Type Local c:Int = 0 SetBlend ALPHABLEND SetAlpha 1.0 SetColor 0,0,0 SetScale 1.0,1.0 SetClsColor 30,60,90 Cls Repeat For Local tree:branch = EachIn branch.list; tree.grow();Next If branch.list.Count() = 0 And c < 255 Then branch.Create(branch.list,Rnd(0,800),Rnd(550,650),0,-4,1.0);c:+2;SetColor c,c*Rnd(0.7,0.9),c*Rnd(0.3,0.6) Flip 0 Until KeyHit(KEY_ESCAPE)
Have fun and happy holidays!