Skip to content

Commit

Permalink
test modules conditional compilation flag added, plotting example added
Browse files Browse the repository at this point in the history
  • Loading branch information
orhanbalci committed Apr 28, 2016
1 parent f7c3a40 commit cad5ec9
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 7 deletions.
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "easer"
version = "0.1.0"
version = "0.1.1"
authors = ["Orhan Balci <[email protected]>"]
description="Tiny library imlementing Robert Penner's easing functions"
documentation="http://orhanbalci.github.io/rust-easing"
Expand All @@ -10,6 +10,11 @@ keywords=["easing","animation","tween"]
license="MIT"
exclude=[".travis.yml"]

[dependencies]
[dev-dependencies]
approx="0.1.0"
gnuplot="0.0.20"

[[example]]
name="easer_plotter"
path="examples/easer_plotter.rs"

108 changes: 108 additions & 0 deletions examples/easer_plotter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
extern crate gnuplot;
extern crate easer;

use gnuplot::{Figure, Caption, Color, AxesCommon};
use easer::functions::*;

fn main() {
let mut fg = Figure::new();
plot_easing_function(&mut fg, Back::ease_in, Back::ease_out, Back::ease_in_out, 0);
plot_easing_function(&mut fg,
Bounce::ease_in,
Bounce::ease_out,
Bounce::ease_in_out,
3);
plot_easing_function(&mut fg, Circ::ease_in, Circ::ease_out, Circ::ease_in_out, 6);
// plot_easing_function(&mut fg,
// Cubic::ease_in,
// Cubic::ease_out,
// Cubic::ease_in_out,
// 9);
// plot_easing_function(&mut fg,
// Elastic::ease_in,
// Elastic::ease_out,
// Elastic::ease_in_out,
// 12);
// plot_easing_function(&mut fg,
// Expo::ease_in,
// Expo::ease_out,
// Expo::ease_in_out,
// 15);
// plot_easing_function(&mut fg,
// Linear::ease_in,
// Linear::ease_out,
// Linear::ease_in_out,
// 18);
// plot_easing_function(&mut fg,
// Quad::ease_in,
// Quad::ease_out,
// Quad::ease_in_out,
// 21);
// plot_easing_function(&mut fg,
// Quart::ease_in,
// Quart::ease_out,
// Quart::ease_in_out,
// 24);
// plot_easing_function(&mut fg,
// Quint::ease_in,
// Quint::ease_out,
// Quint::ease_in_out,
// 27);
// plot_easing_function(&mut fg,
// Sine::ease_in,
// Sine::ease_out,
// Sine::ease_in_out,
// 30);

fg.show();
// rintln!("Hello, world!");
}

fn plot_easing_function<F1, F2, F3>(fg: &mut Figure,
fun_ease_in: F1,
fun_ease_out: F2,
fun_ease_in_out: F3,
cell: u32)
where F1: Fn(f32, f32, f32, f32) -> f32,
F2: Fn(f32, f32, f32, f32) -> f32,
F3: Fn(f32, f32, f32, f32) -> f32
{

let mut x: [f32; 100] = [0.0; 100];
let mut y: [f32; 100] = [0.0; 100];
for i in 0..100 {
x[i] = i as f32;
y[i] = i as f32;
}

let back = y.iter()
.map(|a| fun_ease_in(*a, 0f32, 100f32, 100f32))
.collect::<Vec<f32>>();

fg.axes2d()
.lines(&x[..], &back, &[Caption("In Line"), Color("blue")])
.set_title("Back Ease In", &[])
.set_pos_grid(3, 3, cell);
let back_ease_out = y.iter()
.map(|a| fun_ease_out(*a, 0f32, 100f32, 100f32))
.collect::<Vec<f32>>();

fg.axes2d()
.lines(&x[..],
&back_ease_out,
&[Caption("Out Line"), Color("blue")])
.set_title("Back Ease Out", &[])
.set_pos_grid(3, 3, cell + 1);

let back_ease_in_out = y.iter()
.map(|a| fun_ease_in_out(*a, 0f32, 100f32, 100f32))
.collect::<Vec<f32>>();

fg.axes2d()
.lines(&x[..],
&back_ease_in_out,
&[Caption("In Out Line"), Color("blue")])
.set_title("Back Ease In Out", &[])
.set_pos_grid(3, 3, cell + 2);

}
1 change: 1 addition & 0 deletions src/functions/back.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl Easing for Back {
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use functions::ease::Easing;
Expand Down
1 change: 1 addition & 0 deletions src/functions/bounce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl Easing for Bounce {
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use functions::ease::Easing;
Expand Down
1 change: 1 addition & 0 deletions src/functions/circ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl Easing for Circ {
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use functions::ease::Easing;
Expand Down
1 change: 1 addition & 0 deletions src/functions/cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl Easing for Cubic {
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use functions::ease::Easing;
Expand Down
1 change: 1 addition & 0 deletions src/functions/elastic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl Easing for Elastic {
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use functions::ease::Easing;
Expand Down
1 change: 1 addition & 0 deletions src/functions/expo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl Easing for Expo {
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use functions::ease::Easing;
Expand Down
1 change: 1 addition & 0 deletions src/functions/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl Easing for Linear {
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use functions::ease::Easing;
Expand Down
1 change: 1 addition & 0 deletions src/functions/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl Easing for Quad {
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use functions::ease::Easing;
Expand Down
1 change: 1 addition & 0 deletions src/functions/quart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl Easing for Quart {
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use functions::ease::Easing;
Expand Down
1 change: 1 addition & 0 deletions src/functions/quint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl Easing for Quint {
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use functions::ease::Easing;
Expand Down
1 change: 1 addition & 0 deletions src/functions/sine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl Easing for Sine {
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
use functions::ease::Easing;
Expand Down
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//!
//! #example
//!
//! ```no_run
//! use easer::functions::*;
//! let mut x: [f32; 100] = [0.0; 100];
//! let mut y: [f32; 100] = [0.0; 100];
//! for i in 0..100 {
Expand All @@ -13,11 +15,10 @@
//! y.iter_mut().map(|a| *a = Back::ease_in(*a, 0f32, 100f32, 100f32)).count();
//! println!("After {:?}", &y[..]);
//!
//!
#[macro_use]
extern crate approx;
//! ```
pub mod functions;

#[test]
fn it_works() {}
#[cfg(test)]
#[macro_use]
extern crate approx;

0 comments on commit cad5ec9

Please sign in to comment.