«tri-o emulation» by grirgz

on 29 Mar'15 19:17 in geometrycontroller

I just saw this controller https://gaojiafeng.wordpress.com/2014/02/11/tri-o-2014/, not a bad idea, but no need to have real rotating discs ;) Adapting this code for use with a regular midi controller should be fairly easy

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
(
var w, h = 700, v = 700, run = true;
var starttime = TempoClock.default.beats;
w = Window("trio", Rect(40, 40, h, v), false);
w.onClose = { run = false }; // stop the thread on close
w.front;

w.drawFunc = {
    Pen.width = 2;
    Pen.use {
		var time = TempoClock.default.beats - starttime;
		var x1, y1; // coordinates of rotating point 1
		var r1 = 100; // radius
		var ox1 = 500; // disc center
		var oy1 = 500;
		var f1 = 1; // rotation frequency

		var x2, y2;
		var r2 = 100;
		var ox2 = 200;
		var oy2 = 500;
		var f2 = 1/2;

		var x3, y3;
		var r3 = 100;
		var ox3 = 300;
		var oy3 = 300;
		var f3 = 1/3;

		var o1, o2, o3;
		var p1, p2, p3;

		var l1, l2, l3;
		var perimeter, area;
		var angle1, angle2, angle3;

		o1 = Point(ox1,oy1);
		o2 = Point(ox2,oy2);
		o3 = Point(ox3,oy3);

		x1 = r1 * sin(2*pi*f1*time) + ox1;
		y1 = r1 * cos(2*pi*f1*time) + oy1;

		x2 = r2 * sin(2*pi*f2*time) + ox2;
		y2 = r2 * cos(2*pi*f2*time) + oy2;

		x3 = r3 * sin(2*pi*f3*time) + ox3;
		y3 = r3 * cos(2*pi*f3*time) + oy3;

		p1 = Point(x1,y1);
		p2 = Point(x2,y2);
		p3 = Point(x3,y3);

		l1 = p1.dist(p2);
		l2 = p2.dist(p3);
		l3 = p3.dist(p1);

		perimeter = l1 + l2 + l3;
		area = sqrt(perimeter/2 * (perimeter/2 - l1) * (perimeter/2 - l2) * (perimeter/2 - l3));

		(
			l1: l1,
			l2: l2,
			l3: l3,
			perimeter: perimeter,
			area: area,
		).debug("data");

		Pen.line(o1, p1);
		Pen.line(o2, p2);
		Pen.line(o3, p3);

		Pen.addArc(o1, r1,0,2pi);
		Pen.addArc(o2, r2,0,2pi);
		Pen.addArc(o3, r3,0,2pi);

		Pen.line(p1, p2);
		Pen.line(p2, p3);
		Pen.line(p3, p1);
		Pen.stroke;


		Pen
    };
};


{ while { run } { w.refresh; 0.05.wait;} }.fork(AppClock)

)
raw 1752 chars (focus & ctrl+a+c to copy)
reception
comments