This commit is contained in:
Max Bradbury 2020-07-18 22:10:26 +01:00
parent 023eaed779
commit 140e5914df
1 changed files with 3 additions and 5 deletions

View File

@ -39,10 +39,8 @@ pub fn add_tiles(game_data: String, image: String, prefix: String) -> String {
let height = image.height();
assert_eq!(width % 8, 0);
assert_eq!(height % 8, 0);
let columns = (width as f64 / 8 as f64).floor() as u32;
let rows = (height as f64 / 8 as f64).floor() as u32;
// todo iterate over 8x8 tiles in image
let columns = (width as f64 / 8.).floor() as u32;
let rows = (height as f64 / 8.).floor() as u32;
let mut tile_index = 1;
@ -53,7 +51,7 @@ pub fn add_tiles(game_data: String, image: String, prefix: String) -> String {
for y in (row * SD)..((row + 1) * SD) {
for x in (column * SD)..((column + 1) * SD) {
let pixel = image.get_pixel(x, y).to_rgb();
let total: u32 = (pixel[0] as u32 + pixel[1] as u32 + pixel[2] as u32) as u32;
let total = pixel[0] as u32 + pixel[1] as u32 + pixel[2] as u32;
// is each channel brighter than 128/255 on average?
pixels.push(if total >= 384 {1} else {0});
}