free-rusty-maker/build.rs

221 lines
6.2 KiB
Rust
Raw Permalink Normal View History

2019-04-02 18:48:07 +02:00
use std::fs::create_dir_all;
2020-04-21 19:29:24 +02:00
use image::imageops::{rotate180, rotate270, rotate90};
use image::{GenericImage, RgbaImage};
2019-04-02 18:48:07 +02:00
fn superpose(image: &RgbaImage, superposition: &RgbaImage) -> RgbaImage {
let mut clone = image.clone();
2020-04-21 19:29:24 +02:00
for i in 0..image.width() {
for j in 0..image.height() {
2019-04-02 18:48:07 +02:00
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();
2019-04-03 15:49:51 +02:00
let mut texture = image::open("assets/textures/grass.png").unwrap().to_rgba();
let background = texture.sub_image(0, 0, 32, 32).to_image();
let border = texture.sub_image(32, 0, 32, 32).to_image();
2020-04-21 19:29:24 +02:00
let corner_horiz = texture.sub_image(32 * 2, 0, 32, 32).to_image();
let corner_vert = texture.sub_image(32 * 3, 0, 32, 32).to_image();
let corner_inside = texture.sub_image(32 * 4, 0, 32, 32).to_image();
2019-04-03 15:49:51 +02:00
let corner_outside = texture.sub_image(32 * 5, 0, 32, 32).to_image();
let mut background_color = texture.sub_image(32 * 6, 0, 32, 32);
let background_color = background_color.get_pixel_mut(0, 0);
2019-04-02 18:48:07 +02:00
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);
2020-04-21 19:29:24 +02:00
let image_31 = superpose(
&superpose(
&border,
&superpose(&rotate90(&border), &rotate90(&corner_inside)),
),
&corner_horiz,
);
2019-04-02 18:48:07 +02:00
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);
2020-04-21 19:29:24 +02:00
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),
);
2019-04-02 18:48:07 +02:00
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);
2020-04-21 19:29:24 +02:00
let image_255 = superpose(
&border,
&superpose(
&rotate90(&border),
&superpose(&rotate180(&border), &rotate270(&border)),
),
);
2019-04-02 18:48:07 +02:00
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() {
2020-04-21 19:29:24 +02:00
for y in 0..image.width() {
for x in 0..image.height() {
2019-04-02 18:48:07 +02:00
let new_pixel = image.get_pixel(x, y);
2019-04-03 15:49:51 +02:00
if new_pixel != background_color {
*output.get_pixel_mut(x + 32 * index as u32, y) = *background.get_pixel(x, y);
if new_pixel[3] > 0 {
*output.get_pixel_mut(x + 32 * index as u32, y) = *new_pixel;
}
2019-04-02 18:48:07 +02:00
}
}
}
}
output.save("assets/textures-generated/grass.png").unwrap();
}