vendredi 4 octobre 2019

Using the random() function in p5.js

I am trying to create a code where a smiley face is drawn at random on-screen and in a random colour which should loop but I can't figure out how best to use the random() function to accomplish this. Can anyone give me some pointers! I have tried using variables (var inside the draw function to call function smileyFace but no luck!

CODE:

function setup() {


createCanvas(400, 400);


background(220);


 smileyFace(random(0,400),random(0,400));
}

function draw() {


}

function smileyFace(x,y){


fill(250);
  ellipse(x,y,60,60);
  fill(255);
  ellipse(x-10,y-10,10,10);
  ellipse(x+10,y-10,10,10);
  arc(x,y+5,30,25,0,PI,CHORD);
}



Aucun commentaire:

Enregistrer un commentaire