Program TYPE

Create a typing program to display a different image for each letter on the keyboard.

Class Notes

capture keyboard input

int x = 100;
int y = 100;

PFont font;

void setup() {
size(500,300);
smooth();
strokeWeight(4);
font = loadFont("Arial-Black-48.vlw");
textFont(font); }

void draw () {
background(204);
if (keyCode == UP) {
y--;
}
line (20,y,100,y);

text(key,28,75);
}


create simple mouse buttons

void setup() {
size(500,300);
noStroke(); }

void draw() {
background(204);
if ((mouseX <= width/2) && (mouseY <= height/2)) {
fill(0);
rect(0,0,width/2,height/2); // upper left
} else if ((mouseX <= width/2) && (mouseY > height/2)) {
fill(255,0,0);
rect(0,height/2,width/2,height/2); // upper right
} else if ((mouseX > width/2) && (mouseY < height/2)) {
fill(0,255,0);
rect(width/2,0,width/2,height/2); // lower left
} else {
fill(0,0,255);
rect(width/2,height/2,width/2,height/2); // lower left
}
}


capture mouse input

void setup () {
smooth();
size(300,300);
noStroke(); }

void draw() {
background(222);
float x = mouseX;
float y = mouseY;
float ix = width - mouseX;
float iy = width - mouseY;
if (mousePressed) {
cursor(CROSS); // ARROW, CROSS, HAND, MOVE, TEXT, WAIT
ellipse(ix,iy,20,20); }

}