#FLcreativecoding Draw your name: part 3
/*
* Creative Coding
* Week 1, 03 - Draw your name! (part 3)
* 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 all your drawing and start with a blank screen
*
modiefied by Marius Ivaskevicius
using friendly virtual agent to draw by itself
its a bit drunk so movement direction and speed is randomised
draws the name accoring to array "map"
in which "." is black and numbers 1-4 are colors
one can use variable SPEED to control how many steps agent moves
one can use variable FADEOUT to control how much past traces are fading out.
*/
int SPEED=10000;
int FADEOUT=20;
String[] map ={ "...................................",
"...................................",
"..........1111..11..11..1.1.1.1....",
"..........2.2.2.2.2.2.2.2.2.2.22...",
"..........3.3.3.333.33..3.3.3...3..",
"..........4.4.4.4.4.4.4.4..44.44...",
"..................................."};
// variables to store the delay and target counts
int delayCount;
int targetCount;
//agent init
boolean agent=true;
float agentX=0;
float agentY=0;
float agentSpeed=3;
float agentSpeedNoise=1;
float agentSpeedMax=10;
float agentSpeedMin=1;
float agentSpeedX=0;
float agentSpeedY=0;
float agentDir=125;
float agentDirNoise=180;
float mSize;
// setup function
void setup() {
size(1500, 300);
background(0);
delayCount = 0;
targetCount = (int) random(5, 50); // set target count to a random integer between 10 and 50
}
//--------------- function that prevenst angle from going beyond 0-360 -----------------------------------------------
float safeTurn(float preAngle,float turnAngle){
preAngle+=turnAngle;
if(preAngle<0 br="" preangle=""> if(preAngle>360){preAngle-=360;}
return preAngle;
}
// draw function
void draw() {
stroke(0,FADEOUT);
fill(0,FADEOUT);
rect(0,0,width,height);
for(int skipFrames=0;skipFrames<=SPEED;skipFrames++){
//agent moves
agentSpeedX=agentSpeed*cos(radians(agentDir));
agentSpeedY=agentSpeed*sin(radians(agentDir));
agentX+=agentSpeedX;
agentY+=agentSpeedY;
//walk arround
if(agentX>width){agentX-=width;}
if(agentX<0 agentx="" br="" width=""> if(agentY>height){agentY-=height;}
if(agentY<0 agenty="" br="" height="">
agentSpeed+=random(agentSpeedNoise)-agentSpeedNoise/2;
if(agentSpeed>agentSpeedMax){agentSpeed=agentSpeedMax;}
if(agentSpeed
if(agentDir<0 agentdir="" br=""> if(agentDir>360){agentDir-=360;}
//set colors by map
int gridX=0;
int gridY=0;
int gridXsize=width/map[0].length();
int gridYsize=height/map.length;
for(int i=0;i0>
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home