Processing.js – Hello World 3

Processing.js is a port of the visualization language, Processing. As its front-end, it allows you to write in the Processing language (while JavaScript “bindings” are doable, that’s not necessarily the intent). As for the back-end, Processing.js utilizes the Canvas HTML element as its rendering target.

The Processing language is a very simplified version of Java. It handles and feels very much the same way, except a good bit less verbose. Additionally, the platform introduces input awareness at a global level which allows for the rapid development you see in the screencast.

In this screencast, I explore building a trivial particle system. It is important to note particle systems can become incredibly complex beasts and I do not mean to marginalize the effort required to build them. The effect we achieve here is directly proportional to the time invested, and I plan to expand on this subject in the future.

In our particle class, seen here:

class Particle {
	float x, y;
	float xV, yV;
	float gravity, life;
	
	Particle(float initX, float initY) {
		x = initX;
		y = initY;
		life = 20;
		gravity = 1;
		
		xV = random(-5, 5);
		yV = random(-15, -20);
	}
	
	void update() {
		yV += gravity;
		
		x += xV;
		y += yV;
		
		if(life > 0) {
			life--;
		}
	}
	
	void draw() {
		ellipse(x, y, 10, 10);
	}
}

I make heavy use of the float data type. In execution, our example likely could have used integer values instead. However, if we had added any sort of rotation or adjusted gravity to a fractional value, it would have been necessary to use floats.

In conclusion, the Processing.js library is fascinating in its simplicity and shallow learning curve. I plan to continue exploring the platform in future screencasts.

Thanks again for watching.

Download an example file.

Links:
http://processingjs.org
http://processingjs.org/reference
http://processing.org

Kinsta

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Time limit exceeded. Please complete the captcha once again.

More News & Articles

How CX (Customer Experience) Can Combat Customer Churn

How CX (Customer Experience) Can Combat Customer Churn

A seamless customer experience (CX) can reduce churn and boost retention. Discover essential design strategies that transform frustrating user journeys into engaging, personalized experiences that build loyalty and trust.

Is Graphic Design Dead?

Is Graphic Design Dead?

Graphic design isn’t dead, it’s evolving. Inspired by a Threads post, this piece dives into the art vs. design debate, AI’s impact, and why selling your value matters.

EMAIL NEWSLETTER