#FLcreativecoding Draw your name: part 2
/*
* Creative Coding
* Week 1, 02 - Draw your name! (part 2)
* 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.
* Press 'r' to erase your drawing and start with a blank screen
*
modiefied by Marius Ivaskevicius
press [t] to display name in color
press [y] to display name in black (because black is not a color ;-) )
use variable NAME for obvious purpose
*/
String NAME="MARIUS";
PFont f; // STEP 2 Declare PFont variable
// variables for the angle (in radians) and increment
float angle;
float inc;
void setup() {
size(1200, 400);
background(0);
f = createFont("UNICODE0.TTF",100); // STEP 3 Create Font
rectMode(CENTER); // rectangles drawn from the centre
// initialise angle and inc to 0
angle = 0;
inc = 0;
}
void draw() {
/*
textFont(f,100); // STEP 4 Specify font to be used
fill(20,170,200,100); // STEP 5 Specify font color
text("MARIUS",600+random(10),300+random(10)); // STEP 6 Display Text
*/
/* draw a rectangle at your mouse point while you are pressing
the left mouse button */
// map the mouse x position to the range (0.01, 0.08)
inc = map(mouseX, 0, width, 0.01, 0.08);
// incremment the current angle
angle = angle + inc;
if (mousePressed) {
stroke(170);
fill(120, 60);
rect(mouseX, mouseY, 2, 2);
line(mouseX, mouseY, pmouseX, pmouseY); // pmouse is the mouse position at the previous frame
// oscillate the radius over time
float radius = 1000 * abs( sin(frameCount) );
float first_tempX = mouseX + radius * cos( angle);
float first_tempY = mouseY + radius * sin( angle);
float second_tempX = mouseX + radius * cos(-angle*5);
float second_tempY = mouseY + radius * sin(-angle*5);
// draw some lines and circles using transparency
//stroke(110, 100);
stroke(random(50),random(50),255, 20);
line(mouseX, mouseY, first_tempX, first_tempY);
line(mouseX, mouseY, second_tempX, second_tempY);
float temp_w = random(3);
ellipse(first_tempX, first_tempY, temp_w, temp_w);
ellipse(second_tempX, second_tempY, temp_w, temp_w);
}
// 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(0);
}
if (keyPressed == true && key == 't') {
textFont(f,100); // STEP 4 Specify font to be used
fill(255,random(170),random(200),100); // STEP 5 Specify font color
text(NAME,600+random(10),300+random(10)); // STEP 6 Display Text
}
if (keyPressed == true && key == 'y') {
textFont(f,100); // STEP 4 Specify font to be used
fill(0,0,0,50); // STEP 5 Specify font color
text(NAME,600+random(10),300+random(10)); // STEP 6 Display Text
}
}
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home