Code a week #1

I have been researching creative coding as a practice in art education for a year now and thinking about much longer. Starting a new year, I realized I have not coded that much during the last year. So I set myself a little challenge -To write a little nifty program every week. – To get myself familiar with the most basic stuff again. These are nothing miraculous or fancy. But something fun for myself. Besides the code, I am exploring the artistic qualities of the code in these little sketches. I am using Processing as my tool as it is possible to show the live code in a blog fairly easily. Might be that later on I’ll transition to try something else. Also, I am drawing some inspiration from Daniel Shiffman’s book: The Nature of Code.

Code 1: Ludwig

show code

void thought1(){
int m = second();
if (m >5 && m <15 ){
fill(0);
text("Tell them I've had a wonderful life.", 30, 50);
} else {
fill(255);
text("Tell them I've had a wonderful life.", 30, 50);
}
}
void thought2(){
int m = second();
if (m >18 && m < 27){
fill(0);
text("What is troubling us is the tendency to believe that the mind is like a little man within.", 10, 200);
} else {
fill(255);
text("What is troubling us is the tendency to believe that the mind is like a little man within.", 10, 200);
}
}
void thought3(){
int m = second();
if (m >31 && m < 43){
fill(0);
text("A serious and good philosophical work could be written consisting entirely of jokes.", 10, 100);
} else {
fill(255);
text("A serious and good philosophical work could be written consisting entirely of jokes.", 10, 100);
}
}
void thought4(){
int m = second();
if (m >49 && m < 60){
fill(0);
text("Not how the world is, but that it is, is the mystery.", 50, 300);
} else {
fill(255);
text("Not how the world is, but that it is, is the mystery.", 50, 300);
}
}

class Foot {
float x, y;

float prevX, prevY;

Foot() {
x = width/2;
y = height/2;
}

void render() {

stroke(int (random(0,50)));
line(prevX,prevY,x, y);

}

//Diffrent kind of steps
void step1() {
prevX = x;
prevY = y;

float stepx = random(-1, 1);
float stepy = random(-1, 1);

float stepsize = montecarlo()*50;
stepx *= stepsize;
stepy *= stepsize;

x += stepx;
y += stepy;
x = constrain(x, 0, width-1);
y = constrain(y, 0, height-1);
}
void step2() {
prevX = x;
prevY = y;

float stepx = random(-1, 1);
float stepy = random(-1, 1);

float stepsize = montecarlo()*25;
stepx *= stepsize;
stepy *= stepsize;

x += stepx;
y += stepy;
x = constrain(x, 0, width-1);
y = constrain(y, 0, height-1);
}
void step3() {
prevX = x;
prevY = y;

float stepx = random(-1, 1);
float stepy = random(-1, 1);

float stepsize = montecarlo()*5;
stepx *= stepsize;
stepy *= stepsize;

x += stepx;
y += stepy;
x = constrain(x, 0, width-1);
y = constrain(y, 0, height-1);
}
void step4() {
prevX = x;
prevY = y;

float stepx = random(-1, 1);
float stepy = random(-1, 1);

float stepsize = montecarlo()*50;
stepx *= stepsize;
stepy *= stepsize;

x += stepx;
y += stepy;
x = constrain(x, 0, width-1);
y = constrain(y, 0, height-1);
}
void step5() {
stroke(0);
point(x,y);
int choice = int(random(4));

if (choice == 0) {
x++;
} else if (choice == 1) {
x--;
} else if (choice == 2) {
y++;
} else {
y--;
}

x = constrain(x,0,width-1);
y = constrain(y,0,height-1);
}
}

float montecarlo() {
while (true) {

float r1 = random(1);
float probability = pow(1.0 - r1,8);

float r2 = random(1);
if (r2 < probability) {
return r1;
}
}
}
PFont myFont;
Foot w;
float stepper = 0;
int x;
int y;
void setup() {
size(640,480);
w = new Foot();
background(255);
myFont = createFont("Georgia", 12);
textFont(myFont);
}

void draw() {
fill(255,25);
noStroke();
rect(0,0,height,width);

thought1();
thought2();
thought3();
thought4();
fill(255,25);
rect(0,0,645,485);
x = width/2;
y = height/2;
int stepper = int (random(5));
if (stepper == 0){
w.step1();
w.render();
} else if (stepper == 1){
w.step2();
w.render();
}else if (stepper == 2){
w.step3();
w.render();
}else if (stepper == 3){
w.step4();
w.render();
} else {
w.step5();
w.render();
}
}

Comments are closed.