Project 06 – Abstract Clock

Big circles with no fills and rotation angles of small circles represent seconds.
-The top of the canvas displays the first 30 seconds,
-and the bottom displays the second 30 seconds.

The size of the small rotating circles represents minutes.
-The size of the main circle corresponds to the minutes.
-The greater the current minutes, the greater the size of the circles.

The fill color of the upper biggest circle represents hours.
-Each different hour represents a different fill color.

The stroke colors of the upper big circles represent day and night.
-During the day, the strokes are in the color of light yellow.
-During the night, the strokes are in the color blue.

P6

sketch
//Xinyi Du 
//15104 Section B
//xinyidu@andrew.cmu.edu
//Project-05

/*
Big circles with no fills and rotation angles of small circles represent seconds. 
Top of the canvas displays the first 30 seconds, 
and the bottom displays the second 30 seconds.

The size of the small rotating circles represent minutes.
The size of the main cirle correspond to the minutes. 
The greater the current minutes, the greater the size of the circles. 

The filled color of the upper biggest circle represent hours.
Each different hour represent a different filled color.

The strokes of the upper big circles represent day and night.
During the day, the strokes are in color of light yellow.
During the night, the strokes are in color if blue.
*/

function setup() {
    createCanvas(480, 450);
    frameRate(15);
}

function draw() {
    background(50);
    //set hour, minute, and second
    var hourN = hour();
    var minuteN = minute();
    var secondN = second();

    //To present seconds & hours:
    //draw the number of circles with no fill according to the seconds
    for (var s = 0; s<secondN; s++) {
        //if seconds less than 30, draw the circles on the top half of the canvas
        if (s < 30) { 
            //if during the day, stroke color light yellow
            if (hourN <= 18 & hourN >= 6) {
                var r = 255;
                var g = 243;
                var b = 178;
                stroke(r, g, b);
            //if during the night, stroke color blue
            } else {
                var r = 80;
                var g = 131;
                var b = 220;
                stroke(r, g, b);
            }
            //fill color represent hour
            Hcolor(hourN);
            //each circle with different diameter represent one second
            circle(width/2, -60, 650-(s*15));
        } 
        //if seconds more than 30, draw the circles on the bottom half of the canvas
        if (s >= 30) {
            //stroke color for the bottom half circles: gradually darkening white
            stroke(255-(s-30)*6);
            noFill();
            //each circle with different diameter represent one second
            circle(width/2, height+60, 650-((s-30)*15));
        } 
    }

    
    //To present seconds & minutes:
    for (var s = 0; s<secondN; s++) {
        stroke(255);
        //if seconds less than 30, rotate along the outermost stroke of the top half circles
        if (s < 30) {
            push();
            //tranlate the origin
            translate(width/2, -60);
            //polar coordinates
            var angle = 47+(secondN/60)*180;
            var x = (650/2) * cos(radians(angle));
            var y = (650/2) * sin(radians(angle));
            // fill the main circle that represent minutes with day color
            fill(r, g, b);
            stroke(r, g, b);
            //drew the smaller circles that rotate along the strokes of different circles
            //the size of the main cirle correspond to the minutes
            circle(x, y, minuteN);
            fill(100);
            //other smaller circles
            var x1 = (650/2-30) * cos(radians(angle-40));
            var y1 = (650/2-30) * sin(radians(angle-40));
            circle(x1, y1, minuteN-minuteN/3);
            var x2 = (650/2-60) * cos(radians(angle-20));
            var y2 = (650/2-60) * sin(radians(angle-20));
            circle(x2, y2, minuteN-minuteN/(2/3));
            var x3 = (650/2-90) * cos(radians(angle-70));
            var y3 = (650/2-90) * sin(radians(angle-70));
            circle(x3, y3, minuteN-minuteN/2);
            var x4 = (650/2-120) * cos(radians(angle-50));
            var y4 = (650/2-120) * sin(radians(angle-50));
            circle(x4, y4, minuteN-minuteN/1.5);
            pop();
        }
        //if seconds more than 30, rotate along the outermost stroke of the bottom half circles
        if (s >= 30) {
            push();
            //tranlate the origin
            translate(width/2, height+60);
            //polar coordinates
            var angle = 180+47+((secondN-30)/60)*180;
            var x = (650/2) * cos(radians(angle));
            var y = (650/2) * sin(radians(angle));
            // fill the main circle that represent minutes with day color
            fill(r, g, b);
            stroke(255);
            //drew the smaller circles that rotate along the strokes of different circles
            //the size of the main cirle correspond to the minutes
            circle(x, y, minuteN);
            fill(100);
            //other smaller circles
            var x1 = (650/2-30) * cos(radians(angle-40));
            var y1 = (650/2-30) * sin(radians(angle-40));
            circle(x1, y1, minuteN-minuteN/3);
            var x2 = (650/2-60) * cos(radians(angle-20));
            var y2 = (650/2-60) * sin(radians(angle-20));
            circle(x2, y2, minuteN-minuteN/(2/3));
            var x3 = (650/2-90) * cos(radians(angle-70));
            var y3 = (650/2-90) * sin(radians(angle-70));
            circle(x3, y3, minuteN-minuteN/2);
            var x4 = (650/2-120) * cos(radians(angle-50));
            var y4 = (650/2-120) * sin(radians(angle-50));
            circle(x4, y4, minuteN-minuteN/1.5);
            pop();
        }

    }

    //legend showing the color that respond to each hour
    for (i=0; i<24; i=i+1) {
            Hcolor(i)
            noStroke();
            circle(width-20, 12+i*18.5, 12, 12);      
    }
    for (i=23; i>=0; i=i-1) {
            Hcolor(i)
            noStroke();
            circle(20, height-12-i*18.5, 12, 12);   
    }
}

