Skip to content

Instantly share code, notes, and snippets.

@caitlinelise
Last active November 1, 2019 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save caitlinelise/b5c22ef67f38aaf42a0589a11a51bb44 to your computer and use it in GitHub Desktop.
Save caitlinelise/b5c22ef67f38aaf42a0589a11a51bb44 to your computer and use it in GitHub Desktop.
Colour keyboard final
import processing.pdf.*;
int maxHeight = 40;
int minHeight = 20;
int letterHeight = maxHeight; // Height of the letters
int letterWidth = 40; // Width of the letter
int x = -letterWidth; // X position of the letters
int y = 0; // Y position of the letters
boolean newletter;
boolean saveOneFrame = false;
int numChars = 26; // There are 26 characters in the alphabet
color[] colors = new color[numChars];
void setup() {
size(520, 700);
noStroke();
colorMode(HSB, numChars);
background(0,0,100);
// Set a hue value for each key
for(int i = 0; i < numChars; i++) {
colors[i] = color(i, numChars, numChars);
}
}
void draw() {
if(saveOneFrame == true) {
beginRecord(PDF, "COdE.pdf");
}
if(newletter == true) {
// Draw the "letter"
int y_pos;
if (letterHeight == maxHeight) {
y_pos = y;
noStroke();
colorMode(HSB, numChars);
ellipse( x, y_pos, letterWidth, letterHeight );
} else {
y_pos = y + minHeight;
noStroke();
colorMode(HSB, numChars, 0,0,100);
ellipse( x, y_pos, letterWidth, letterHeight );
}
newletter = false;
}
if(saveOneFrame == true) {
endRecord();
saveOneFrame = false;
}
}
void keyPressed()
{
// If the key is between 'A'(65) to 'Z' and 'a' to 'z'(122)
if((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z')) {
int keyIndex;
if(key <= 'Z') {
keyIndex = key-'A';
letterHeight = maxHeight;
fill(colors[keyIndex]);
} else {
keyIndex = key-'a';
letterHeight = minHeight;
fill(colors[keyIndex]);
}
} else {
fill(255);
letterHeight = 30;
}
newletter = true;
// Update the "letter" position
x = ( x + letterWidth );
// Wrap horizontally
if (x > width - letterWidth) {
x = 0;
y+= maxHeight;
}
// Wrap vertically
if( y > height - letterHeight) {
y = 0; // reset y to 0
}
}
void mousePressed() {
beginRecord(PDF, "COLOUR PAGE1.pdf");
}
void mouseReleased() {
endRecord();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment