Javascript Sketches: SHARK VARIATIONS

 

Screenshot 2017-09-22 13.00.43

I used the following code to generate this image in Processing

void setup(){
background(255);
size(650,650);
//this code describes a plain white backdrop
noLoop();
}
float resolution = 640;

void draw(){

for (int i =10 ; i < 650 ; i = i + 80){
for (int j = 10 ; j < 650 ; j = j + 80){

//this refers to the rate at which the triangles are repeated:
//every 80 pixels horizontally or vertically a new loop begins

//triangle set 1:

//this creates a set of eight congruent triangles which tessellate across the grid
drawTriangle (i-20,j-10,i+20,j+10,i-20,j+30);
drawTriangle (i+20,j+10,i-20,j+30,i+20,j+50);
drawTriangle (i+20,j-30,i+60,j-10,i+20,j+10);
drawTriangle (i+20,j+10,i+60,j+30,i+20,j+50);

drawTriangle (i+20,j-30,i-20,j-10,i+20,j+10);
drawTriangle (i+60,j+30,i+20,j+50,i+60,j+70);
drawTriangle (i+60,j-10,i+20,j+10,i+60,j+30);
drawTriangle (i-20,j+30,i+20,j+50,i-20,j+70);

//triangle set 2

//this creates a smaller set of triangles, which sit just a few pixels inside the first set.
drawTriangle (i-16,j-2,i+12,j+10,i-16,j+22);
drawTriangle (i+16,j+18,i-12,j+30,i+16,j+42);
drawTriangle (i+24,j-22,i+52,j-10,i+24,j+2);
drawTriangle (i+24,j+18,i+52,j+30,i+24,j+42);

drawTriangle (i+16,j-22,i-12,j-10,i+16,j+2);
drawTriangle (i+54,j+38,i+28,j+50,i+54,j+62);
drawTriangle (i+56,j-2,i+28,j+10,i+56,j+22);
drawTriangle (i-16,j+38,i+12,j+50,i-16,j+62);

stroke (1);

}}

drawLines();
}

void drawTriangle (int a, int b, int p, int q, int x, int y) {

//this code allows us to create conditions for the triangles based on the relative values of //the vertices as represented by set pronumeral digits (a,b,p,q,x,y)

if (a%4 == 0) {
//so as the horizontal value of the first vertex is divisible by 4
//we can apply a certain condition- so a set number of triangles are a shade of grey //(representing the shark’s fin)
fill(noise(x / resolution, y / resolution) * 255)
;
} else {
fill(noise(a / resolution, b / resolution) * 255,
noise(p / resolution / 64, q/ resolution / 12) * 255,
noise(a / resolution / 120, x / resolution / 12) * 255);
//for every other triangle in the loop will be coloured a random shade varying
//according to the positions of the vertices, using perlin noise for a
//more subtle gradient

//various experimentations with this give a range of aqua-blue, flesh-tones or deep red (see below)
}
triangle (a,b,p,q,x,y);
//this applies the conditions as set throughout the function
}
void drawLines(){
for (int i =10 ; i < 650 ; i = i +80 ){
for (int j = 10 ; j < 650 ; j = j + 80){
//this refers to the rate at which the patterns are repeated:
//every 80 pixels horizontally or vertically a new loop begins

//lines set 1

//these lines are specially placed to go between the vertex of the interior triangles and a //certain point on the exterior triangles just a few pixels away.  It’s a repeated patter for //every triangle in order to complete the illusion.

//I’m looking for a way to code in a formula or set of conditions for the lines so they don’t //need to be plotted individually

line (i-16,j-2,i-20,j-4);
line (i-20,j-4,i-24,j-2);
line(i-26, j-12,i-26,j-20);
line(i-26,j-12,i-30,j-9);
line (i+16,j+18,i+20,j+15);
line (i+24,j-22,i+20,j-24);
line (i-16,j+38,i-20,j+35);
line(i-20,j+35,i-26,j+38);
line (i+16,j-23,i+20,j-25);
line (i+20,j-25,i+24,j-23);
line (i+54,j+38,i+54,j+43);
line (i+56,j-2,i+60,j-5);
line (i-16,j+38,i-20,j+35);
line (i-16,j+22,i-16,j+17);
line (i-12,j+30,i-16,j+27);
line(i-16,j+27,i-16,j+22);
line (i-24,j+22,i-24,j+27);
line (i-24,j+27,i-28,j+30);

line (i-12,j-10,i-16,j-13);
line (i-16,j-13,i-16,j-17);
line (i+12,j+10,i+16,j+7);
line(i+16,j+7,i+16,j+3);
line(i+24,j+7,i+24,j+3);
line(i+24,j+7,i+28,j+10);
line(i+24,j+18,i+20,j+14);
line(i+24,j+48,i+24,j+40);
line(i+16,j+48,i+16,j+40);
line(i+16,j+48,i+12,j+50);
}}}

Advertisements

One thought on “Javascript Sketches: SHARK VARIATIONS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s