Create a draw() function inside other function in Javascript Processing -


ok, have piece of code:

 var = 0;  var left = random(width);  var right = left +50;  var pos = left;  var isleft = true;   var draw= function() {     background(255, 0, 0);     fill(255, 0, 0);     strokeweight(2);     stroke(255, 255, 255);     ellipse(pos,400-a,10,10);      a=a+0.5;     if (isleft === true) {         pos +=0.5;     }     if (pos === right) {         isleft = false;     }     if (isleft === false) {         pos -=0.5;     }     if (pos === left) {         isleft = true;     }  }; 

basically create bubble floats upwards while moving left , right little bit. idea make happens/starts when click mouse. don't seem know how. still learning how code. can me produce desired effect.

thanks , sorry bad english.

if want happen if click anywhere example should work you:

document.body.addeventlistener("click", draw, false); 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -