メニュー 閉じる

067. p5.jsで炭酸の泡のようなエフェクトを作ってみる

泡がどんどん浮き上がるエフェクトです。

http://www.velvet-number.com/p5_test/test047/

var back_img;

var images01 = [];
var images02 = [];
var images03 = [];
var images04 = [];

var brands01 = [];
var brands02 = [];
var brands03 = [];
var brands04 = [];

var bubbles = [];

function preload () {

	back_img = loadImage ('images/back_image.jpg');

}

function setup () {

	pixelDensity (displayDensity ());
	createCanvas (windowWidth, windowHeight);
	colorMode (RGB, 256);
	background (0);

}

function draw () {

	background (0);

	image (back_img, 0, 0, width, height);

	bubbles.push (new BubblesBase (random (width), height + 40.0, random (20,0), random (0.1, 20.0)));

	for (var i = 0; i < bubbles.length; i++) {
		bubbles[i].update ();
		bubbles[i].render ();
		if (bubbles[i].by < 0) {
			bubbles.splice (i, 1);
		}
	}

}

function BubblesBase (x, y, r, up) {

	this.bx = x;
	this.by = y;
	this.br = r;

	this.update = function () {

		this.by -= up;

	}

	this.render = function () {

		ellipseMode (CENTER);
		fill (255, 80);
		noStroke ();
		ellipse (this.bx, this.by, this.br);

	}

}

 

 

Posted in p5.js , processing