/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.T7mYPSj8CGx/rev.6
*
* authors:
* GoToLoop
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
/**
* Talking Faces (v2.0)
* by Casselli
* mod GoToLoop (2015/Feb/07)
*
* forum.processing.org/two/discussion/9323/
* creating-a-extra-function-in-order-to-create-
* multiple-instances-of-the-same-group-of-primitives
*
* studio.processingtogether.com/sp/pad/export/ro.9G5yFfYFFDXi1/latest
*/
static final color BG = #403090;
static final short FACES = 4, SMOOTH = 4, FPS = 12;
final Face[] faces = new Face[FACES];
void setup() {
size(600, 600, JAVA2D);
smooth(SMOOTH);
frameRate(FPS);
ellipseMode(Face.MODE);
rectMode(Face.MODE);
stroke(Face.STROKE);
strokeWeight(Face.WEIGHT);
faces[0] = new Face(width>>2, height>>2, width/3, height/2.5);
faces[1] = new Face(3*width>>2, height>>2, width/3/1.2, height/2.5/1.2);
faces[2] = new Face(width>>2, 3*height>>2, width/3/2, height/2.5/2);
faces[3] = new Face(3*width>>2, 3*height>>2, width/3*1.2, height/2.5*1.2);
}
void draw() {
background(BG);
for (Face f : faces) f.display();
}
final class Face {
static final short MODE = CENTER;
static final float WEIGHT = 1.5;
static final color STROKE = 0;
static final color FACE = #FFFF00, NOSE = #FF0000;
static final color EYES = 0, MOUTH = #FF00FF;
final short x, y, w, h;
final float m;
Face(float xx, float yy, float ww, float hh) {
x = (short) xx;
y = (short) yy;
w = (short) ww;
h = (short) hh;
m = (ww+hh)/2.0;
}
void display() {
fill(FACE);
ellipse(x, y, w, h);
fill(NOSE);
ellipse(x, y, w/6, h>>2);
fill(EYES);
ellipse(x - w/6.5, y - (h>>3), m/9.65, m/9.65);
ellipse(x + w/6.5, y - (h>>3), m/9.65, m/9.65);
fill(MOUTH);
rect(x, y + h/3.2, w/2.6, random(h>>4));
}
}