Hi, I’m trying to convert a processing 3 sketch that works to a p5.js and I can’t wrap my head around what the changes are or where to find a translation guide. I think if I can crack this conversion I’ll be able to do most of my coding in p5.js. The lump of code is the processing sketch I’m trying to convert. It makes a circle grow and shrink.
Ball myBall;
boolean grow =true;
boolean button =false;
void setup(){
size(400,400);
myBall = new Ball(color(255, 0,0));
}
void draw(){
background(255);
myBall.GrowBall();
myBall.dispBall();
myBall.shrink();
}
//----class----
class Ball{
float pX;
float pY;
float bSize;
color c;
float addSize=1;
float ballMax= 100;
float ballMin =10;
Ball( color tempC){
bSize=10;
c = tempC;
}
void dispBall(){
pX = 200;
pY = 200;
noStroke();
fill(c);
circle(pX, pY, bSize);
bSize= +addSize;
}
void GrowBall(){
//grow shrink boolean switch
if (grow==true){
addSize= addSize+0.5;
}else {
addSize = addSize-0.5;
}
//-----condionals
bSize = constrain(bSize, 10, 100);
// addSize = constrain(addSize, 10, 100);
}//grow
void shrink(){
if(bSize==100){ // when size is 100 switch the boolean value to it's opposite
grow=!grow;
}
if(bSize==10){
grow=true; //when 10 grow the circle
}
}
}
Thanks. I think this will help with my issues. I really need a step by step conversion process. I will be able to work it out from this though. And I can write my own conversion tutorial for bits that I found difficult to follow or understand. Cheers!!
Hi cheers for the constant help. I’ve decided to leave p5.js alone for now, as there is so much stuff I don’t yet know how to do in vanillia processing and I’m working from a book using it. I’ll come back to p5.js eventually. When I have a better grasp of the concepts in processing in general.
The link and coding train stuff you provided will help a lot with that!
Thanks!