tsuku 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +46 -0
- data/README.md +2 -0
- data/lib/tsuku/easing.rb +44 -0
- data/lib/tsuku/tween.rb +63 -0
- data/lib/tsuku/version.rb +3 -0
- data/lib/tsuku.rb +11 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/mock_target.rb +9 -0
- data/spec/tsuku_spec.rb +7 -0
- data/spec/tween_spec.rb +44 -0
- data/tsuku.gemspec +23 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8bfd429da0b770c819bc22a8ac2d20b916a7c39aee53ad8f309d608c68399b0e
|
4
|
+
data.tar.gz: 64c79f6f3704bd322c27c85bbbea6713eeb48db4fc434363860f02f38ed39147
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f80cb14e286cd41964a355be0de81e6faf49783e297b94c04928b1991a4844c500be97612d7f0dc2b3506fcf0377db4f4693dfc2ac715caccfc7f65ae5d1d2ed
|
7
|
+
data.tar.gz: 3acfc46de978fe92db5ed5c217e9e46777a45cdd74a477b64651b64c730cc82cdd9375cb494f5084babdfca982facb1b4937ff9a60456da43a769b585203fc82
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tsuku (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
byebug (9.1.0)
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
method_source (0.9.2)
|
13
|
+
pry (0.12.2)
|
14
|
+
coderay (~> 1.1.0)
|
15
|
+
method_source (~> 0.9.0)
|
16
|
+
pry-byebug (3.5.1)
|
17
|
+
byebug (~> 9.1)
|
18
|
+
pry (~> 0.10)
|
19
|
+
rake (10.5.0)
|
20
|
+
rspec (3.8.0)
|
21
|
+
rspec-core (~> 3.8.0)
|
22
|
+
rspec-expectations (~> 3.8.0)
|
23
|
+
rspec-mocks (~> 3.8.0)
|
24
|
+
rspec-core (3.8.0)
|
25
|
+
rspec-support (~> 3.8.0)
|
26
|
+
rspec-expectations (3.8.3)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.8.0)
|
29
|
+
rspec-mocks (3.8.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-support (3.8.0)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
x86_64-darwin-18
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bundler (~> 1.15)
|
40
|
+
pry-byebug (~> 3.5.0)
|
41
|
+
rake (~> 10.0)
|
42
|
+
rspec (~> 3.0)
|
43
|
+
tsuku!
|
44
|
+
|
45
|
+
BUNDLED WITH
|
46
|
+
1.17.2
|
data/README.md
ADDED
data/lib/tsuku/easing.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Tsuku
|
2
|
+
class Easing
|
3
|
+
class << self
|
4
|
+
def linear(t, b, c, d)
|
5
|
+
c * t / d + b
|
6
|
+
end
|
7
|
+
|
8
|
+
def ease_in_quad(t, b, c, d)
|
9
|
+
t /= d
|
10
|
+
c * t * t + b
|
11
|
+
end
|
12
|
+
|
13
|
+
def ease_out_quad(t, b, c, d)
|
14
|
+
t /= d
|
15
|
+
-c * t * (t - 2) + b
|
16
|
+
end
|
17
|
+
|
18
|
+
def ease_in_out_quad(t, b, c, d)
|
19
|
+
t /= d / 2
|
20
|
+
return c / 2 * t * t + b if t < 1
|
21
|
+
t -= 1
|
22
|
+
-c / 2 * (t * (t - 2) - 1) + b
|
23
|
+
end
|
24
|
+
|
25
|
+
def ease_in_cubic(t, b, c, d)
|
26
|
+
t /= d
|
27
|
+
return c * t * t * t + b
|
28
|
+
end
|
29
|
+
|
30
|
+
def ease_out_cubic(t, b, c, d)
|
31
|
+
t /= d
|
32
|
+
t -= 1
|
33
|
+
c * (t * t * t + 1) + b
|
34
|
+
end
|
35
|
+
|
36
|
+
def ease_in_out_cubic(t, b, c, d)
|
37
|
+
t /= (d / 2)
|
38
|
+
return c / 2 * t * t * t + b if t < 1
|
39
|
+
t -= 2
|
40
|
+
return c / 2 * (t * t * t + 2) + b
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/tsuku/tween.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Tsuku
|
2
|
+
class Tween
|
3
|
+
def initialize(target, final_property_values, duration_ms, easing: :linear)
|
4
|
+
@target = target
|
5
|
+
@final_property_values = final_property_values
|
6
|
+
@duration_ms = duration_ms
|
7
|
+
@easing = easing
|
8
|
+
|
9
|
+
@running = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def start
|
13
|
+
@elapsed_ms = 0.0
|
14
|
+
|
15
|
+
@initial_property_values = {}
|
16
|
+
|
17
|
+
@final_property_values.each_key do |k|
|
18
|
+
@initial_property_values[k] = @target.send(k)
|
19
|
+
end
|
20
|
+
|
21
|
+
@running = true
|
22
|
+
end
|
23
|
+
|
24
|
+
def step(delta_ms)
|
25
|
+
return if !@running
|
26
|
+
|
27
|
+
@elapsed_ms += delta_ms
|
28
|
+
|
29
|
+
if @elapsed_ms >= @duration_ms
|
30
|
+
complete
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
advance_property_values
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def advance_property_values
|
40
|
+
@final_property_values.each_key do |k|
|
41
|
+
# Based on Penner's equations
|
42
|
+
t = @elapsed_ms
|
43
|
+
b = @initial_property_values[k]
|
44
|
+
c = @final_property_values[k] - @initial_property_values[k]
|
45
|
+
d = @duration_ms
|
46
|
+
|
47
|
+
current_value = Easing.method(@easing).call(t, b, c, d)
|
48
|
+
|
49
|
+
@target.send("#{k}=", current_value)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def complete
|
54
|
+
@elapsed_ms = @duration_ms
|
55
|
+
|
56
|
+
@final_property_values.each do |k,v|
|
57
|
+
@target.send("#{k}=", v)
|
58
|
+
end
|
59
|
+
|
60
|
+
@running = false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/tsuku.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "tsuku"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
16
|
+
end
|
data/spec/tsuku_spec.rb
ADDED
data/spec/tween_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Tsuku::Tween do
|
4
|
+
let(:target) { MockTarget.new(x: 1, y: 2, z: 3) }
|
5
|
+
|
6
|
+
let(:tween) { Tsuku::Tween.new(target, { x: 10, y: -10, z: 3 }, 1000) }
|
7
|
+
|
8
|
+
it "tweens correctly in positive direction" do
|
9
|
+
tween.start
|
10
|
+
tween.step(1000)
|
11
|
+
expect(target.x).to eq(10)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "tweens correctly in negative direction" do
|
15
|
+
tween.start
|
16
|
+
tween.step(1000)
|
17
|
+
expect(target.y).to eq(-10)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "tweens correctly when target property does not change" do
|
21
|
+
tween.start
|
22
|
+
tween.step(1000)
|
23
|
+
expect(target.z).to eq(3)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "does not tween past target value" do
|
27
|
+
tween.start
|
28
|
+
tween.step(5000)
|
29
|
+
expect(target.x).to eq(10)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "tweens correctly when property value changes after tween initialization" do
|
33
|
+
target.x = 50
|
34
|
+
tween.start
|
35
|
+
tween.step(1000)
|
36
|
+
expect(target.x).to eq(10)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "computes intermediate value correctly (linear easing)" do
|
40
|
+
tween.start
|
41
|
+
tween.step(500)
|
42
|
+
expect(target.x).to eq(5.5)
|
43
|
+
end
|
44
|
+
end
|
data/tsuku.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../lib/tsuku/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'tsuku'
|
5
|
+
spec.version = Tsuku::VERSION
|
6
|
+
spec.authors = ['John Tuttle']
|
7
|
+
spec.email = ['jtuttle.develops@gmail.com']
|
8
|
+
|
9
|
+
spec.summary = 'A tweening library made with Ruby'
|
10
|
+
spec.description = 'A tweening library made with Ruby'
|
11
|
+
spec.homepage = 'https://github.com/jtuttle/tsuku'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\0")
|
15
|
+
spec.test_files = `git ls-files -z spec/`.split("\0")
|
16
|
+
spec.extra_rdoc_files = ['README.md', 'CHANGELOG.md']
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
20
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
21
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
22
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.5.0'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tsuku
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Tuttle
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.5.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.5.0
|
69
|
+
description: A tweening library made with Ruby
|
70
|
+
email:
|
71
|
+
- jtuttle.develops@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- README.md
|
76
|
+
- CHANGELOG.md
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- CHANGELOG.md
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- README.md
|
84
|
+
- lib/tsuku.rb
|
85
|
+
- lib/tsuku/easing.rb
|
86
|
+
- lib/tsuku/tween.rb
|
87
|
+
- lib/tsuku/version.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- spec/support/mock_target.rb
|
90
|
+
- spec/tsuku_spec.rb
|
91
|
+
- spec/tween_spec.rb
|
92
|
+
- tsuku.gemspec
|
93
|
+
homepage: https://github.com/jtuttle/tsuku
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubygems_version: 3.0.3
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: A tweening library made with Ruby
|
116
|
+
test_files:
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- spec/support/mock_target.rb
|
119
|
+
- spec/tsuku_spec.rb
|
120
|
+
- spec/tween_spec.rb
|