Hi there, i am trying to make a clock that displays time in an abstract way,
I want to use sine waves that resemble seconds,minutes,hours,day,month,year. I wanted to display this via various frequencies.
I found following code from the processing website
int xspacing = 16; // How far apart should each horizontal location be spaced
int w; // Width of entire wave
float theta = 0.0; // Start angle at 0
float amplitude = 75.0; // Height of wave
float period = 500.0; // How many pixels before the wave repeats
float dx; // Value for incrementing X, a function of period and xspacing
float[] yvalues; // Using an array to store height values for the wave
void setup() {
size(640, 360);
w = width+16;
dx = (TWO_PI / period) * xspacing;
yvalues = new float[w/xspacing];
}
void draw() {
background(0);
calcWave();
renderWave();
}
void calcWave() {
// Increment theta (try different values for 'angular velocity' here
theta += 0.02;
// For every x value, calculate a y value with sine function
float x = theta;
for (int i = 0; i < yvalues.length; i++) {
yvalues[i] = sin(x)*amplitude;
x+=dx;
}
}
void renderWave() {
noStroke();
fill(255);
// A simple way to draw the wave with an ellipse at each location
for (int x = 0; x < yvalues.length; x++) {
ellipse(x*xspacing, height/2+yvalues[x], 16, 16);
}
}
Thats my current version
//Second
int xspacing = 1;
int w;
float theta = 0;
float amplitude = 100.0;
float period = 500;
float dx;
float[] yvalues;
//MINUTE
int Mxspacing = 1;
int Mw;
float Mtheta = 0;
float Mamplitude = 100.0;
float Mperiod = 500;
float Mdx;
float[] Myvalues;
//hour
int Hxspacing = 1;
int Hw;
float Htheta = 0;
float Hamplitude = 100.0;
float Hperiod = 500;
float Hdx;
float[] Hyvalues;
void setup() {
size(860, 540);
w = width;
dx = (TWO_PI / period) * xspacing;
yvalues = new float[w/xspacing];
Mw = width;
Mdx = (TWO_PI / Mperiod) * Mxspacing;
Myvalues = new float[Mw/Mxspacing];
Hw = width;
Hdx = (TWO_PI / Hperiod) * Hxspacing;
Hyvalues = new float[Hw/Hxspacing];
frameRate(millis());
}
void draw() {
background(0);
calcWave();
renderWave();
McalcWave();
MrenderWave();
HcalcWave();
HrenderWave();
}
void calcWave() { // Second
theta += 6.2832 ;
float x = theta;
for (int i = 0; i < yvalues.length; i++) {
yvalues[i] = sin(x)*amplitude;
x+=dx;
}
}
void McalcWave() { // Minute
Mtheta += 0.1047197551;
float Mx = Mtheta;
for (int s = 0; s < Myvalues.length; s++) {
Myvalues[s] = sin(Mx)*Mamplitude;
Mx+=Mdx;
}
}
void HcalcWave() { //Hour
Htheta += 0.0017453293;
float Hx = Htheta;
for (int H = 0; H < Hyvalues.length; H++) {
Hyvalues[H] = sin(Hx)*Hamplitude;
Hx+=Hdx;
}
}
void renderWave() {
strokeWeight(1);
stroke(255);
for (int x = 0; x < yvalues.length; x++) {
ellipse(x*xspacing, height/2+yvalues[x], 16, 16);
}
}
void MrenderWave() {
strokeWeight(1);
stroke(255);
for (int Mx = 0; Mx < Myvalues.length; Mx++) {
ellipse(Mx*Mxspacing, height/2+Myvalues[Mx], 16, 16);
}
}
void HrenderWave() {
strokeWeight(1);
stroke(255);
for (int Hx = 0; Hx < Hyvalues.length; Hx++) {
ellipse(Hx*Hxspacing, height/2+Hyvalues[Hx], 16, 16);
}
}
But i really cant figure how to archive those various frequencies
I tried to calculate my needed angle-velocity for lets say 1second / 1 Hertz. and put those values into “theta” (line 25; source code)
360° degree in 1 sec = 6.28318530718 radians per second… and so forth
this didnt work…
I’d really appreciate any help