//To present hours:
//Fill each different hour with a different color:
function Hcolor(h) {
    if (h == 0) {
        fill(6, 24, 51);
    } else if (h == 1) {
        fill(10, 33, 62);
    } else if (h == 2) {
        fill(19, 54, 103);
    } else if (h == 3) {
        fill(22, 59, 98);
    } else if (h == 4) {
        fill(24, 64, 106);
    } else if (h == 5) {
        fill(28, 69, 101);
    } else if (h == 6) {
        fill(36, 83, 118);
    } else if (h == 7) {
        fill(57, 125, 155);
    } else if (h == 8) {
        fill(116, 186, 191);
    } else if (h == 9) {
        fill(190, 223, 198);
    } else if (h == 10) {
        fill(218, 223, 148);
    } else if (h == 11) {
        fill(240, 212, 124);
    } else if (h == 12) {
        fill(245, 194, 121);
    } else if (h == 13) {
        fill(242, 182, 107);
    } else if (h == 14) {
        fill(240, 167, 103);
    } else if (h == 15) {
        fill(229, 147, 89);
    } else if (h == 16) {
        fill(226, 124, 124);
    } else if (h == 17) {
        fill(199, 109, 136);
    } else if (h == 18) {
        fill(124, 68, 130);
    } else if (h == 19) {
        fill(72, 41, 121);
    } else if (h == 20) {
        fill(44, 28, 107);
    } else if (h == 21) {
        fill(33, 39, 97);
    } else if (h == 22) {
        fill(16, 24, 75);
    } else if (h == 23) {
        fill(6, 14, 60);
    } 
}






Looking Outwards 06: Randomness

https://www.artnome.com/news/2018/8/8/why-love-generative-art

Lillian Schwartz

Pixillation, photographic film stills

1970

The works by Lillian Schwartz can be considered an excellent example of the computational art that applies “randomness”. Lilian is one of the first groups of artists that started to use “computers” to help them generate artwork.

Using computer bases, the works show great randomness but high consistency. Each segment of the diagrams is different to a certain degree, but the overall effects created by the various elements form a very balanced composition. The use of black and white also creates great contrasts to make the geometric shapes more prominent, which are amazing examples of the use of figures and ground.

If take a closer look, you will find that the four pictures are somewhat correlated with each other. The top left can be considered the first version because the shapes are simpler and the forms are more regular–mainly the laying of white squares and black rectangles. The bottom left and bottom right can be considered the second version–the shapes are merging to form more complicated forms, with the bottom left looking more flat and neat and the bottom right looking more three-dimensional because of the overlaying of squares. The top right can be considered the later version because it looks like the designer is trying to make the forms of the merging parts of the squares more irregular and curved.

