I have been working on a tree system for my procedural world builder and it is going good. The way that It works is that there is one tree to start and over time the tree checks for positions that are suitable for a seed, aka somewhere where there isn't another tree. overall it isn't really that complex but I plan to make each tree release a set number of seeds in addition to a wind system for better looking forests.
The code for it so far is:
define (Draw trees)
delete all of (Tree x)
delete all of (Tree y)
* Repeat until (length of (Tree x) = 0)
I = rnd(0 - (length of Tree x))
Check
End
Mostly Just simple list stuff for the part that runs the loop also the place that there is the * You can replace that with a finite number. Anyway the code that I use for the placement of the tree is:
define (Check)
go to x (item (I) of (Tree x)) y (item (I) if (Tree y))
Point in direction (90)
repeat 4
move dist = rnd(1 - 4)
move (move dist)
if: not(touching color(tree color)) + touching color(land color)
add (x) to (Tree x)
add (y) to (Tree y)
stamp
end
turn right (90)
end
Then you have a very simple way to make a procedural forest in scratch though I would recommend to use turbowarp. BTW you should always put an erase all block at the start to make it so that the full screen is reset. also for finding the position you can just use the code:
go to (rnd position
repeat until not(touching color(tree color)) + touching color(land color)
go to (rnd position)
end
Now for what I think that would make the system even better.
For the first thing I think that the seeds placement should be determined by the wind by making the checking position slightly shifted in the direction of the wind. Next For something that Is possibly for other things as it is hard to control Is that the trees would be clones and would have a seed# variable. Once they have released all of their seeds then they would stamp themselves. But anyway, Thanks for reading this little thing, have a great rest of your day :)
Top comments (1)
4 days in a row that I've done this posting stuff, its nice. this is definitely a project I would like to make better than it is right now.