Error (: line 0)

Good day,

I am new to this forum and would like to have your advice concerning an error which I am not able to solve. When I run the code below (tree simulation) in p5js,
it gives me this error : Script error. (: line 0).

I would like tho know if you have any idea how to solve this.

Best wishes.

Iris

<
var dotSize = 9;
var angleOffsetA;
var angleOffsetB;

function setup() {
createCanvas(windowWidth, windowHeight);
noStroke();
fill(0);
frameRate(1); // Redraw the tree once second

angleOffsetA = radians(1.5);//Convert 1.5 degrees to radians
angleOffsetB = radians(50); //Convert 50 degrees to radians
}

function draw() {
background(255);
seed1(dotSize, radians(270), width/2, height); //Start the tree
}

function seed1(dotSize, angle, x, y) {

if (dotSize > 1.0){

//Create a random numbers between 0 and 1
var r = random(0, 1.0);

//98% chance this will happen
if (r > 0.02) {
ellipse(x, y dotSize, dotSize);
var newx = x + cos(angle) * dotSize;
var newy = y + sin(angle) * dotSize;
seed1(dotSize * 0.99,angle - angleOffsetA, newx, newy);
}
//02% chance this will happen
else{
var newx = x + cos(angle);
var newy = y + sin(angle);
seed2(dotSize * 0.99,angle + angleOffsetA, newx, newy);
seed1(dotSize * 0.60,angle + angleOffsetB, newx, newy);
seed2(dotSize * 0.50,angle - angleOffsetB, newx, newy);

}
}
}

function seed2(dotSize, angle, x, y) {

if (dotSize > 1.0) {

//Create a random numbers between 0 and 1
var r = random(0, 1.0);

//95% chance this will happen
if (r > 0.05) {
ellipse(x, y, dotSize, dotSize);
var newx = x + cos(angle) * dotSize;
var newy = y + sin(angle) * dotSize;
seed2(dotSize * 0.99,angle - angleOffsetA, newx, newy);
}

//05% chance this will happen
else {
ellipse(x, y, dotSize, dotSize);
var newx = x + cos(angle);
var newy = y + sin(angle);
seed2(dotSize * 0.99,angle + angleOffsetA, newx, newy);
seed1(dotSize * 0.60,angle + angleOffsetB, newx, newy);
seed2(dotSize * 0.50,angle - angleOffsetB, newx, newy);
}
}
}
function mousePressed (){
background(255,45);
seed1(dotSize, radians(270, mouseX, height);
}
/>
Homework policy: https://discourse.processing.org/t/faq-guidelines/5#homework
Asking Questions: Guidelines—Asking Questions
–>

I found some issues. It is mostly misplaced “}” and a forgotten “)”.

here is the fixed code:

var dotSize = 9;
var angleOffsetA;
var angleOffsetB;

function setup() {
  createCanvas(windowWidth, windowHeight);
  noStroke();
  fill(0);
  frameRate(1); // Redraw the tree once second

  angleOffsetA = radians(1.5); //Convert 1.5 degrees to radians
  angleOffsetB = radians(50); //Convert 50 degrees to radians
}

function draw() {
  background(255);
  seed1(dotSize, radians(270), width / 2, height); //Start the tree
}

function seed1(dotSize, angle, x, y) {

  if (dotSize > 1.0) {

    //Create a random numbers between 0 and 1
    var r = random(0, 1.0);

    //98% chance this will happen
    if (r > 0.02) {
      circle(x, y, dotSize);
      var newx = x + cos(angle) * dotSize;
      var newy = y + sin(angle) * dotSize;
      seed1(dotSize * 0.99, angle - angleOffsetA, newx, newy);
    }
  }
  //02% chance this will happen
  else {
    var newx = x + cos(angle);
    var newy = y + sin(angle);
    seed2(dotSize * 0.99, angle + angleOffsetA, newx, newy);
    seed1(dotSize * 0.60, angle + angleOffsetB, newx, newy);
    seed2(dotSize * 0.50, angle - angleOffsetB, newx, newy);

  }
}

function seed2(dotSize, angle, x, y) {

  if (dotSize > 1.0) {

    //Create a random numbers between 0 and 1
    var r = random(0, 1.0);

    //95% chance this will happen
    if (r > 0.05) {
      ellipse(x, y, dotSize, dotSize);
      var newx = x + cos(angle) * dotSize;
      var newy = y + sin(angle) * dotSize;
      seed2(dotSize * 0.99, angle - angleOffsetA, newx, newy);
    }

    //05% chance this will happen
    else {
      ellipse(x, y, dotSize, dotSize);
      var newx = x + cos(angle);
      var newy = y + sin(angle);
      seed2(dotSize * 0.99, angle + angleOffsetA, newx, newy);
      seed1(dotSize * 0.60, angle + angleOffsetB, newx, newy);
      seed2(dotSize * 0.50, angle - angleOffsetB, newx, newy);
    }
  }
}

function mousePressed() {
  background(255, 45);
  seed1(dotSize, radians(270, mouseX, height));
}

Thank you so much codeMasterX!

I should be more careful with these “{“ and these “)”, it solves a part of the problem. However, I still have the error message followed by this message:

Script error. (: line 0)

If not intentional, this is often a problem with scope: [https://p5js.org/examples/data-variable-scope.html]. (http://p5js.org/reference/#/p5/circle)

I will try to get more insight from the link they provided.

Thanks again for your help!

Iris

I don’t really understand what this program is supposed to do : P so I can’t fix it. I am not too good at reading code and determining what is supposed to happen.

The code is supposed to draw a different tree shape every time we press the mouse. :slight_smile: