-
Notifications
You must be signed in to change notification settings - Fork 0
/
recorte.js
183 lines (142 loc) · 3.99 KB
/
recorte.js
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
Math.radians = function(degrees) {
return degrees * Math.PI / 180;
};
// aspects:
// conjunction (0), **NOT INCLUDED** sextile (60), square (90), trine (120), opposition (180)
function aspects(angles, positions) {
var m = 7.5; // margin for aspects
var lines = [];
for (var who = 0; who < angles.length; who++) {
// checks each planet with subsequent planets
for (var with_whom = who + 1; with_whom < angles.length; with_whom++) {
var delta = Math.abs(angles[who] - angles[with_whom]);
var line = null;
// conjunction
if (-m < delta && delta < m) {
line = {
'origin': positions[who],
'end': positions[with_whom],
'type': 'conjunction'
};
}
// square
if ((90-m < delta && delta < 90+m) || (270-m < delta && delta < 270+m)) {
line = {
'origin': positions[who],
'end': positions[with_whom],
'type': 'square'
};
}
// trine
if ((120-m < delta && delta < 120+m) || (240-m < delta && delta < 240+m)) {
line = {
'origin': positions[who],
'end': positions[with_whom],
'type': 'trine'
};
}
// opposition
if (180-m < delta && delta < 180+m) {
line = {
'origin': positions[who],
'end': positions[with_whom],
'type': 'opposition'
};
}
if (line) {
lines.push(line);
}
}
}
return lines;
}
function planet_position(angle, radius) {
var x, y;
var a = radius[0]/2, b = radius[1]/2;
var theta = Math.radians(angle);
x = a * Math.cos(theta);
y = b * Math.sin(theta);
return new Point(x,y);
}
// 0 = sun
// 1 = moon
// 2 = mercury
// 3 = venus
// 4 = mars
// 5 = jupiter
// 6 = saturn
var radii = [
[251, 122],
[339, 165],
[426, 207],
[514, 250],
[601, 292],
[689, 335],
[777, 378],
];
var positions = [];
var delta_x = paper.view.viewSize.width / 2;
var delta_y = paper.view.viewSize.height / 2;
var type_layer = new Layer(),
planets_layer = new Layer(),
aspects_layer = new Layer();
function plot_planets() {
console.log('Will now draw the planets...');
planets_layer.removeChildren();
planets_layer.activate();
positions = [];
if (planets.length == 0) {
for (var i = 0; i < 7; i++) {
planets.push(Math.floor(Math.random() * 360));
}
}
for (var i = 0; i < planets.length; i++) {
r = [radii[i][0], radii[i][1]];
// console.log(r);
r[0] *= g_f;
r[1] *= g_f;
// console.log(r);
var p = planet_position(planets[i], r);
positions.push(p);
var adjusted_point = new Point(p.x + delta_x, p.y + delta_y)
var drawn_planet = new Path.Circle(adjusted_point, PLANET_WIDTH);
drawn_planet.fillColor = versions[used_version].color;
}
}
function plot_aspects() {
console.log('...and their aspects.');
if (positions.length == 0) {
plot_planets();
}
aspects_layer.removeChildren();
aspects_layer.activate();
var lines = aspects(planets, positions);
for (var i = 0; i < lines.length; i++) {
var myPath = new Path();
myPath.strokeColor = versions[used_version].color;
myPath.strokeWidth = ASPECT_STROKE;
myPath.add(new Point(lines[i].origin.x + delta_x, lines[i].origin.y + delta_y));
myPath.add(new Point(lines[i].end.x + delta_x, lines[i].end.y + delta_y));
}
aspects_layer.sendToBack();
}
view.onFrame = function(event) {
if (redraw && g_f == 1) {
delta_x = paper.view.viewSize.width / 2;
delta_y = paper.view.viewSize.height / 2;
}
if (data_is_dirty || redraw) {
data_is_dirty = false;
redraw = false;
plot_planets();
plot_aspects();
}
if (recalculate_deltas) {
recalculate_deltas = false;
console.log(delta_x);
delta_x = Math.floor(Math.random() * paper.view.viewSize.width - paper.view.viewSize.width/2);
delta_y = Math.floor(Math.random() * paper.view.viewSize.height - paper.view.viewSize.height/2);
console.log(delta_x);
redraw = true;
}
}