We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I try to convert this source code from processing to p5.js , any help . Thank you. Best regards.
// example progressbar
// default variables for progressbar
// start the time for progressbar
int startTime;
// counter progressbar
int counter;
// maximum time progressbar
int maxTime;
// boolean for the end progressbar
boolean done;
// settings for this example
function setup() {
// set title of window
frame.setTitle("Example progressbar | free-tutorials.org");
// window size and background color
// p5.js
CreateCanvas(640,130);
//size(640,130);
background(255);
// set variables of progressbar
counter = 0;
startTime= millis();
maxTime=int(random(1000,1976));
done=false;
//end settings
}
// draw all text and progressbar
function draw() {
// set same background color
background(255);
// check end of progressbar fill
if (counter-startTime < maxTime) {
counter=millis();
} else { done=true; }
// create the color for fill progressbar
fill(110,110,255);
// no stroke for draw
noStroke();
// show all text variables and progressbar
text("Progress bar blue - size 620", 230, 20);
rect(10,30,map(counter-startTime,0,maxTime,0,620), 30 );
text("counter- startTime "+int(counter- startTime)+" ",10,80);
text("maxTime "+ int(maxTime) + " ", 10,100);
text("map converted counter-startTime"+ int ( map(counter-startTime,0,maxTime,0,200)), 10,120);
noFill();
}
// reload the draw of progress bar
function mousePressed () { if (done) { counter = 0; startTime= millis();
maxTime=int(random(1000,1976)); done=false; }
}
Answers
Your code isn't properly indented. This site can help ya out w/ that: http://JsBeautifier.org B-)
It's important to also post the original code besides the attempt conversion 1. L-)
BtW, have you read this wiki tutorial? ~O)
https://GitHub.com/processing/p5.js/wiki/Processing-transition
The answer for conversion to P5.js :
change to var all int , float ...
don't use frame.setTitle ...
now is working , thank's