xxxxxxxxxx
115
// Student name : Alex Wang
//Professor : Xin Xin
//Code 1.A.Fa19
// This project acts as a direct visulizer of how much time you still have in a day.
// Achieved by 'for' loop, and 'noise' function.
let x = 0;
let y = 0;
let Mt = 0;
let Mh = 0;
function setup() {
createCanvas(600, 600);
}
function draw() {
background(0);
//Reference of time.
let dy = day();
let hr = hour();
let mn = minute();
let sc = second();
stroke(255);
strokeWeight(0.5);
// The formation of the topper outline of the eye.
// The intensity of the 'cross-sketching' depends on the day in a Month.
for (let x = 0; x < width; x = x + dy + 1)
{
let w = random(-10, 0);
let h = random(600, 610);
line(x, w, h, x);
}
for (let y = 0; y < height; y = y + dy + 1) {
let w = random(-10, 0);
let h = random(600, 610);
line(w, y, y, h);
}
//Center everything in the middle.
translate(width / 2, height / 2)
// I use loop function to draw a circle, then I randomiz the radius of the circle. As the value of 'a +=' is 0,2, that means the circle is divided into 2Pi/0.2 segments. If the radius are randomized, there are spikes created.
stroke(255);
strokeWeight(1);
noFill();
beginShape();
for (let a = 0; a < (sc + 1) * TWO_PI / 60; a += 0.2) {
let r = random(270 - sc, 150);
//let r= 100;
x = r * -sin(a);
y = r * -cos(a);
vertex(x, y);
}
endShape();
// Here I introduced a noise function to replace the 'random' function that I used before. They behave similiarly, but the spikes looks more fluent in the simulation of the minute pointer of a clock.
stroke(255);
strokeWeight(2);
noFill();
beginShape();
for (let a = 0; a < (mn - 1) * TWO_PI / 60; a += 0.1) {
//let r= random(200-mn,100);
let r = map(noise(a + Mt), 0, 1, 100, 200)
//let r= 100;
x = r * -sin(a);
y = r * -cos(a);
vertex(x, y);
// This is the offset of the noise value.
Mt += 0.1;
}
endShape();
stroke(255);
strokeWeight(15);
noFill();
beginShape();
for (let a = 0; a < (hr + 1) * TWO_PI / 24; a += 0.1) {
let r = map(noise(a + Mh), 0, 1, 0, 220);
//let r= 100;
x = r * -sin(a);
y = r * -cos(a);
vertex(x, y);
Mh += 0.8;
}
endShape();
}