-
Notifications
You must be signed in to change notification settings - Fork 0
/
cartao-verso.js
206 lines (144 loc) · 4.04 KB
/
cartao-verso.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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 c = 0.27;
var radii = [
[251*c, 122*c],
[339*c, 165*c],
[426*c, 207*c],
[514*c, 250*c],
[601*c, 292*c],
[689*c, 335*c],
[777*c, 378*c],
];
var positions = [];
var delta_x = paper.view.viewSize.width / 2;
var delta_y = paper.view.viewSize.height / 2;
function plot_planets() {
console.log('(Cartão 1) 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++) {
var p = planet_position(planets[i], radii[i]);
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*c);
drawn_planet.fillColor = '#007cff';
}
planets_layer.bringToFront();
}
function plot_aspects() {
console.log('(Cartão 1) ...and their aspects.');
aspects_layer.removeChildren();
aspects_layer.activate();
var mask = new Path.Rectangle(13,13,260,170);
var lines = aspects(planets, positions);
// console.log(positions);
for (var i = 0; i < lines.length; i++) {
var myPath = new Path();
myPath.strokeColor = '#007cff';
myPath.strokeWidth = ASPECT_STROKE*c;
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.clipped = true;
aspects_layer.bringToFront();
}
var base_layer = new Layer(),
type_layer = new Layer(),
aspects_layer = new Layer(),
planets_layer = new Layer();
function plot_images_l1() {
base_layer.removeChildren();
base_layer.activate();
base_layer.importSVG('svgs/cartao_verso_base.svg');
base_layer.scale(2,2);
base_layer.sendToBack();
}
function plot_images_l2() {
type_layer.removeChildren();
type_layer.activate();
type_layer.importSVG('svgs/cartao_verso_topo.svg');
type_layer.scale(2,2);
type_layer.bringToFront();
}
view.onFrame = function(event) {
if (svgs_are_dirty) {
plot_images_l1();
plot_planets();
plot_images_l2();
plot_aspects();
planets_layer.bringToFront();
svgs_are_dirty = false;
}
}