Face

This is an example of Processing to learn: -To use Text to Speech library (ttslib) -To draw shapes capable to follow mouse position -To introduce an image using PImage and insert into desired screen coordinates -To control the frame rate -To assign randomly or according to Perlin noise diferent face colours. -To execute something when a key is pressed. -To change mouth and eye shape using a conditional statement  face

show code

float r, g, b, R, G, B;
float mouthHeight=10;
float eyeHeight=20;
void setup() {
size (800, 600);
background (127);
}
void draw() {
background(255);
mouthHeight+=2;
if (mouthHeight>50) {
mouthHeight=10;
}
eyeHeight=eyeHeight-2;
if (eyeHeight<0) {
eyeHeight=20;
}
frameRate(5);
r= random(127,255);
g= random(127,255);
b= random(127,255);
R= random(126);
G= random(126);
B= random(126);
fill(r, g, b);
ellipse(mouseX, mouseY, 250, 350);
fill (R, G, B);
rectMode(CENTER);
rect(mouseX-50, mouseY-100, 40, eyeHeight);
rect(mouseX+50, mouseY-100, 40, 20);
ellipse(mouseX, mouseY+130, 60, mouthHeight);
if (mouseY < height/2) {

println("I am on top!");
}
else {

println("I am at the bottom!");
}
if (mouseX < width/2) {

println("I am on the left hand!");
}
else {

println("I am on the right hand!");
}
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
mouseX=width/2; mouseY=height/2-100;
println( "GOING UP ARROW");
}
else if (keyCode == DOWN) {
mouseX=width/2; mouseY = height/2+100;
println("GOING DOWN ARROW");
}
}
else {
}
}

——————————————— //with TEXT TO SPEECH import guru.ttslib.*; PImage logo; TTS tts; float t, r, g, b, R,G, B; float surprise=10; void setup(){ logo= loadImage(“logo.png”); size (800,600); background (127); tts=new TTS(); } void draw(){ image(logo, 0, 0); surprise+=2; if (surprise>50){ surprise=10; } frameRate(5); r= random(255); g= random(255); b= random(255); R= map(noise(t),0,1,0,255); G= map(noise(t+1),0,1,0,255); B= map(noise(t+2),0,1,0,255); t+=1; fill(r,g,b); ellipse(mouseX, mouseY, 250, 350); fill (R,G,B);rectMode(CENTER); rect(mouseX-50, mouseY-100,40,20); rect(mouseX+50,mouseY-100,40,20); ellipse(mouseX,mouseY+150,100,surprise); } void keyPressed(){ tts.speak(“I am an human being”); println(“I am human”); }

logo

The best way to predict the future is to invent it (Alan Kay)