Project 06 – Abstract Clock – srauch

Here is my abstract clock. It’s a beach with tides: high tide is at noon and low tide is at midnight. The grass rustles in the breeze, and the beach is strewn with starfish and shells. It’s dark from 8 pm to 5am. Sunrise is from 6am to 7am, and sunset is from 7pm to 8pm.

sketch

//Sam Rauch, section B, srauch@andrew.cmu.edu, project 06: abstract clock
//this code creates a beach with a tide. High tide is at noon, and low tide is at midnight.
//the grass rustles in the sea breeze. it gets darker from 7pm 8 pm and lighter from 6 to 7am. 

var grasslength = []; //length of blades of grass
var sandspotX = []; //x position of specks in sand
var sandspotY = []; //y position of specks in sand
var waveY; //height of the tide
var waveShift; //amount the water's edge fluctuates by 
var daytime; //the time of day in minutes
var darkness; //amount of darkness it is

function setup() {
    createCanvas(400, 400);
    background(220);
    text("p5.js vers 0.9.0 test.", 10, 15);

    //initializing x position of specks in sand
    for (var i = 0; i < 50; i++){
        sandspotX[i] = random(0, width);
    }

    //initializing y position of specks in sand
    for (var i = 0; i < 50; i++){
        sandspotY[i] = random(200, 400);
    }

    frameRate(5);

    //creating y position of tide. High tide is at noon, low tide is at midnight
    daytime = hour()*60 + minute(); //time of day, in minutes
    if (daytime < 690) { //if before noon
        waveY = map(daytime, 0, 690, 400, 200); //before noon, wave gets higher with time
    } else { //if after noon
        waveY = map(daytime, 690, 1380, 200, 400); //after noon, wave gets lower with time
    }

    //making it get lighter and darker at sunrise and sunset
    if (daytime >= 300 & daytime < 360) { //if from 5 to 6 am, it gets lighter
        darkness = map(daytime, 300, 360, 120, 0);
    } else if (daytime >= 1140 & daytime < 1200) { //from 7 to 8 pm, it gets darker
        darkness = map(daytime, 1140, 1200, 0, 120);
    } else if (daytime >= 360 & daytime < 1140) { //in the middle of the day, it's not dark
        darkness = 0;
    } else { //in the middle of the night, it's dark
        darkness = 120;
    }
}

function draw() {
    noStroke();
    background(155, 207, 207);

    //row of grass bunches
    for (var i = 0; i <2; i++){
        for(var j = 0; j<=width; j += 20) {
        grass(j, 220);
        }
    }
    
    //sand
    fill(196, 178, 122);
    rect(0, 200, width, 200);

    //little specks in sand
    strokeWeight(3);
    stroke(146, 128, 72)
    for (var i = 0; i<50; i++){
        point(sandspotX[i], sandspotY[i]);
    }
    noStroke();

    //assorted shells and starfish
    starfish(250, 250, color(120, 130, 120), 10);
    starfish(50, 340, color(50, 74, 64), 50);
    starfish(180, 370, color(120, 79, 97), 5);
    shell(140, 260, color(60, 50, 70), color(100, 80, 107), 60);
    shell(300, 300, color(80, 50, 50), color(120, 80, 97), -5);

    //waves
    waveShift = randomGaussian(1, 2);
    fill(30, 100, 155, 240);
    rect(0, waveY+waveShift, width, 300);
    fill(30, 100, 155, 100);
    rect(0, waveY-(random(1,3))+waveShift, width, 300);

    //rectangle that makes darkness and lightness of environment using alpha channel
    blendMode(MULTIPLY);
    fill(35, 50, 70, darkness);
    rect(0,0,width,height);
    blendMode(BLEND);
}

//makes starfish
function starfish(x,y, color, spin){
    push();
    translate(x,y);
    rotate(radians(spin));
    strokeWeight(4);
    stroke(color);
    for (var i = 0; i<5; i++){ //draw five arms from 0,0, rotating after each one
        line(0,0,0,-10);
        rotate(radians(72));
    }
    noStroke();
    pop();
}

//makes seashells
function shell(x,y, color1, color2, spin) {
    push();
    translate(x,y);
    rotate(radians(spin));
    strokeWeight(1);
    stroke(color1);
    fill(color2);

    var radius = 7; //radius of seashell, ie distance from circles to center
    var size = 12; //size of circles themselves
    var angle = radians(0); //theta of circle location
    for (var i = 0; i<20; i++) { //draw circles that get smaller as they get closer to the center
        ellipse ( cos(angle)*radius, sin(angle)*radius, size);
        angle-=radians(24);
        size -= i/20; //decrease size of circles
        radius -= i/30; //decrease radius of seashell       
    }
    noStroke();
    pop();
}

//makes a bunch of grass
function grass(x,y){
    push();
    translate(x,y);
    stroke(65, 100, 52);
    strokeWeight(2);
    rotate(radians(-40));
    for (var i = 0; i < 20; i++){ //creating each blade of grass in a bunch
        for (var j = 0; j < 20; j++){ //creating random lengths for each blade of grass
            grasslength[j] = random(35, 40);
        }
        line(0,0,0, -1*grasslength[i]);
        rotate(radians(4));
    }

    pop();
}

Looking Outward – 06

John Cage had this exhibition in Cambridge. He was known for his different kinds of music and his 1952 composition in which his music was so random. He also used randomness in his hard and it determined his entire exhibition from which stones were chosen to what would be painted around the stones. He also used computer generated coordinates to determine the heights and positions of the pictures while also using a random process to add and remove different pieces during the exhibition as well!

This is important because it starts talking about how certain artists can afford to give up control so he uses computation as a way to make “no mistakes”. Everything has a purpose even if its randomness.

Sometimes randomization also came from solutions. This stained glass window was actually created as a solution to a Sudoku puzzle. So, broken down by row and column, it’s solutions defined the color and types of the stained window.

https://understandinguncertainty.org/node/1066

Looking Outwards 06

This project is a version of the set algorithm where the color of each triangle gradually changes according to when it was created. The color changes gradually from white to black, then flips instantly back to white again. According to the artist, this was originally just an accident, but somehow it turns into this cool piece with three dimensional illusion. I admire this piece of work because seems random upon first glance but it creates this overall beautiful organic pattern. It started by his other project “Differential Lines” and from that he moved on to this 3D algorithm. The key thing to get this to work is to have the mesh do various self-balancing operations as it grows. From this project, I learned that randomness exist by following certain rules, for example, this project was following rules like

  • Split edges that are too long.
  • Avoid inserting new vertices where the vertex density is too high.
  • Flip edges to reduce the length of the edge.
  • Add a force that makes the triangles attempt to be roughly equilateral.

When randomness is in balance, art is created.

Different Meshes” by Anders Hoff

Project 06: Abstract-Clock

For this project, the inner circle represents every second, the outer circle shows the seconds turning to minutes, the different colored rays of the “sun” show the different minutes, and the pink background shows the number of hours in the day!

sketch
function setup() {
    createCanvas(350, 350);
    background(173, 216, 230);
}

function draw() {
    background(173, 216, 230);
    hoursBackground();
    minutesCircle();
    secondsCircle();
}

function hoursBackground() { //creates pink rectangles every hour
    push();
    for(var i = 0; i < hour(); i++) {
        strokeWeight(0.1);
        fill(243, 196, 207);
        rect(0,0, width/24, height);
        translate(width/24,0);
    }
    pop();
}

function minutesCircle() { //every minute, a new ray appears coming out of the inner circle
    push();
    strokeWeight(11);
    translate(width/2, height/2);
    for (var i = 0; i < minute(); i ++) {
        angleMode(DEGREES);
        if(i % 2 == 0) { //if i mod 2 is 0, then a short yellow line is drawn
            stroke(253, 253, 150, 200);
            line(0,0, 0, -100);
            rotate(6);
        }else{ // else a long orange line is drawn
            stroke(255, 179, 71, 200);
            line(0,0, 0, -125);
            rotate(6);
        }   
    }
    pop();
}

function secondsCircle() {
        fill(173, 216, 230); //creates inner blue circle
        strokeWeight(0.1);
        circle(width/2, height/2, 40);

        strokeWeight(10); //creates outer white circle that counts 60 seconds in a minute
        stroke(255);
        noFill();
        arc(width/2, height/2, 250, 250, 270, 270 + second()*6);

        strokeWeight(1); // creates inner circle that visually shows every second
        fill(255);
        arc(width/2, height/2, 30, 30, 270, 270 + millis()*0.36);
}

Project 06 Abstract Clock

The way time is tracked in this piece of design is by having the little blue fish tracking seconds, the little pink fish tracking minutes, and the rainbow tracking hours. So the blue fish moves right a bit every second and when the minute increases the pink fish moves right. the rainbow goes from red to blue every hour and it restarts from red again when the full rainbow is done.

sketch
//Jenny Wang
//Section B
//jiayiw3@andrew.cmu.edu
//Project 06 Abstract Clock

//set variables
var H;//hour
var M;//min
var S;//sec
var bx;//blue fish x
var px;//piink fish x

function setup() {
    createCanvas(480, 400);
    background(255);

} 

function draw() {
    background(199,137,201);//purple
    
    //current time
    H = hour();
    M = minute();
    S = second();

    //rainbow (hour)
    if(H == 6 || H == 12 || H==18 || H==24){
        noStroke();
        fill(122,153,229);//blue
        ellipse(240,140,560,470)
        fill(131,226,210);//teal
        ellipse(240,140,480,390);
        fill(151,226,134);//green
        ellipse(240,140,400,310);
        fill(239,232,101);//yellow
        ellipse(240,140,320,230);
        fill(229,156,90);//orange
        ellipse(240,140,240,150);
        fill(247,129,87);//red
        ellipse(240,140,160,70);
    }
    else if(H == 5 || H == 11 || H==17 || H==23){
        noStroke();
        fill(131,226,210);//teal
        ellipse(240,140,480,390);
        fill(151,226,134);//green
        ellipse(240,140,400,310);
        fill(239,232,101);//yellow
        ellipse(240,140,320,230);
        fill(229,156,90);//orange
        ellipse(240,140,240,150);
        fill(247,129,87);//red
        ellipse(240,140,160,70);
    }
    else if(H == 4 || H == 10 || H== 16 || H== 22){
        noStroke();
        fill(151,226,134);//green
        ellipse(240,140,400,310);
        fill(239,232,101);//yellow
        ellipse(240,140,320,230);
        fill(229,156,90);//orange
        ellipse(240,140,240,150);
        fill(247,129,87);//red
        ellipse(240,140,160,70);
    }

    else if(H == 3 || H == 9 || H== 15 || H== 21){
        noStroke();
        fill(239,232,101);//yellow
        ellipse(240,140,320,230);
        fill(229,156,90);//orange
        ellipse(240,140,240,150);
        fill(247,129,87);//red
        ellipse(240,140,160,70);
    }

    else if(H == 2 || H == 8 || H== 14 || H== 20){
        noStroke();
        fill(229,156,90);//orange
        ellipse(240,140,240,150);
        fill(247,129,87);//red
        ellipse(240,140,160,70);
    }

    else if(H == 1 || H == 7 || H== 13 || H== 19){
        noStroke();
        fill(247,129,87);//red
        ellipse(240,140,160,70);
    }

    //ocean
    fill(198,230,227);
    rect(0,132,480,351);

    //bluefish(sec)
    bx = width/59;
    bluefish(S*bx,height/2);

    //pink fish(min)
    px = width/59
    pinkfish(M*px,3*height/4);
}
 
function bluefish(x,y){
    //tail
    fill(44,170,213);
    triangle(x-38,y+13,x-38,y-13,x,y);
    //fin on top and bottom
    fill(144,214,235);
    triangle(x+5,y-17,x-10,y-23,x-10,y+10);
    //body
    fill(44,170,213);
    ellipse(x,y,55,34);
    //fin
    fill(144,214,235);
    triangle(x-15,y-6,x-15,y+6,x,y-2);
    //head
    fill(144,214,235);
    ellipse(x+16,y,23,27);
    //eye
    fill(73,64,24);
    ellipse(x+15,y-3,5,5);
    fill("white");
    ellipse(x+14,y-4,2,2);
    //smile
    stroke(73,64,24);
    strokeWeight(1);
    point(x+19,y+6);
    point(x+20,y+6.5);
    point(x+21,y+7);
    point(x+22,y+7.3);
    point(x+23,y+7);
    point(x+24,y+6.5);
}

function pinkfish(x,y){
    //tail
    noStroke();
    fill(193,82,144);//dark pink
    triangle(x-38,y+13,x-38,y-13,x,y);
    //fin on top and bottom
    fill(233,171,205);//light pink
    triangle(x+5,y-17,x-10,y-23,x-10,y+10);
    //body
    fill(193,82,144);
    ellipse(x,y,55,34);
    //fin
    fill(233,171,205);
    triangle(x-15,y-6,x-15,y+6,x,y-2);
    //head
    fill(233,171,205);
    ellipse(x+16,y,23,27);
    //eye
    fill(73,64,24);
    ellipse(x+15,y-3,5,5);
    fill("white");
    ellipse(x+14,y-4,2,2);
    //smile
    stroke(73,64,24);
    strokeWeight(1);
    point(x+19,y+6);
    point(x+20,y+6.5);
    point(x+21,y+7);
    point(x+22,y+7.3);
    point(x+23,y+7);
    point(x+24,y+6.5);
}

LO: 06

When thinking about randomness, my mind went straight to Dada, specifically Dada poetry. So much of Dada itself is left up to chance: the process, the reaction, the viewer, the artist: this is especially true with Dada poetry. Paradoxically, Dada poetry often both gave instruction on how to create Dada art while considered a piece of Dada art itself. Tristan Tzara’s 1920 To Make a Dadaist Poem is a great example:

“Pick up a newspaper.

Take some scissors.

Choose in the newspaper an article of length that tells you to give your poem.

Cut out the item.

Carefully cut out each of the words that make up the item carefully and put them in a bag.

Shake gently.

Now pull each cutting one after another.

Copy conscientiously

In the order they have left the bag.

The poem will resemble you.

And you are an infinitely original writer and a bewitching sensibility, although misunderstood by the vulgar.”

There is obvious randomness in the actions described: random newspaper, random words, random order. But Tzara’s call to action is also given to a random artist. This serves the Dada goal of nonmeaning well. I have also been considering the fact that Dada poetry that prompts viewer response is similar in a lot of ways to programming. Obviously there are differences, but the fact that one is given a list of instructions to follow, usually phrased particularly does connect the two in my mind.

excerpt of Dada poetry

Project 06

For my abstract clock, the day/night period is from 7 am to 7 pm & vice versa. This means that the sun rises & sets at 7 am & 7 pm, respectively. The number of stars displayed on screen references what minute it is, and one complete rotation of a star = 1 minute. The half-circle path that the sun/moon takes can be used to tell the hour.

sketch
//Lily van Veen, section B, lvanveen@andrew.cmu.edu, project 6
var r; //red value
var g; //green value
var b; //blue value
var h; //hour
var m; //min
var s; //sec
var x = []; //x value of top point of stars
var y = []; //y value of top point of stars
var t = 0; // rotation/turn of stars

function setup() {
	frameRate(30);
    createCanvas(480, 480);
    background(235, 205, 124);
    for(var i = 0; i < 60; i++){ 
    	x[i] = random(30, width-30);
    	y[i] = random(30, height-240);
    }
}

