Back to photostream

Creative Coding - Draw Your Name (remix)

 

/*

* Creative Coding

* Week 1, 01 - Draw your name!

* by Indae Hwang and Jon McCormack

* Copyright (c) 2014 Monash University

 

* This program allows you to draw using the mouse.

* Press 's' to save your drawing as an image to the file "yourName.jpg"

* Press 'r' to erase your drawing and start with a blank screen

*

*/

 

PFont font;

String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

char toPrint;

 

 

// setup function -- called once when the program begins

void setup() {

 

 

// set the display window to size 500 x 500 pixels

size(500, 500);

 

 

// set the background colour to white

background( #333333 );

 

 

// set the rectangle mode to draw from the centre with a specified radius

rectMode(RADIUS);

 

font = loadFont( "AmericanTypewriter-Condensed-16.vlw" );

}

 

 

// draw function -- called continuously while the program is running

void draw() {

 

 

/* draw a rectangle at your mouse point while you are pressing

the left mouse button */

 

 

if( mousePressed ) {

textFont( font, random( 1, 32 ) );

toPrint = letters.charAt( floor( random( 0, 26 ) ) );

fill( #ff00ff, random( 128, 255 ) );

text( toPrint, mouseX, mouseY );

}

 

 

// save your drawing when you press keyboard 's'

if (keyPressed == true && key=='s') {

saveFrame("yourName.jpg");

}

 

 

// erase your drawing when you press keyboard 'r'

if (keyPressed == true && key == 'r') {

background( #333333 );

}

}

 

585 views
1 fave
0 comments
Uploaded on August 9, 2015