Forked from caitlinelise/Caitlin Cole final code
Last active
October 25, 2019 00:25
-
-
Save timturnidge/ec757d98c74620644fefa7ac63fbd6e3 to your computer and use it in GitHub Desktop.
Colour keyboard final
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.pdf.*; | |
int maxHeight = 30; | |
int minHeight = 20; | |
int letterHeight = maxHeight; // Height of the letters | |
int letterWidth = 30; // 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, "Line.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); | |
ellipse( x, y_pos, letterWidth, letterHeight ); | |
fill(0,0,50); | |
rect( x, y_pos+minHeight, 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(0,0,100); | |
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, "Lines.pdf"); | |
//background(0); | |
} | |
void mouseReleased() { | |
endRecord(); | |
//background(255); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment