2019-04-02 18:48:07 +02:00
|
|
|
use std::fs::create_dir_all;
|
|
|
|
|
|
|
|
use image::RgbaImage;
|
|
|
|
use image::imageops::{rotate90, rotate180, rotate270};
|
|
|
|
|
|
|
|
fn superpose(image: &RgbaImage, superposition: &RgbaImage) -> RgbaImage {
|
|
|
|
let mut clone = image.clone();
|
|
|
|
|
|
|
|
for i in 0 .. image.width() {
|
|
|
|
for j in 0 .. image.height() {
|
|
|
|
let new_pixel = superposition.get_pixel(i, j);
|
|
|
|
if new_pixel[3] > 0 {
|
|
|
|
*clone.get_pixel_mut(i, j) = *new_pixel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clone
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
create_dir_all("assets/textures-generated").unwrap();
|
|
|
|
let background = image::open("assets/textures/grass/background.png").unwrap().to_rgba();
|
|
|
|
let border = image::open("assets/textures/grass/border.png").unwrap().to_rgba();
|
|
|
|
let corner_horiz = image::open("assets/textures/grass/corner-horiz.png").unwrap().to_rgba();
|
|
|
|
let corner_vert = image::open("assets/textures/grass/corner-vert.png").unwrap().to_rgba();
|
|
|
|
let corner_inside = image::open("assets/textures/grass/corner-inside.png").unwrap().to_rgba();
|
|
|
|
let corner_outside = image::open("assets/textures/grass/corner-outside.png").unwrap().to_rgba();
|
|
|
|
|
|
|
|
let mut vec = vec![];
|
|
|
|
|
|
|
|
let image_0 = background.clone();
|
|
|
|
vec.push(&image_0);
|
|
|
|
|
|
|
|
let image_1 = corner_outside.clone();
|
|
|
|
vec.push(&image_1);
|
|
|
|
|
|
|
|
let image_4 = rotate90(&corner_outside);
|
|
|
|
vec.push(&image_4);
|
|
|
|
|
|
|
|
let image_5 = superpose(&image_1, &image_4);
|
|
|
|
vec.push(&image_5);
|
|
|
|
|
|
|
|
let image_7 = superpose(&superpose(&corner_horiz, &border), &rotate90(&corner_vert));
|
|
|
|
vec.push(&image_7);
|
|
|
|
|
|
|
|
let image_16 = rotate90(&rotate90(&corner_outside));
|
|
|
|
vec.push(&image_16);
|
|
|
|
|
|
|
|
let image_17 = superpose(&image_16, &corner_outside);
|
|
|
|
vec.push(&image_17);
|
|
|
|
|
|
|
|
let image_20 = superpose(&rotate90(&corner_outside), &rotate180(&corner_outside));
|
|
|
|
vec.push(&image_20);
|
|
|
|
|
|
|
|
let image_21 = superpose(&image_20, &corner_outside);
|
|
|
|
vec.push(&image_21);
|
|
|
|
|
|
|
|
let image_23 = superpose(&image_7, &image_16);
|
|
|
|
vec.push(&image_23);
|
|
|
|
|
|
|
|
let image_28 = rotate90(&image_7);
|
|
|
|
vec.push(&image_28);
|
|
|
|
|
|
|
|
let image_29 = superpose(&image_1, &image_28);
|
|
|
|
vec.push(&image_29);
|
|
|
|
|
|
|
|
let image_31 = superpose(&superpose(&border, &superpose(&rotate90(&border), &rotate90(&corner_inside))), &corner_horiz);
|
|
|
|
let image_31 = superpose(&image_31, &rotate180(&corner_vert));
|
|
|
|
vec.push(&image_31);
|
|
|
|
|
|
|
|
let image_64 = rotate270(&image_1);
|
|
|
|
vec.push(&image_64);
|
|
|
|
|
|
|
|
let image_65 = superpose(&image_1, &image_64);
|
|
|
|
vec.push(&image_65);
|
|
|
|
|
|
|
|
let image_68 = superpose(&image_4, &image_64);
|
|
|
|
vec.push(&image_68);
|
|
|
|
|
|
|
|
let image_69 = superpose(&image_1, &image_68);
|
|
|
|
vec.push(&image_69);
|
|
|
|
|
|
|
|
let image_71 = superpose(&image_7, &image_64);
|
|
|
|
vec.push(&image_71);
|
|
|
|
|
|
|
|
let image_80 = superpose(&image_16, &image_64);
|
|
|
|
vec.push(&image_80);
|
|
|
|
|
|
|
|
let image_81 = superpose(&image_1, &image_80);
|
|
|
|
vec.push(&image_81);
|
|
|
|
|
|
|
|
let image_84 = superpose(&image_4, &image_80);
|
|
|
|
vec.push(&image_84);
|
|
|
|
|
|
|
|
let image_85 = superpose(&image_1, &image_84);
|
|
|
|
vec.push(&image_85);
|
|
|
|
|
|
|
|
let image_87 = superpose(&image_7, &image_80);
|
|
|
|
vec.push(&image_87);
|
|
|
|
|
|
|
|
let image_92 = superpose(&image_28, &image_64);
|
|
|
|
vec.push(&image_92);
|
|
|
|
|
|
|
|
let image_93 = superpose(&image_1, &image_92);
|
|
|
|
vec.push(&image_93);
|
|
|
|
|
|
|
|
let image_95 = superpose(&image_31, &image_64);
|
|
|
|
vec.push(&image_95);
|
|
|
|
|
|
|
|
let image_112 = rotate180(&image_7);
|
|
|
|
vec.push(&image_112);
|
|
|
|
|
|
|
|
let image_113 = superpose(&image_1, &image_112);
|
|
|
|
vec.push(&image_113);
|
|
|
|
|
|
|
|
let image_116 = superpose(&image_4, &image_112);
|
|
|
|
vec.push(&image_116);
|
|
|
|
|
|
|
|
let image_117 = superpose(&image_1, &image_116);
|
|
|
|
vec.push(&image_117);
|
|
|
|
|
|
|
|
let image_119 = superpose(&image_7, &image_112);
|
|
|
|
vec.push(&image_119);
|
|
|
|
|
|
|
|
let image_124 = rotate90(&image_31);
|
|
|
|
vec.push(&image_124);
|
|
|
|
|
|
|
|
let image_125 = superpose(&image_1, &image_124);
|
|
|
|
vec.push(&image_125);
|
|
|
|
|
|
|
|
let image_127 = superpose(&superpose(&border, &superpose(&rotate90(&border), &rotate90(&corner_inside))), &corner_horiz);
|
|
|
|
let image_127 = superpose(&superpose(&image_127, &rotate180(&corner_inside)), &rotate180(&border));
|
|
|
|
let image_127 = superpose(&image_127, &rotate270(&corner_vert));
|
|
|
|
vec.push(&image_127);
|
|
|
|
|
|
|
|
let image_193 = rotate270(&image_7);
|
|
|
|
vec.push(&image_193);
|
|
|
|
|
|
|
|
let image_197 = superpose(&image_4, &image_193);
|
|
|
|
vec.push(&image_197);
|
|
|
|
|
2019-04-02 20:27:05 +02:00
|
|
|
let image_199 = rotate270(&image_31);
|
2019-04-02 18:48:07 +02:00
|
|
|
vec.push(&image_199);
|
|
|
|
|
|
|
|
let image_209 = rotate90(&image_116);
|
|
|
|
vec.push(&image_209);
|
|
|
|
|
|
|
|
let image_213 = rotate90(&image_117);
|
|
|
|
vec.push(&image_213);
|
|
|
|
|
|
|
|
let image_215 = rotate180(&image_125);
|
|
|
|
vec.push(&image_215);
|
|
|
|
|
|
|
|
let image_221 = rotate90(&image_119);
|
|
|
|
vec.push(&image_221);
|
|
|
|
|
|
|
|
let image_223 = rotate270(&image_127);
|
|
|
|
vec.push(&image_223);
|
|
|
|
|
|
|
|
let image_241 = rotate90(&image_124);
|
|
|
|
vec.push(&image_241);
|
|
|
|
|
|
|
|
let image_245 = rotate270(&image_215);
|
|
|
|
vec.push(&image_245);
|
|
|
|
|
|
|
|
let image_247 = rotate270(&image_223);
|
|
|
|
vec.push(&image_247);
|
|
|
|
|
|
|
|
let image_253 = rotate180(&image_223);
|
|
|
|
vec.push(&image_253);
|
|
|
|
|
|
|
|
let image_255 = superpose(&border, &superpose(&rotate90(&border), &superpose(&rotate180(&border), &rotate270(&border))));
|
|
|
|
let image_255 = superpose(&image_255, &corner_inside);
|
|
|
|
let image_255 = superpose(&image_255, &rotate90(&corner_inside));
|
|
|
|
let image_255 = superpose(&image_255, &rotate180(&corner_inside));
|
|
|
|
let image_255 = superpose(&image_255, &rotate270(&corner_inside));
|
|
|
|
vec.push(&image_255);
|
|
|
|
|
|
|
|
let mut output = RgbaImage::new(32 * 47, 32);
|
|
|
|
for (index, image) in vec.into_iter().enumerate() {
|
|
|
|
for y in 0 .. image.width() {
|
|
|
|
for x in 0 .. image.height() {
|
|
|
|
*output.get_pixel_mut(x + 32 * index as u32, y) = *background.get_pixel(x, y);
|
|
|
|
let new_pixel = image.get_pixel(x, y);
|
|
|
|
if new_pixel[3] > 0 {
|
|
|
|
*output.get_pixel_mut(x + 32 * index as u32, y) = *new_pixel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
output.save("assets/textures-generated/grass.png").unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
|