-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPLOT1.js
More file actions
107 lines (74 loc) · 2.02 KB
/
Copy pathPLOT1.js
File metadata and controls
107 lines (74 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function setup() {
createCanvas(windowWidth, windowHeight);
//flag Variables
stretchScale = false;
doOffset = true;
//Global variables
dW = 1600;
dH = 900;
oW = 0; //widthOffset
oH = 0; //heightOffset
sW = 1; //widthScale
sH = 1; //heightScale
feedback = 0; //Feedback used in closed loops.
plotter = new Plotter(100, 100, dW - 200, dH - 200);
doScale();
}
function draw() {
//Apply scale
if (stretchScale) {
scale(sW, sH);
} else {
scale(min(sW,sH));
}
background(255);
//Generator function >> plotter INPuT >> plotter UPDaTe >> plotter DRAW
let x = frameCount/60;
let wave = "sin(PI*x)/(PI*x)";
//let wave = sin(x) - sin(2*x) * cos(x/7); //EXAMPLE 1
//let wave = "sin(x) - sin(2*x) * cos(x/7);"
//let wave = 10;
//let wave = sin(x);
//let wave = "abs(x % 4 - 2) + sin(x) - sin(2*x) * cos(x/7)";
wave = Function("x", "return " + wave + ";"); //Evaluate wave
let dataIn = wave(x);
plotter.inpt(dataIn);
//Snap data in plotter
if (true /*x < 10*/) {plotter.snap()};
//Update plotter
plotter.updt();
//Draw plotter - MUST ALWAYS HAPPEN
plotter.draw();
}
function doScale() {
//True workspace size is dW x dH px
sW = windowWidth/dW;
//console.log("sW = " + sW);
sH = windowHeight/dH;
//console.log("sH = " + sH);
//Calculate offsets to center the piece on the canvas
if (!stretchScale && doOffset) {
oW = (windowWidth - dW*min(sW,sH)) / min(sW,sH); //WTF OFFSET??
oW /= 2;
//console.log("oW = " + oW);
oH = (windowHeight - dH*min(sW,sH)) / min(sW,sH); //EXCUSE WTF??
oH /= 2;
//console.log("oH = " + oH);
}
plotter.setOffset(oW, oH);
return;
}
function mousePressed() {
if (this.stretchScale) {plotter.click(mouseX/sW, mouseY/sH);}
else {plotter.click(mouseX/min(sW,sH), mouseY/min(sW,sH));}
return;
}
function mouseMoved() {
if (this.stretchScale) {plotter.hover(mouseX/sW, mouseY/sH);}
else {plotter.hover(mouseX/min(sW,sH), mouseY/min(sW,sH));}
return;
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
doScale();
}