-
Notifications
You must be signed in to change notification settings - Fork 1
/
drawCircle.ts
103 lines (82 loc) · 2.21 KB
/
drawCircle.ts
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
import { postError, atSketch } from './jsCommon';
inlets = 2;
outlets = 0;
var seqReal: number[] = [];
var seqImg: number[] = [];
function list() {
switch (inlet) {
case 0:
seqReal = arrayfromargs(arguments);
break;
case 1:
seqImg = arrayfromargs(arguments);
break;
}
bang();
}
function bang() {
draw();
refresh();
}
function hsvToRgb(h: number, s: number, v: number) {
var r, g, b;
var i = Math.floor(h * 6);
var f = h * 6 - i;
var p = v * (1 - s);
var q = v * (1 - f * s);
var t = v * (1 - (1 - f) * s);
switch (i % 6) {
case 0: r = v, g = t, b = p; break;
case 1: r = q, g = v, b = p; break;
case 2: r = p, g = v, b = t; break;
case 3: r = p, g = q, b = v; break;
case 4: r = t, g = p, b = v; break;
case 5: r = v, g = p, b = q; break;
default: throw "impossible";
}
return [r, g, b];
}
function draw() {
let len = seqReal.length;
atSketch($ => {
$.glscale(1.8, 1.8);
$.gltranslate(-0.5, -0.5);
// set how the polygons are rendered
$.glclearcolor(vbrgb[0], vbrgb[1], vbrgb[2], vbrgb[3]) // set the clear color
$.glclear() // erase the background
$.gllinewidth(5);
$.moveto(seqReal[len - 1], seqImg[len - 1])
$.glcolor(0, 0, 0, 0.7)
for (
let i = 0;
i < seqReal.length;
i++ // iterate through the columns
) {
$.lineto(seqReal[i], seqImg[i]);
}
$.gllinewidth(2);
$.moveto(seqReal[len - 1], seqImg[len - 1])
for (
let i = 0;
i < seqReal.length;
i++ // iterate through the columns
) {
const [r, g, b] = hsvToRgb(0.83 - ((0.83 - 0.5) * (i / seqReal.length)), 1, 0.9)
$.glcolor(r, g, b, 1)
$.lineto(seqReal[i], seqImg[i]);
}
});
}
var vbrgb = [0, 0, 0, 0];
var vfrgb = [0.118, 0.118, 0.118, 1.000];
try {
// set up jsui defaults to 2d
sketch.default2d();
// initialize graphics
draw();
refresh();
} catch (e) {
postError(e, "Error initializing drawCircle");
}
let module = {};
export = {};