Discuss Scratch

eleventyOne
Scratcher
82 posts

recursion function not allowing other function to run

“you might need a different way of creating the tree to be able to do more types of animation like things with it, and the way of doing that is to, rather than draw the tree all at once in a recursive function, build the tree out of objects” - Daniel Shiffman
eleventyOne
Scratcher
82 posts

recursion function not allowing other function to run

eleventyOne wrote:

Is this what you're trying to say? or something similar to it?
var angle = 0;
var slider;
function setup() {
  createCanvas(400, 400);
  slider = createSlider(0, TWO_PI, PI / 4, 0.01);
}
function draw() {
  background(51);
  angle = slider.value();
  stroke(255);
  translate(200, height);
  branch(100);
}
function branch(len) {
  line(0, 0, 0, -len);
  translate(0, -len);
  if (len > 4) {
    push();
    rotate(angle);
    branch(len * 0.67);
    pop();
    push();
    rotate(-angle);
    branch(len * 0.67);
    pop();
  }

This is exactly what im not trying to achieve. The remix that you made looks like this, but correct me if im wrong.
eleventyOne
Scratcher
82 posts

recursion function not allowing other function to run

Help guys
deck26
Scratcher
1000+ posts

recursion function not allowing other function to run

So in what way is that not what you're trying to achieve? It's hard to help when you don't give any useful details, just reject the help.
eleventyOne
Scratcher
82 posts

recursion function not allowing other function to run

sorry! I just want it to be vector based, object oriented. not draw-all-at-once this is just a simple recursion draw function, nothing object oriented about it. Man there are other projects in scratch out there with simple recursion like u showed. i wouldnt have asked here if that was my goal.
deck26
Scratcher
1000+ posts

recursion function not allowing other function to run

So do something with clones.. Each branch, if it is long enough creates two clones at the angles. Each clone draws a line and continues the process. That's probalby the nearest you'll get in Scratch to handling this as object-oriented.

Powered by DjangoBB