function draw() {
	let h = hour();
    let m = minute();
    let s = second();
	if(h > 7 & h < 19){ //"sunrise" and "sunset" will happen @ 7 am & 7 pm respectively
    	r = 235; //yellow
    	g = 205;
    	b = 124;
    	background(r, g, b);
    }else if(h < 7 || h > 19){
    	r = 48; //blue
    	g = 68;
    	b = 133;
    	background(r, g, b);
    }else if(h == 7){
    	r += .01; // w/ .01 change in color @ 30 fps, will take abt 2 min to fully shift from day to night (also about the same time a sunset/sunrise takes :) )
    	g += .01;
    	b -= .01;
    	background(min(r, 235), min(r, 205), max(b, 124));
    }else if(h == 19){
    	r -= .01;
    	g -= .01;
    	b += .01;
    	background(max(r, 48), max(g, 68), min(b, 133));
    }

    for(var i = 0; i < m; i++){ // i is used to count the # of minutes; this is the section to draw the star - initally was going to put this under a function called drawStar(); but didn't function properly
    	push();
        translate(x[i], y[i]);
        rotate(radians(s*6));
    	fill(255, 249, 201); //light yellow
	    strokeWeight(0);
	    triangle(0, -5, -5, 5, 5, 5);
	    triangle(-5, 5, -7.5, 10, 0, 7.5);
	    triangle(5, 5, 7.5, 10, 0, 7.5);
	    triangle(0, 7.5, -5, 5, 5, 5);
	    triangle(-5, 5, -10, 0, 0, 0);
	    triangle(5, 5, 10, 0, 0, 0);
	    pop();
    }
    	push(); //creates path of sun to better indicate hour of the day, "sun" visible from 7 am -> 7 pm
    	translate(240, 480);
    	rotate(radians((((h-7)*60)+m)*(360/1440)));
    	strokeWeight(0);
    	fill(255, 248, 189);
    	ellipse(-215, 0, 50, 50);
    	pop();

    	push(); //creates path of sun to better indicate hour of the day, "sun" visible from 7 pm -> 7 am
    	translate(240, 480);
    	rotate(radians((((h-7)*60)+m)*(360/1440)+180));
    	strokeWeight(0);
    	fill(255, 248, 189);
    	ellipse(-215, 0, 50, 50); //so the ellipse to carve out moon shape is the same as bg :)
    	if(h > 7 & h < 19){ //"sunrise" and "sunset" will happen @ 7 am & 7 pm respectively
      	    r = 235;

Project: 06 – Abstract Clock

Crop Circles

I was inspired by crop circles for my clock. Each node is one hour in a day. The crops in the background grow with the mouse.

Sketch
sketch
/* Evan Stuhlfire
** estuhlfi@andrew.cmu.edu, section B
** Project 06: Abstract Clock  */

var r = 90; // radius of center circle, noon
var deg = 360; // degrees in a circle
var nodeCount = 24; // 24 hours, each node is one hour
var c = []; // color array
var x = []; // x position of circle
var theta = []; //angle
var size = []; // diam of the circles
var defaultColor;
var tempSize = 0; // allows the nodes to grow with time
var pSize = 25;

function setup() {
    createCanvas(480, 480);
    background(127, 198, 164);
    fillArray(); // fill arrays with start values

}

function draw() {
    var thetaRotate = 40; // canvas rotation

    background(127, 198, 164);
    drawCrops();

    // build color array
    buildColorArray();

    stroke(93, 115, 126);
    // settings to draw circles (nodes)
    push(); // save settings
    translate(width/2, height/2); // reset origin to center
    rotate(radians(thetaRotate)); // rotate canvas to draw at an angle

    // call function to draw the nodes
    drawNodes();
    pop(); // restore settings

    // make crops reactive to mouse location and time
    pSize = mouseX/hour();
}

function drawCrops() {
    var rows = width/30;
    var cols = height/30;
    var incr = width/16;
    
    var s1 = width/16;
    var s2 = height/16;
    var len = pSize;
    var a = len/4; 

    // loop over double for loop to add colums and rows of crops
    for(var i = 0; i < rows; i++) {
        for(var j = 0; j < cols; j++) {
            push();
            translate(s1/2, s2/2);
            drawOne(len, a); 
            pop();
            s2 += 2 * incr;
        }
        s1 += 2 * incr;
        s2 = incr;
    }
}

function drawOne(len, a) {
    // function to draw on plant for crops
    stroke(93, 115, 126, 60);
    line(0, -a, 0, len);
    line(-a, -a, 0, len/2);
    line(a, -a, 0, len/2);
}

function buildColorArray() {
    // set the default color
    defaultColor = color(242, 245, 234);

    // fill array with colors
    for(var i = 0; i < x.length; i++){
        if(i < 3) {
            c[i] = color(93, 115, 126);    
        } else if(i < 6) {
            c[i] = color(118, 129, 179);
        } else if(i < 9) {
            c[i] = color(214, 248, 214);
        } else if(i < 11) {
            c[i] = color(163, 213, 255);
        } else if(i < 14) {
            c[i] = color(250, 243, 62);
        } else if (i < 16) {
            c[i] = color(163, 213, 255);
        } else if (i < 19) {
            c[i] = color(214, 248, 214);
        } else if (i < 22) {
            c[i] = color(118, 129, 179);
        } else if (i < 25) {
            c[i] = color(93, 115, 126)
        }
    }
}

function fillArray() {
    var angle = 30; // nodes are positioned 30 degrees apart
    var angle2 = 150; // starting point for second set of nodes
    var dist = 65; // nodes begin at dist from center
    var offset = 1.2 // distance offset 
    var offset2 = .8 
    var minSize = 15; // can be no smaller than minSize

    // fill arrays with start values
    x.push((-deg/2) + 10);
    theta.push(180);
    size.push(r * offset2); // 80% size of center

    // fill array with first 12 nodes
    for(var i = 1; i < nodeCount/2; i++) {
        x[i] = dist;
        theta[i] = angle * i;
        size[i] = max(r * i/18, minSize);

        dist = dist + i * offset;
    }

    // push center circle into array
    x.push(deg/2 - 10);
    theta.push(0);
    size.push(r);

    dist = dist - i * offset; // undo last dist calc
    // fill array with last 12 nodes
    // loop backward so that decreasing i can be used to decrease size
    for(i = x.length; i > 2; i--) {
        x.push(dist);
        theta.push(angle2);
        size.push(max(r * i/22, minSize));

        dist = dist - i * offset2;
        angle2 -= angle;
    }

    // push last circle into array, midnight
    x.push(0);
    theta.push(0);
    size.push(r * offset2); // 80% size of center
}

function drawNodes() {
    var h = hour();
 
    stroke(93, 115, 126);
    // draw line behind center node so that it is behind
    line(0, 0, deg/2, 0);

    // draw the satellite nodes
    push();

    translate(x[0], 0); // reset origin to top circle
    loopAndDraw(0, x.length/2, h);

    // draw top midnight circle
    fill(c[0]);
    circle(0, 0, r * .8);
    pop();

    push();
    translate((deg/2) -10, 0);
    loopAndDraw(int(x.length/2) + 1, x.length, h);

    pop();
}

function loopAndDraw(start, end, h) {
    var dx;
    var dy;
    var current = false; // identify the current node

    // iterate over arrays
    for(var i = start; i < end; i++) {
        dx = x[i] * cos(radians(theta[i]));
        dy = x[i] * sin(radians(theta[i]));

        // midnight
        if(h == 0) {
            h = 24;
        }
        // if the hour has passed or is the current hour use fill
        if(i < h){
            fill(c[i]);
        } else if (i == h) {
            current = true;
            fill(c[i]);
        } else {
            fill(defaultColor);
        }

        stroke(93, 115, 126);
        line(0, 0, dx, dy);
        circle(dx, dy, size[i]);

        if(current) {
            currentHour(i, dx, dy);
        }

        current = false;
    }
}

function currentHour(i, dx, dy) {
    // add time elements to nodes to track time
    // subtract to adjust for rotation of canvas
    var s = second() * 6 - 140;
    var m = minute() * 6 - 140;
    var h = hour() * 30 + minute()/2 - 140; 

    fill(c[i]); // use the color stored in the array
    push();
    translate(dx, dy);
    // make current circle bigger
    tempSize = size[i] * 1.32;
    circle(0, 0, tempSize);

    // have a second hand orbit the current hour
    if(i > 3 & i < 23) {
        fill(c[i - 3]); //use previous color.
    } else {
        fill(defaultColor);
    }
    // mark hours
    var hx = size[i] * .6 * cos(radians(h));
    var hy = size[i] * .6 * sin(radians(h));
    circle(hx, hy, tempSize * .25);

    // mark minutes
    var mx = size[i] * .3 * cos(radians(m));
    var my = size[i] * .3 * sin(radians(m));
    
    circle(mx, my, tempSize * .2);

    // mark seconds
    var armX = size[i] * .55 * cos(radians(s));
    var armY = size[i] * .55 * sin(radians(s));
    strokeWeight(1);
    circle(armX, armY, tempSize * .15);
    pop();
}