easing 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in easing.gemspec
4
+ gemspec
5
+
6
+ gem 'gnuplot', '~> 2.6.2'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Damián Silvani
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # Easing
2
+
3
+ A port of known [Robert Penner's easing
4
+ functions](http://www.robertpenner.com/easing/) for Ruby, implemented both in
5
+ pure-Ruby and with FFI.
6
+
7
+ Check out [easings.net](http://easings.net/) to help you easily visualize each
8
+ of the easing functions.
9
+
10
+ ## Usage
11
+
12
+ All functions are defined in the Easing module, and the same 4 parameters:
13
+
14
+ * `t`: current time
15
+ * `b`: beginning or start value
16
+ * `c`: change in value (or *destination* - `b`)
17
+ * `d`: duration
18
+
19
+ ```ruby
20
+ (0..10).map { |t| Easing.ease_in_out_expo(t, 0, 10, 10) }
21
+ # => [0.0, 0.01953125, 0.078125, 0.3125, 1.2500000000000002, 5.0, 8.75, 9.6875, 9.921875, 9.98046875, 10.0]
22
+ ```
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ gem 'easing'
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ Or install it yourself as:
35
+
36
+ $ gem install easing
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'lib' << 'test'
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ t.verbose = false
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'easing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'easing'
8
+ spec.version = Easing::VERSION
9
+ spec.authors = ['Damián Silvani']
10
+ spec.email = ['munshkr@gmail.com']
11
+ spec.description = %q{Collection of common easing functions for Ruby}
12
+ spec.summary = %q{A Ruby implementation of the well-known Robert Penner's easing functions}
13
+ spec.homepage = 'http://munshkr.github.io/easing-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'minitest', '~> 5.0.2'
24
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift("#{__FILE__}/../lib")
2
+ require 'easing'
3
+ require 'gnuplot'
4
+
5
+ Gnuplot.open do |gp|
6
+ Gnuplot::Plot.new(gp) do |plot|
7
+ plot.title "Easing Functions"
8
+ plot.xlabel "x"
9
+ plot.ylabel "y"
10
+ plot.xrange "[0:100]"
11
+ plot.yrange "[0:100]"
12
+
13
+ x = (0 .. 100).map { |t| t.to_f }
14
+ ease_funcs = Easing.instance_methods(false)
15
+
16
+ plot.data = ease_funcs.map do |method|
17
+ y = x.map { |t| Easing.send(method, t, 0, x.size, x.size) }
18
+
19
+ Gnuplot::DataSet.new([x, y]) do |ds|
20
+ ds.with = "lines"
21
+ ds.title = method
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,147 @@
1
+ require "easing/version"
2
+
3
+ module Easing
4
+ extend self
5
+
6
+ def linear_tween(t, b, c, d)
7
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
8
+
9
+ c * t / d + b
10
+ end
11
+
12
+ def ease_in_quad(t, b, c, d)
13
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
14
+
15
+ return c*(t/=d)*t + b;
16
+ end
17
+
18
+ def ease_out_quad(t, b, c, d)
19
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
20
+
21
+ return -c *(t/=d)*(t-2) + b;
22
+ end
23
+
24
+ def ease_in_out_quad(t, b, c, d)
25
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
26
+
27
+ t /= d / 2
28
+ return c / 2*t*t + b if (t < 1)
29
+ t -= 1
30
+ return -c/2 * (t*(t-2) - 1) + b
31
+ end
32
+
33
+ def ease_in_cubic(t, b, c, d)
34
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
35
+
36
+ return c*(t/=d)*t*t + b
37
+ end
38
+
39
+ def ease_out_cubic(t, b, c, d)
40
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
41
+
42
+ return c*((t=t/d-1)*t*t + 1) + b
43
+ end
44
+
45
+ def ease_in_out_cubic(t, b, c, d)
46
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
47
+
48
+ return c/2*t*t*t + b if ((t/=d/2) < 1)
49
+ return c/2*((t-=2)*t*t + 2) + b
50
+ end
51
+
52
+ def ease_in_quart(t, b, c, d)
53
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
54
+
55
+ return c*(t/=d)*t*t*t + b
56
+ end
57
+
58
+ def ease_out_quart(t, b, c, d)
59
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
60
+
61
+ return -c * ((t=t/d-1)*t*t*t - 1) + b
62
+ end
63
+
64
+ def ease_in_out_quart(t, b, c, d)
65
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
66
+
67
+ return c/2*t*t*t*t + b if ((t/=d/2) < 1)
68
+ return -c/2 * ((t-=2)*t*t*t - 2) + b
69
+ end
70
+
71
+ def ease_in_quint(t, b, c, d)
72
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
73
+
74
+ return c*(t/=d)*t*t*t*t + b
75
+ end
76
+
77
+ def ease_out_quint(t, b, c, d)
78
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
79
+
80
+ return c*((t=t/d-1)*t*t*t*t + 1) + b
81
+ end
82
+
83
+ def ease_in_out_quint(t, b, c, d)
84
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
85
+
86
+ return c/2*t*t*t*t*t + b if ((t/=d/2) < 1)
87
+ return c/2*((t-=2)*t*t*t*t + 2) + b
88
+ end
89
+
90
+ def ease_in_sine(t, b, c, d)
91
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
92
+
93
+ return -c * Math.cos(t/d * (Math::PI/2)) + c + b
94
+ end
95
+
96
+ def ease_out_sine(t, b, c, d)
97
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
98
+
99
+ return c * Math.sin(t/d * (Math::PI/2)) + b
100
+ end
101
+
102
+ def ease_in_out_sine(t, b, c, d)
103
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
104
+
105
+ return -c/2 * (Math.cos(Math::PI*t/d) - 1) + b
106
+ end
107
+
108
+ def ease_in_expo(t, b, c, d)
109
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
110
+
111
+ return (t==0) ? b : c * (2 ** (10 * (t/d - 1))) + b
112
+ end
113
+
114
+ def ease_out_expo(t, b, c, d)
115
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
116
+
117
+ return (t==d) ? b+c : c * (-2**(-10 * t/d) + 1) + b
118
+ end
119
+
120
+ def ease_in_out_expo(t, b, c, d)
121
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
122
+
123
+ return b if t == 0
124
+ return b + c if t == d
125
+ return (c/2) * 2**(10 * (t-1)) + b if ((t /= d/2) < 1)
126
+ return (c/2) * (-2**(-10 * t-=1) + 2) + b
127
+ end
128
+
129
+ def ease_in_circ(t, b, c, d)
130
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
131
+
132
+ return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b
133
+ end
134
+
135
+ def ease_out_circ(t, b, c, d)
136
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
137
+
138
+ return c * Math.sqrt(1 - (t=t/d-1)*t) + b
139
+ end
140
+
141
+ def ease_in_out_circ(t, b, c, d)
142
+ t = t.to_f; b = b.to_f; c = c.to_f; d = d.to_f
143
+
144
+ return -c/2 * (Math.sqrt(1 - t*t) - 1) + b if ((t/=d/2) < 1)
145
+ return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b
146
+ end
147
+ end
@@ -0,0 +1,3 @@
1
+ module Easing
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+ require 'easing'
3
+
4
+ describe Easing do
5
+ describe 'linear_tween' do
6
+ it { assert_equal 10, Easing.linear_tween(10, 0, 100, 100) }
7
+ it { assert_equal 90, Easing.linear_tween(90, 0, 100, 100) }
8
+ end
9
+
10
+ describe 'ease_in_out_quad' do
11
+ it { assert_equal 2.0, Easing.ease_in_out_quad(10, 0, 100, 100) }
12
+ it { assert_equal 98.0, Easing.ease_in_out_quad(90, 0, 100, 100) }
13
+ end
14
+
15
+ describe 'ease_in_out_expo' do
16
+ it { assert_equal 0.1953125, Easing.ease_in_out_expo(10, 0, 100, 100) }
17
+ it { assert_equal 99.8046875, Easing.ease_in_out_expo(90, 0, 100, 100) }
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Damián Silvani
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 5.0.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 5.0.2
62
+ description: Collection of common easing functions for Ruby
63
+ email:
64
+ - munshkr@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - easing.gemspec
75
+ - examples/gnuplot.rb
76
+ - lib/easing.rb
77
+ - lib/easing/version.rb
78
+ - test/easing_test.rb
79
+ - test/test_helper.rb
80
+ homepage: http://munshkr.github.io/easing-ruby
81
+ licenses:
82
+ - MIT
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ segments:
94
+ - 0
95
+ hash: 2127886532900283718
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ segments:
103
+ - 0
104
+ hash: 2127886532900283718
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.25
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: A Ruby implementation of the well-known Robert Penner's easing functions
111
+ test_files:
112
+ - test/easing_test.rb
113
+ - test/test_helper.rb