Need help from converting this p5.js/JavaScript program to Processing

I want to do this same exact thing and needed help converting this p5.js program to processing code. I’m not sure how to do that. Any suggestions? Or if anyone knows where I can find a simpler fireworks example that I can using in processing that would help too. (I already tried open processing but a lot of the examples do not have comments so I’m not able to understand what they are coding and why its coded like that)
NOTE: This is just an example that I found.
Here is the code that I like, and I need help converting this so I can use that code in processing and modify the colors to what I prefer. Thanks.

var fireworks = [];
var gravity;

function setup() {
  createCanvas(windowWidth, windowHeight);
  gravity = createVector(0, 0.2);
  stroke(255);
  strokeWeight(4);
	background(0);
}

function draw() {
	colorMode(RGB);
  background(0, 0, 0, 25);
  if (random(1) < 0.03) {
    fireworks.push(new Firework());
  }
  for (var i = fireworks.length -1; i >= 0 ; i--) {
    fireworks[i].show();
    fireworks[i].update();
		if(fireworks[i].done()) {
			fireworks.splice(i, 1);
		}
  }
	console.log(fireworks.length);
}
ArrayList<Firework> fireworks = new ArrayList();
PVector gravity;

void setup() {
  fullScreen();
  gravity = new PVector(0, 0.2);
  stroke(255);
  strokeWeight(4);
  background(0);
}

void draw() {
  colorMode(RGB);
  background(0, 0, 0, 25);
  if (random(1) < 0.03) {
    fireworks.add(new Firework());
  }
  for (int i = fireworks.size()-1; i >= 0 ; i--) {
    fireworks.get(i).show();
    fireworks.get(i).update();
    if(fireworks.get(i).done()) {
      fireworks.remove(i);
    }
  }
}

// This class is just missing...
class Firework{
  Firework(){}
  void show(){}
  void update(){}
  boolean done(){return(false);}
}
// That is the bare minimum code needed to avoid syntax errors...

It’s boring without the Firework class. And you didn’t post that.

1 Like

Thanks a lot! I tried running it however and I’m getting a black screen, is it running on your end? I tried putting your code into just one tab and then I also tried putting the firework code is another still getting a black screen.

Of course I am just getting a black screen. I don’t have a Firework class that draws anything!

Without the Firework class, how do you expect me to get anything other than a black screen, or test it properly?

@charmypatel you probably just took the code from Codingtrain, but if you just looked a little further you would’ve found he actually already made the code in processing as well: https://github.com/CodingTrain/website/tree/master/CodingChallenges/CC_027_FireWorks/Processing

1 Like

yes i did, not taking credit for it thats his code. i’m still new to processing so i was trying to follow along with his code and play around to learn how all the code works. thanks for link i guess i missed that