Skip to content

Instantly share code, notes, and snippets.

@MichaelPaulukonis
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelPaulukonis/9223885 to your computer and use it in GitHub Desktop.
Save MichaelPaulukonis/9223885 to your computer and use it in GitHub Desktop.
painting with text
/* Traditionally, text and image are segregated in Western Art.
This sketch plays with those boundaries, providing an polychromatic
text painting environment.
Mouse click and drag to paint (previous paints will fade slightly).
Color and size are based on mouse position.
Space to paint without fading previous actions.
RIGHT/LEFT to increase/decrease rotation of letters.
R to reset rotation to 0.
UP/DOWN to change paint mode.
Delete or Backspace to clear the screen.
S to Save.
inspired by Marco Scarfagna's sketch https://class.coursera.org/compartsprocessing-001/forum/thread?thread_id=145#post-1804
https://class.coursera.org/compartsprocessing-001/forum/profile?user_id=536813
*/
String bodycopy = "An sketch a day keeps the doctor away........*****xxx ";
int curRot = 0;
void setup(){
size(900,600);
strokeWeight(2);
textAlign(CENTER, CENTER);
colorMode(HSB, width, height, 100);
clearScreen();
}
void draw(){
if (mousePressed && mouseY > 0 && mouseY < height
&& mouseX > 0 && mouseX < width) {
drawGrid();
}
}
void drawGrid() {
// if mouseX > width/2, reverse course.... [eliminated for now]
int stepX = mouseX + 5;
//if (stepX > width / 2) stepX = width - stepX;
textSize(stepX);
for (int gridY = 0; gridY < height; gridY += stepX) {
for (int gridX = 0; gridX < width; gridX += stepX) {
setPaintMode(gridX, gridY);
stroke(255);
char letter = getText();
pushMatrix();
// move to the CENTER of the invisible rectangle [that we aren't drawing]
// to be honest, stepX/5 was found experimentally.
// since characters can be all over the place in the max/min of the font
// it's really hard [for me] to find a good all-over alignment
translate(gridX + stepX/2, gridY + stepX/5);
rotate(radians(curRot));
text(letter, 0, 0);
popMatrix();
}
}
}
char getText() {
int i = int(random(bodycopy.length()));
return bodycopy.charAt(i);
}
void clearScreen() {
background(0, 0, 100);
}
void mousePressed() {
fill(#FFFFFF, 50);
rect(0,0,width,height);
}
int nextPaintMode(int direction) {
currentMode = (currentMode + direction) % paintModes;
if (currentMode < 0) currentMode = paintModes - 1;
return currentMode;
}
void nextRotation(int direction) {
int step = 5;
curRot = (curRot + step*direction) % 360;
if (curRot < 0) curRot = 360;
}
int paintModes = 4; // 1..n
int currentMode = 0;
void setPaintMode(int gridX, int gridY) {
switch(currentMode) {
case 1:
fill(width-gridX, gridY, 100, 100);
break;
case 2:
fill(gridX/2, gridY/2, 900, 180);
break;
case 3: // offset from default
int x = (gridX + width/2) % width;
int y = (height-gridY + height/2) % height;
fill(x, y, 900, 180);
break;
case 0:
default:
fill(gridX, height-gridY, 900, 180);
break;
}
}
// only resets the angle, for now...
void reset() {
curRot = 0;
}
void keyPressed() {
switch(key) {
case CODED:
if (keyCode == UP || keyCode == DOWN) {
if (keyCode == UP) {
nextPaintMode(1);
} else {
nextPaintMode(-1);
}
println("currentMode: " + currentMode);
}
if (keyCode == LEFT || keyCode == RIGHT) {
if (keyCode == LEFT) {
nextRotation(-1);
} else {
nextRotation(1);
}
}
break;
case DELETE:
case BACKSPACE:
clearScreen();
break;
case ' ':
drawGrid();
break;
case 'r':
case 'R':
reset();
break;
case 's':
case 'S':
saveFrame("screenshot####.png");
println("saved");
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment