flip/mirror/rotate functions for tiles
This commit is contained in:
parent
226292dcac
commit
9081c157d6
|
@ -5,7 +5,7 @@ pub struct Image {
|
||||||
|
|
||||||
impl Image {
|
impl Image {
|
||||||
/// flip image vertically
|
/// flip image vertically
|
||||||
fn flip(&mut self) {
|
pub fn flip(&mut self) {
|
||||||
let mut pixels = Vec::with_capacity(64);
|
let mut pixels = Vec::with_capacity(64);
|
||||||
|
|
||||||
for row in self.pixels.chunks(8).rev() {
|
for row in self.pixels.chunks(8).rev() {
|
||||||
|
@ -18,7 +18,7 @@ impl Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// mirror image horizontally
|
/// mirror image horizontally
|
||||||
fn mirror(&mut self) {
|
pub fn mirror(&mut self) {
|
||||||
let mut pixels = Vec::with_capacity(64);
|
let mut pixels = Vec::with_capacity(64);
|
||||||
|
|
||||||
for row in self.pixels.chunks(8) {
|
for row in self.pixels.chunks(8) {
|
||||||
|
@ -31,7 +31,7 @@ impl Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// rotate image 90° clockwise
|
/// rotate image 90° clockwise
|
||||||
fn rotate(&mut self) {
|
pub fn rotate(&mut self) {
|
||||||
let mut pixels = Vec::with_capacity(64);
|
let mut pixels = Vec::with_capacity(64);
|
||||||
|
|
||||||
// start from bottom-left corner, work upward in that column,
|
// start from bottom-left corner, work upward in that column,
|
||||||
|
|
26
src/tile.rs
26
src/tile.rs
|
@ -40,6 +40,32 @@ impl Tile {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo refactor
|
||||||
|
|
||||||
|
pub fn flip(&mut self) {
|
||||||
|
self.animation_frames = self.animation_frames.iter().map(|frame: &Image| {
|
||||||
|
let mut image = frame.clone();
|
||||||
|
image.flip();
|
||||||
|
image
|
||||||
|
}).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mirror(&mut self) {
|
||||||
|
self.animation_frames = self.animation_frames.iter().map(|frame: &Image| {
|
||||||
|
let mut image = frame.clone();
|
||||||
|
image.mirror();
|
||||||
|
image
|
||||||
|
}).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn rotate(&mut self) {
|
||||||
|
self.animation_frames = self.animation_frames.iter().map(|frame: &Image| {
|
||||||
|
let mut image = frame.clone();
|
||||||
|
image.rotate();
|
||||||
|
image
|
||||||
|
}).collect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for Tile {
|
impl From<String> for Tile {
|
||||||
|
|
Loading…
Reference in New Issue