Snakes on a Screen

The processing assignment we were tasked with, was an exercise in iterative art. So in the theme of the assignment, my code went through various iterations. Inspired by the guest lecture by Ted Mittew, I failed early and often. The first class I made using help from the MEDA102 Gist page and a YouTube tutorial, however my code didn’t execute as intended. The first 4 images show my first attempt at making a moving object. My code now creates a dynamic artwork different in every iteration. The code generates an array of bouncing snake that leaves a geometric trail, similar in aesthetic to an Aztec inscription. By altering the randomness of the speed of the snakes and the position of the squares I was able to capture the desired aesthetic in every random iteration of the code. Similar to LeWitts wall drawings, the code is a set of instructions generating a new interpretation of the artwork.
1

7 5
3.2
Here is the results of my final code.

15

Here we see the effects of higher speeds.

14

16

rgkxs

Snake

SnakeClass

//Declare class array
//Here the array is making 5 random smakes to be called later
Snake [] mysnakes = new Snake[5];

void setup() {
// size(850,650);
background(random(255),random(255),random(255));
fullScreen();

//snake speed. These defines the speed of the snakes which is commom among all snakes
int xspeed = (int) random(1,7);
int yspeed = (int) random(1,7);

//Initialise
//the for loop here makes multipul snakes from the array above
for(int i =0; i<5; i++){
mysnakes[i] = new Snake(random(width),random(height),(xspeed),(yspeed));
}
}

void draw() {
//Call Functionanlity
//here the run function executes all other functions that happen simultaneously in order for it to run correctly
for(int i =0; i<5; i++){
mysnakes[i]. run();
}
}

class Snake{

//Global varriables
//These variables are used thoughout the code to define the snakes
float x ;
float y ;
float speedX = 0;
float speedY = 0;
color k;
color r;
color g;
color b;

//Constuctor
//x and y speed as well as size variables to be entered
Snake(float _x, float _y, float s1, float s2){

x=_x;
y=_y;
speedX = s1;
speedY = s2;
k = color((int)random(255),(int)random(255),(int)random(255));
r = color((int)random(255),(int)random(255),(int)random(255));
g = color((int)random(255),(int)random(255),(int)random(255));
b = color((int)random(255),(int)random(255),(int)random(255));
}

//Functions
//run function will execute all of this when call rather than call each function seperatly
void run(){
display();
move();
draw();
}

void move(){
x += speedX;
y += speedY;
//These commands makes the snakes bounce when they touch the sides
//This code was borrowed from a YouTube tutorial
if (x > width){
speedX = speedX * -1;
}

if (x < 0){
speedX = speedX * -1;
}

if (y > height){
speedY = speedY * -1;
}

if (y < 0){
speedY = speedY * -1;
}
}

//Display was used in a video tutorial I followed on how to make classes
void display() {

noStroke();
//noLoop();

//MAIN SQUARE
fill(r);
rect(x,y,50,50);

//Top Left Square
fill(g);
rect(x,y,25,25);

//Top right Square
fill(b);
rect(x+30,y,25,25);

//Bottom right square
fill(k);
rect(x+30,y+30,25,25);

//Middle Square
fill(k);
rect(x+12.5,y+12.5,25,25);

}

//This draw fucntion creates the series of squares that make up the snakes
void draw(){
fill(b);
rect(x,y,60,60);

//left eye
fill(255);
rect(x+10,y+5,10,10);
//right eye
fill(255);
rect(x+35,y+5,10,10);

//scale left
fill(g);
rect(x,y+20,15,15);

//scale right
fill(g);
rect(x+40,y+20,15,15);

//scale right 2
fill(r);
rect(x+35,y+35,10,10);

//scale left 2
fill(r);
rect(x+12,y+35,10,10);

//tounge
fill(250,0,0);
rect(x+27,y+45,3,7);

if(speedX > 0){

//left eye ball
fill(0);
rect(x+15,y+10,5,5);
//right eye ball
fill(0);
rect(x+40,y+10,5,5);
} else if (speedY > 0){
//left eye ball
fill(0);
rect(x+10,y+5,5,5);
//right eye ball
fill(0);
rect(x+35,y+5,5,5);
} else {
if(speedY > 0){

//left eye ball
fill(0);
rect(x+15,y+10,5,5);
//right eye ball
fill(0);
rect(x+40,y+10,5,5);
} else{
//left eye ball
fill(0);
rect(x+10,y+10,5,5);
//right eye ball
fill(0);
rect(x+35,y+10,5,5);

}
}
}
}

Leave a comment