//Shapes fill and unfill based on the number
//keys that are pressed... Keys 0-9 may be used
//All other keys have no effect.
int quadSize=25;
int[] numKeyFill= new int[2560];
int randFill, whereAmI, x,y;
int prev=10;
int twoB4=10;
int current=0;
int c =0;
void setup(){
size(400,400);
stroke(255);
noFill();
randomSeed(2);
for(int i=0; i<numKeyFill.length; i++){
randFill= int(random(1,3));
if(randFill==1){
numKeyFill[i] = 255;
}
else{
numKeyFill[i]=0;
}
}
}
void draw(){
background(0);
pattern();
}
void pattern(){
for(int e=800; e>=80; e-=80){
if(current<10){
if(((current+1)%(e/80)==0)) {
fill(255);
}
else{
fill(0);
}
}
if(prev<10){
if(((prev+1)%(e/80)==0)){
fill(255);
}
else{
fill(0);
}
}
if(twoB4<10){
if(((twoB4+1)%(e/80)==0)){
fill(255);
}
else{
fill(0);
}
}
ellipse(width/2.0, height/2.0, e/2, e/2);
}
noFill();
for(int n=0; n<16; n++){
for(int i=0; i<16; i++){
whereAmI = i+n*i;
if(i==0){
whereAmI = n+n*i;
}
x=i*quadSize;
y= n*quadSize;
if(numKeyFill[whereAmI*(current+1)]==255){
fill(255);
}
else{
noFill();
}
quad(x, y, x+quadSize/2, y, x+quadSize, y+quadSize, x +quadSize/2, y+quadSize);
}
}
}
void keyPressed(){
if(key>=48 && key<=57){
c=key-48;
twoB4=prev;
prev=current;
current = c;
}
}
void keyReleased(){
if(key>=48 && key<=57){
c=key-48;
current = twoB4;
twoB4=prev;
prev = c;
}
}
Exercise 09: Create a black-and-white abstract image that changes in response to input from the keyboard. Utilize the keyPressed() and keyReleased() functions.