Code
//letters based on 22 triangles
//SPACE BAR TURNS OFF THE TWITCH AND SLOWS THINGS DOWN
//ARROW KEYS ADJUST WIDTH AND HEIGHT
//LETTER KEYS CHANGE THE LETTER
int xspace = 50;
int yspace = 70;
int x = 70, y = 25;
int al = int(floor(random(26)));
int[][][] letters = {{{0,4,1,5,0,5},{0,4,1,5,1,4},{1,3,0,4,1,4},{1,3,0,4,0,3},{0,2,1,3,0,3},{0,2,1,3,1,2},{1,1,0,2,1,2},{2,0,1,1,1,0},{2,0,1,1,2,1},{2,0,3,1,2,1},{2,0,3,1,3,0},{3,1,4,2,3,2},{4,2,3,3,3,2},{4,2,3,3,4,3},{3,3,4,4,4,3},{3,3,4,4,3,4},{4,4,3,5,3,4},{4,4,3,5,4,5},{2,2,3,3,3,2},{2,2,3,3,2,3},{2,2,1,3,2,3},{2,2,1,3,1,2}},{{0,4,1,5,1,4},{1,3,0,4,1,4},{1,3,0,4,0,3},{0,2,1,3,0,3},{0,2,1,3,1,2},{1,1,0,2,1,2},{1,1,0,2,0,1},{0,0,1,1,0,1},{0,0,1,1,1,0},{2,0,1,1,1,0},{2,0,1,1,2,1},{2,0,3,1,2,1},{3,1,2,2,2,1},{2,2,1,3,2,3},{2,2,1,3,1,2},{2,2,3,3,2,3},{3,3,2,4,2,3},{3,3,2,4,3,4},{2,4,3,5,3,4},{2,4,3,5,2,5},{2,4,1,5,2,5},{2,4,1,5,1,4}},{{0,4,1,5,1,4},{1,3,0,4,1,4},{1,3,0,4,0,3},{0,2,1,3,0,3},{0,2,1,3,1,2},{1,1,0,2,1,2},{1,1,0,2,0,1},{2,0,1,1,1,0},{2,0,1,1,2,1},{2,0,3,1,2,1},{2,4,1,5,2,5},{2,4,1,5,1,4},{2,4,3,5,2,5},{2,4,3,5,3,4},{3,3,4,4,3,4},{2,0,3,1,3,0},{3,1,4,2,3,2},{3,1,4,2,4,1},{3,3,4,4,4,3},{0,4,1,5,1,4},{1,3,0,4,1,4},{3,3,4,4,3,4}},{{0,4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0,1},{0,0,1,1,0,1},{3,1,2,2,3,2},{3,1,2,2,2,1},{2,0,3,1,2,1},{2,2,3,3,2,3},{2,2,3,3,3,2},{3,3,2,4,2,3},{2,4,1,5,1,4},{1,3,2,4,1,4},{1,3,2,4,2,3},{3,3,2,4,2,3},{2,2,3,3,2,3},{3,1,2,2,2,1},{2,0,3,1,2,1}},{{0,0,1,1,1,0},{2,0,1,1,1,0},{2,0,1,1,2,1},{2,0,3,1,2,1},{2,0,3,1,3,0},{4,0,3,1,3,0},{4,0,3,1,4,1},{3,1,2,2,3,2},{2,2,1,3,2,3},{1,3,0,4,1,4},{0,4,1,5,1,4},{0,4,1,5,0,5},{2,4,1,5,1,4},{2,4,1,5,2,5},{2,4,3,5,2,5},{2,4,3,5,3,4},{4,4,3,5,3,4},{0,0,1,1,1,0},{2,0,1,1,1,0},{2,0,1,1,2,1},{2,0,3,1,2,1},{0,4,1,5,0,5}}};
int[][] ala = letters[al];
float[][] p = new float[22][6];
float[][] v = new float[22][6];
float[][] a = new float[22][6];
float bounce = .9;
float speed = .5;
//make them twitchy
float ox = xspace/15;
float oy = yspace/15;
boolean twitch = true;
void setup(){
size(400,400);
smooth();
//define positions
for(int i=0;i<22;i++){
for(int j=0;j<6;j++){
if(j%2==0){
p[i][j] = float(x+xspace*ala[i][j]);
}else{
p[i][j] = float(y+yspace*ala[i][j]);
}
}
}
}
void loop(){
if(twitch==true){
ox = xspace/15;
oy = yspace/15;
bounce = .9;
speed = .5;
}else{
ox = 0;
oy = 0;
bounce = .1;
speed = .2;
}
background(190,197,246);
fill(255,85,13,100);
stroke(255);
for(int i=0;i<22;i++){
for(int j=0;j<6;j++){
if(j%2==0){
a[i][j] = float(x+xspace*ala[i][j]-p[i][j])*bounce;
}else{
a[i][j] = float(y+yspace*ala[i][j]-p[i][j])*bounce;
}
v[i][j] += a[i][j];
v[i][j] *= speed;
p[i][j] += v[i][j];
}
triangle(random(-ox,ox)+p[i][0],random(-oy,oy)+p[i][1],random(-ox,ox)+p[i][2],random(-oy,oy)+p[i][3],random(-ox,ox)+p[i][4],random(-oy,oy)+p[i][5]);
}
/*
beginShape(TRIANGLE_STRIP);
for(int i=0;i<22;i++){
fill(255,50);
vertex(p[i][0],p[i][1]);
vertex(p[i][2],p[i][3]);
vertex(p[i][4],p[i][5]);
}
endShape();
*/
}
void keyPressed(){
if(int(key)>96&&int(key)<=122){
al = int(key)-97;
}else if(int(key)>64&&int(key)<=90){
al = int(key)-65;
}else if(int(key)==32){
if(twitch==true){
twitch = false;
}else{
twitch = true;
}
}else if(key==UP){
yspace++;
}else if(key==DOWN){
yspace--;
}else if(key==LEFT){
xspace--;
}else if(key==RIGHT){
xspace++;
}
//velocities
v = new float[22][6];
//accelerations
a = new float[22][6];
//targets
ala = letters[al];
}
022 -- Intermorphable Alphabet: A custom graphic alphabet
Statement:Create an alphabet (using any graphic primitives you prefer). Conform all of your letters to the same "structuring logic", such that any letter could smoothly morph into any other letter. For example, design an alphabet in which every letter is constructed from 3 arcs, or from 4 rectangles, or from 7 triangles, etc. etc. Some people who have done this: Peter Cho's typeMeNot, David Lu's example, Nik Pashenkov's Alphabot.
NOTE: For this assignment, you *should* be able to animate the transitions from one letter to another. You are granted one extra week to complete this specific feature, if you need the extra time. If you can complete the animated transitions this week, please do. The required interaction is one in which pressing a key calls forth an animated transition (of approximately a second's duration) to the desired letter.
letters with a terrible nervous twitch