Top Level Namespace
Defined Under Namespace
Modules: CanDisable, HasSprite, Processing, RubySketch
Classes: Background, Button, Card, CardPlace, Curtain, Dialog, Fade, History, Klondike, Particle, ParticleSprite, Pixelate, RootScene, Scene, Score, Settings, Shake, Skin, Start, TransitionEffect
Constant Summary
collapse
- EASINGS =
{
linear: lambda {|x| x},
sineIn: lambda {|x| 1.0 - Math.cos(x * Math::PI / 2)},
sineOut: lambda {|x| Math.sin(x * Math::PI / 2)},
quadIn: lambda {|x| quadIn x},
cubicIn: lambda {|x| cubicIn x},
quartIn: lambda {|x| quartIn x},
quintIn: lambda {|x| quintIn x},
circIn: lambda {|x| circIn x},
backIn: lambda {|x| backIn x},
expoIn: lambda {|x| expoIn x},
elasticIn: lambda {|x| elasticIn x},
bounceIn: lambda {|x| 1.0 - bounceOut(1.0 - x)},
quadOut: lambda {|x| 1.0 - quadIn(1.0 - x)},
cubicOut: lambda {|x| 1.0 - cubicIn(1.0 - x)},
quartOut: lambda {|x| 1.0 - quartIn(1.0 - x)},
quintOut: lambda {|x| 1.0 - quintIn(1.0 - x)},
circOut: lambda {|x| 1.0 - curcIn(1.0 - x)},
backOut: lambda {|x| 1.0 - backIn(1.0 - x)},
expoOut: lambda {|x| 1.0 - expoIn(1.0 - x)},
elasticOut: lambda {|x| 1.0 - elasticIn(1.0 - x)},
bounceOut: lambda {|x| bounceOut x},
sineInOut: lambda {|x| x < 0.5 ? sineIn(x) : sineOut(x)},
quadInOut: lambda {|x| x < 0.5 ? quadIn(x) : quadOut(x)},
cubicInOut: lambda {|x| x < 0.5 ? cubicIn(x) : cubicOut(x)},
quartInOut: lambda {|x| x < 0.5 ? quartIn(x) : quartOut(x)},
quintInOut: lambda {|x| x < 0.5 ? quintIn(x) : quintOut(x)},
circInOut: lambda {|x| x < 0.5 ? circIn(x) : circOut(x)},
backInOut: lambda {|x| x < 0.5 ? backIn(x) : backOut(x)},
expoInOut: lambda {|x| x < 0.5 ? expoIn(x) : expoOut(x)},
elasticInOut: lambda {|x| x < 0.5 ? elasticIn(x) : elasticOut(x)},
bounceInOut: lambda {|x| x < 0.5 ? bounceIn(x) : bounceOut(x)}
}
Instance Method Summary
collapse
-
#animate(name = unique, seconds, ease: :expoOut, &block) ⇒ Object
-
#animateValue(name = unique, seconds, from:, to:, **kwargs, &block) ⇒ Object
-
#backgroundScene ⇒ Object
-
#backIn(x) ⇒ Object
-
#bounceOut(x) ⇒ Object
-
#checkFocus ⇒ Object
-
#circIn(x) ⇒ Object
-
#cubicIn(x) ⇒ Object
-
#dataPath(path) ⇒ Object
-
#debug? ⇒ Boolean
-
#delay(&block) ⇒ Object
-
#drawShake ⇒ Object
-
#elasticIn(x) ⇒ Object
-
#expoIn(x) ⇒ Object
-
#fireTimers ⇒ Object
-
#getTimer(name) ⇒ Object
-
#ios? ⇒ Boolean
-
#loadSound(path) ⇒ Object
-
#move(obj, toPos, seconds, **kwargs, &block) ⇒ Object
-
#now ⇒ Object
-
#quadIn(x) ⇒ Object
-
#quartIn(x) ⇒ Object
-
#quintIn(x) ⇒ Object
-
#resizeImage(image, w, h) ⇒ Object
-
#sendCommand(type, *args) ⇒ Object
-
#settings ⇒ Object
-
#shake(obj, length = nil, vector: nil) ⇒ Object
-
#shakeScreen(length = nil, vector: nil) ⇒ Object
-
#skin(index = nil) ⇒ Object
-
#startInterval(name = unique, seconds, now: false, &block) ⇒ Object
-
#startTimer(name = unique, seconds, &block) ⇒ Object
-
#stopTimer(name) ⇒ Object
-
#unique ⇒ Object
-
#windowPos ⇒ Object
Instance Method Details
#animate(name = unique, seconds, ease: :expoOut, &block) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 89
def animate(name = unique, seconds, ease: :expoOut, &block)
fun = EASINGS[ease]
start = now
eachDrawBlock = lambda do
t = (now - start) / seconds
if t >= 1.0
block.call fun.call(1.0), true, 1.0
else
block.call fun.call(t), false, t
startTimer name, 0, &eachDrawBlock
end
end
startTimer name, 0, &eachDrawBlock
end
|
#animateValue(name = unique, seconds, from:, to:, **kwargs, &block) ⇒ Object
104
105
106
107
108
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 104
def animateValue(name = unique, seconds, from:, to:, **kwargs, &block)
animate name, seconds, **kwargs do |t, finished, tt|
block.call lerp(from, to, t), finished, t, tt
end
end
|
#backgroundScene ⇒ Object
50
51
52
|
# File 'lib/rubysketch/solitaire.rb', line 50
def backgroundScene()
$backgroundScene ||= Background.new
end
|
#backIn(x) ⇒ Object
61
62
63
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 61
def backIn(x)
2.70158 * x ** 3 - 1.70158 * x ** 2
end
|
#bounceOut(x) ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 78
def bounceOut(x)
n1, d1 = 7.5625, 2.75
case
when x < 1.0 / d1 then n1 * x * x
when x < 2.0 / d1 then x -= 1.5 / d1; n1 * x * x + 0.75;
when x < 2.5 / d1 then x -= 2.25 / d1; n1 * x * x + 0.9375;
else x -= 2.625 / d1; n1 * x * x + 0.984375;
end
end
|
#checkFocus ⇒ Object
54
55
56
57
58
|
# File 'lib/rubysketch/solitaire.rb', line 54
def checkFocus()
$prevFocused = focused if $prevFocused == nil
$root.focusChanged focused if focused != $prevFocused
$prevFocused = focused
end
|
#circIn(x) ⇒ Object
57
58
59
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 57
def circIn(x)
1.0 - Math.sqrt(1.0 - x ** 2)
end
|
#cubicIn(x) ⇒ Object
45
46
47
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 45
def cubicIn(x)
x ** 3
end
|
#dataPath(path) ⇒ Object
16
17
18
|
# File 'lib/rubysketch/solitaire/common/utils.rb', line 16
def dataPath(path)
File.expand_path "../../../../data/#{path}", __dir__
end
|
#debug? ⇒ Boolean
33
34
35
|
# File 'lib/rubysketch/solitaire.rb', line 33
def debug?()
$debug || ENV['DEBUG'] || false
end
|
#delay(&block) ⇒ Object
24
25
26
|
# File 'lib/rubysketch/solitaire/common/timer.rb', line 24
def delay(&block)
startTimer 0, &block
end
|
#drawShake ⇒ Object
44
45
46
47
48
|
# File 'lib/rubysketch/solitaire/common/shake.rb', line 44
def drawShake()
v = $shake&.vector
translate v.x, v.y if v
$shake&.update
end
|
#elasticIn(x) ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 69
def elasticIn(x)
c = Math::PI * 2.0 / 3.0
case x
when 0 then 0
when 1 then 1
else -(2 ** (10.0 * x - 10.0)) * Math.sin((x * 10.0 - 10.75) * c)
end
end
|
#expoIn(x) ⇒ Object
65
66
67
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 65
def expoIn(x)
x == 0 ? 0.0 : 2.0 ** (10.0 * x - 10.0)
end
|
#fireTimers ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/rubysketch/solitaire/common/timer.rb', line 28
def fireTimers()
now_ = now
blocks = []
$timers.delete_if do |_, (time, block)|
(now_ >= time).tap {|t| blocks.push block if t}
end
blocks.each &:call
end
|
#getTimer(name) ⇒ Object
20
21
22
|
# File 'lib/rubysketch/solitaire/common/timer.rb', line 20
def getTimer(name)
$timers[name]
end
|
#ios? ⇒ Boolean
4
5
6
|
# File 'lib/rubysketch/solitaire/common/utils.rb', line 4
def ios?()
RbConfig::CONFIG['CFLAGS'] =~ %r{/Platforms/iPhone(OS|Simulator).platform/}
end
|
#loadSound(path) ⇒ Object
4
5
6
|
# File 'lib/rubysketch/solitaire/common/sound.rb', line 4
def loadSound(path)
Beeps::Sound.load path
end
|
#move(obj, toPos, seconds, **kwargs, &block) ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 110
def move(obj, toPos, seconds, **kwargs, &block)
from, to = obj.pos.dup, toPos.dup
animate seconds, **kwargs do |t, *args|
obj.pos = Vector.lerp(from, to, t)
block&.call t, *args
end
end
|
#now ⇒ Object
8
9
10
|
# File 'lib/rubysketch/solitaire/common/utils.rb', line 8
def now()
Time.now.to_f
end
|
#quadIn(x) ⇒ Object
41
42
43
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 41
def quadIn(x)
x ** 2
end
|
#quartIn(x) ⇒ Object
49
50
51
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 49
def quartIn(x)
x ** 4
end
|
#quintIn(x) ⇒ Object
53
54
55
|
# File 'lib/rubysketch/solitaire/common/animation.rb', line 53
def quintIn(x)
x ** 5
end
|
#resizeImage(image, w, h) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/rubysketch/solitaire/common/utils.rb', line 20
def resizeImage(image, w, h)
createGraphics(w, h).tap do |g|
g.beginDraw do
g.copy image, 0, 0, image.width, image.height, 0, 0, w, h
end
end
end
|
#sendCommand(type, *args) ⇒ Object
37
38
39
|
# File 'lib/rubysketch/solitaire.rb', line 37
def sendCommand(type, *args)
$command = [type, *args].map {|s| URI.encode_www_form_component s}.join ':'
end
|
#settings ⇒ Object
41
42
43
|
# File 'lib/rubysketch/solitaire.rb', line 41
def settings()
$settings ||= Settings.new 'solitaire.json'
end
|
#shake(obj, length = nil, vector: nil) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/rubysketch/solitaire/common/shake.rb', line 27
def shake(obj, length = nil, vector: nil)
shake = Shake.new length, vector
pos = obj.pos.dup
fun = -> do
v = shake.vector
break obj.pos = pos unless v
obj.pos = pos + v
shake.update
delay {fun.call}
end
fun.call
end
|
#shakeScreen(length = nil, vector: nil) ⇒ Object
40
41
42
|
# File 'lib/rubysketch/solitaire/common/shake.rb', line 40
def shakeScreen(length = nil, vector: nil)
$shake = Shake.new length, vector
end
|
#skin(index = nil) ⇒ Object
45
46
47
48
|
# File 'lib/rubysketch/solitaire.rb', line 45
def skin(index = nil)
$skin = nil if index != nil && index != $skin.index
$skin ||= Skin.new index || settings['skinIndex'] || 0
end
|
#startInterval(name = unique, seconds, now: false, &block) ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/rubysketch/solitaire/common/timer.rb', line 8
def startInterval(name = unique, seconds, now: false, &block)
block.call if now
startTimer name, seconds do
block.call
startInterval name, seconds, &block
end
end
|
#startTimer(name = unique, seconds, &block) ⇒ Object
3
4
5
6
|
# File 'lib/rubysketch/solitaire/common/timer.rb', line 3
def startTimer(name = unique, seconds, &block)
$timers[name] = [now + seconds, block]
name
end
|
#stopTimer(name) ⇒ Object
16
17
18
|
# File 'lib/rubysketch/solitaire/common/timer.rb', line 16
def stopTimer(name)
$timers.delete name
end
|
#unique ⇒ Object
12
13
14
|
# File 'lib/rubysketch/solitaire/common/utils.rb', line 12
def unique()
Object.new.object_id
end
|
#windowPos ⇒ Object
79
80
81
82
83
84
|
# File 'lib/rubysketch/solitaire.rb', line 79
def windowPos()
settings['windowPos'] || [
(displayWidth - windowWidth) / 2,
(displayHeight - windowHeight) / 2
]
end
|