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

0 Comments

Submit a Comment

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

More News & Articles

Sign-Up: Enhancing Conversions through good UX

Sign-Up: Enhancing Conversions through good UX

Optimize your website’s sign-up process by focusing on clarity, ease, and user mindset. Clearly explain the purpose, benefits, and steps, and use social proof to build trust and drive conversions.

The Essential Guide to Getting Started on Freelance Writing

The Essential Guide to Getting Started on Freelance Writing

Explore the lucrative and fulfilling world of freelance writing with our essential guide. Learn about specialties like blogging, social media, article, and technical writing. Build a portfolio, find work, set up your business, and discover the potential earnings. Embrace the freedom of working from home and follow tips for success in your dream career.

EMAIL NEWSLETTER