// Desma 28: Assignment 10
// Wayne Fan
// Animate two shapes of your own design.
// Give one a mechanical motion and give
// the other a more organic motion.
// A program that demostrate the interaction between two
// simple shapes that express organic and mechanical
// motions.
void setup(){
size(400, 400);
background(#ffffff);
smooth();
//randomSeed(30);
frameRate(60);
}
float sz_s = 0;
float sz_i = 20;
float posX = 200;
float posY = 200;
float shell = 15;
float shell_b = 10;
boolean touch = false;
float sz_s2 = 0;
float sz_i2 = 10;
float posX2 = 200;
float posY2 = 200;
float x = 50;
float y = 80;
void draw(){
background(#ffffff);
float posX2_c = constrain(posX2, 280, 320);
float posY2_c = constrain(posY2, 180, 220);
sz_s2 = sz_s2 + 0.1; // breath: sine variable
float sz2 = sin(sz_s2)*3 + sz_i2;
x = x + random(-1, 3);
y = y + random(-1, 3);
if( x > 430 ){
x = 0;
y= 0;
}
if( y > 430){
x= 0;
y= 0;
}
ellipse(x, y, sz2, sz2);
float coll_worm = dist(x, y, width/2, height/2);
println(coll_worm);
sz_s = sz_s + 0.1; // breath: sine variable
fill(#000000);
if(sz_i < 100 && touch == false){ // grow
sz_i = sz_i + 0.15;
}
if(touch == true){ // shrink on touch
if(sz_i > 31){
sz_i = sz_i - 4;
}
}
if(coll_worm < 50){ // shrink on touch
if(sz_i > 31){
sz_i = sz_i - 4;
}
}
if(sz_i < 31){ // start grow again
touch = false;
}
float coll = dist(mouseX, mouseY, posX, posY);
//float sz = sin(sz_s)*2 + sz_i;
float sz = sz_i;
if(coll < sz){
touch = true;
if(shell < 40){
shell = shell + 6;
shell_b = shell_b + 4;
}
}
if(coll_worm < 50){
touch = true;
if(shell < 40){
shell = shell + 6;
shell_b = shell_b + 4;
}
}
if(coll > sz){
if(sz > 40){
if(shell > 15){
shell = shell - 3;
shell_b = shell_b - 2;
}
}
}
rectMode(CENTER);
ellipse(posX, posY, sz+shell, sz+shell);
fill(#ffffff);
ellipse(posX, posY, sz+shell_b, sz+shell_b);
fill(#000000);
ellipse(posX, posY, sz, sz);
}
Exercise 10: Animate two shapes of your own design. Give one a mechanical motion and give the other a more organic motion.