/*
* Name: Parametric Equations
* Author: Mark Schnabel
* Version: 1.0
*
* Reference Video: https://www.youtube.com/watch?v=LaarVR1AOvs
*/
float t = 0;
static final int NUM_TRAILS = 15;
// Initializes the height, width and background color of the window
void setup() {
size(600, 600);
background(0);
}
// Main draw loop of the program
void draw() {
// Erases drawing from previous iteration so the new drawing can be drawn over it
background(0);
stroke(255);
strokeWeight(2);
// Sets starting point for any line or point that will be drawn to be at the center of the screen
translate(width/2, height/2);
/* Loop is used to draw the sequence of trailing lines/dots for the sketch.
* The number of trailing lines/dots is set by the constant NUM_TRAILS above
* The loop works by drawing lines and points at the coordinates generated by the x1, y1, x2, and y2 functions below.
* The counter variable i is used to seperate the lines from the one drawn the prior iteration of the for loop by incrementing
* the x and y values produced by the functions below with the current value of t.
* This addition and subtraction offsets each line or point's x,y values by 1 in order to create the trailing effect displayed in the running program.
*/
for(int i = 0; i < NUM_TRAILS; i++) {
line(x1(t - i), y1(t - i), x2(t - i), y2(t - i));
line(y1(t - i), x1(t - i), y2(t - i), x2(t - i));
point(x2(t + i), y2(t + i));
point(y2(t + i), x2(t + i));
}
// t is TODO incremented to continuosly alter the x and y output of the equations
t += 0.65;
}
/* Using trigonomic functions below such as sin() and cos() is what allows for the wave like patterns to be drawn by the program
* sin() and cos() functions are layered on top of one another to produce interesting effects
*
* The coefficient inside of a sin() or cos() function is what will alter the frequency of the lines drawn
* For example: In the function "x1" below sin(t / 10), t / 10 is what determines the frequency of lines drawn or the wave
* Dividing t by 10 lowers the frequency from what sin(t) would be, however if you were to multiply t by 10 the frequency would increase
*
* The coeffcient outside of a sin() or cos() function is what will alter the amplitude of a wave
* For example: In the function "x1" below * 100 is what determines the amplitude of lines drawn or the wave
* Multiplying sin(t / 10) by 100 as done below increases the amplitude, but if you were to divide by 100 that would decrease the amplitude
*
* Playing with the equations will produce wildly different resukts
*/
// values returned by x1 and y1 are used to draw the lines of the sketch
float x1(float t) {
return sin(t / 10) * 100 + sin(t / 5) * 20;
}
float y1(float t) {
return cos(t / 10) * 100;
}
// values returned by x2 and y2 are used to return the dots of the sketch
float x2(float t) {
return cos(t / 10) * 200 + sin(t) * 2;
}
float y2(float t) {
return sin(t / 90) * 200 + cos(t / 12) * 20;
}