-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEAM_Core.rb
More file actions
257 lines (202 loc) · 6.25 KB
/
Copy pathEAM_Core.rb
File metadata and controls
257 lines (202 loc) · 6.25 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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
################################################################################
# EASYANIMATION CORE, must be always included (in the project, not in the class)
#
# Version 1.0 (Build 1)
# 18/11/15
# Scripter: Fuji
################################################################################
################################################################################
# Callbacks class
################################################################################
class EAM_Callback
DEBUG = true
class << self
def log(obj,type)
case type
when :move
echoln("Move finished") if DEBUG
when :fade
echoln("Fade finished") if DEBUG
when :zoom
echoln("Zoom finished") if DEBUG
when :rotate
echoln("Rotate finished") if DEBUG
when :coloring
echoln("Coloring finished") if DEBUG
end
end
end
end
################################################################################
# Utility arithmetic functions class
################################################################################
class Curve
class << self
def circPoint(origin, angle, rad, axisX) # axisX = true if calculating X, else false if calculating Y
if axisX
# echoln("Cos - origine: " + origin.to_s + " Angle: " + angle.to_s + " Rad: " + rad.to_s)
return origin + Math.cos(Curve.rad(angle)) * rad
else
# echoln("Sin - origine: " + origin.to_s + " Angle: " + angle.to_s + " Rad: " + rad.to_s)
return origin - Math.sin(Curve.rad(angle)) * rad
end
end
# Convert Radiants to Degrees
def deg(radiants)
return radiants * 180 / Math::PI
end
# Convert Degrees to Radiants
def rad(degrees)
return degrees * Math::PI / 180
end
# Convert value in a valid angle [0-360]
def correctAngle(angle)
return angle % 360
end
def radiusFromPoints(circX, circY, pX, pY)
dX = (circX - pX).abs
dY = (circY - pY).abs
return Math.sqrt(dX * dX + dY * dY)
end
def angle(circX, circY, pX, pY)
begin
m = -(pY - circY).to_f / (pX - circX).to_f
rescue
return (circY > pY ? 90 : 270)
end
# echoln("m: " + m.to_s + " - y = " + self.y.to_s + " cy = " + @circY.to_s + " x = " + self.x.to_s + " cx = " + @circX.to_s)
angle = Curve.deg(Math.atan(m))
if m > 0
angle += 180 if circY < pY
elsif m < 0
if circY > pY
angle += 180
else
angle += 360
end
else
angle = (pX > circX ? 0 : 180)
end
# @angle += 360 if @angle < 0
return angle
end
end
end
# Update all elements in the passed array (or hash) at the same time (same frame)
# NB This could be heavy to process
def waitAnimation(array)
while true
exit = true
array.each {|element| exit = false if element.isAnimating?}
break if exit
array.each {|element| element.update}
Graphics.update
array.each {|element| element.postUpdate}
end
end
################################################################################
# A port of known Robert Penner's easing functions for Ruby by munshkr
# https://github.com/munshkr/easing-ruby/
################################################################################
class Ease
class << self
def linear_tween(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c * t / d + b
end
def ease_in_quad(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c*(t/=d)*t + b;
end
def ease_out_quad(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return -c *(t/=d)*(t-2) + b;
end
def ease_in_out_quad(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
t /= d / 2
return c / 2*t*t + b if (t < 1)
t -= 1
return -c/2 * (t*(t-2) - 1) + b
end
def ease_in_cubic(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c*(t/=d)*t*t + b
end
def ease_out_cubic(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c*((t=t/d-1)*t*t + 1) + b
end
def ease_in_out_cubic(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c/2*t*t*t + b if ((t/=d/2) < 1)
return c/2*((t-=2)*t*t + 2) + b
end
def ease_in_quart(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c*(t/=d)*t*t*t + b
end
def ease_out_quart(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return -c * ((t=t/d-1)*t*t*t - 1) + b
end
def ease_in_out_quart(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c/2*t*t*t*t + b if ((t/=d/2) < 1)
return -c/2 * ((t-=2)*t*t*t - 2) + b
end
def ease_in_quint(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c*(t/=d)*t*t*t*t + b
end
def ease_out_quint(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c*((t=t/d-1)*t*t*t*t + 1) + b
end
def ease_in_out_quint(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c/2*t*t*t*t*t + b if ((t/=d/2) < 1)
return c/2*((t-=2)*t*t*t*t + 2) + b
end
def ease_in_sine(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return -c * Math.cos(t/d * (Math::PI/2)) + c + b
end
def ease_out_sine(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c * Math.sin(t/d * (Math::PI/2)) + b
end
def ease_in_out_sine(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return -c/2 * (Math.cos(Math::PI*t/d) - 1) + b
end
def ease_in_expo(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return (t==0) ? b : c * (2 ** (10 * (t/d - 1))) + b
end
def ease_out_expo(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return (t==d) ? b+c : c * (-2**(-10 * t/d) + 1) + b
end
def ease_in_out_expo(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return b if t == 0
return b + c if t == d
return (c/2) * 2**(10 * (t-1)) + b if ((t /= d/2) < 1)
return (c/2) * (-2**(-10 * t-=1) + 2) + b
end
def ease_in_circ(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b
end
def ease_out_circ(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return c * Math.sqrt(1 - (t=t/d-1)*t) + b
end
def ease_in_out_circ(t, b, c, d)
t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
return -c/2 * (Math.sqrt(1 - t*t) - 1) + b if ((t/=d/2) < 1)
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b
end
end
end