|
|
|
#![allow(dead_code)]
|
|
|
|
#![allow(unused_variables)]
|
|
|
|
#![allow(unused_mut)]
|
|
|
|
|
|
|
|
extern crate quick_xml;
|
|
|
|
extern crate sfml;
|
|
|
|
extern crate cgmath;
|
|
|
|
extern crate image;
|
|
|
|
|
|
|
|
mod slider;
|
|
|
|
mod timer;
|
|
|
|
mod input;
|
|
|
|
mod util;
|
|
|
|
|
|
|
|
use crate::timer::Timer;
|
|
|
|
use crate::input::Input;
|
|
|
|
use crate::slider::Slider;
|
|
|
|
|
|
|
|
extern crate nalgebra as na;
|
|
|
|
|
|
|
|
use image::{GenericImageView, GenericImage, DynamicImage, Pixel, SubImage};
|
|
|
|
|
|
|
|
use sfml::graphics::{
|
|
|
|
Color, RenderTarget, RenderWindow,
|
|
|
|
};
|
|
|
|
use sfml::window::{ Event, Key, Style};
|
|
|
|
use sfml::system::Vector2 as sfVec2;
|
|
|
|
|
|
|
|
fn surrounding_pixels(x: u32, y: u32, img: &DynamicImage) -> Vec<image::Rgba<u8>> {
|
|
|
|
|
|
|
|
let mut pixels: Vec<image::Rgba<u8>> = Vec::new();
|
|
|
|
|
|
|
|
if img.in_bounds(x+1, y+1) {pixels.push(img.get_pixel(x+1, y+1))}
|
|
|
|
if img.in_bounds(x+1, y) {pixels.push(img.get_pixel(x+1, y))}
|
|
|
|
if img.in_bounds(x+1, y-1) {pixels.push(img.get_pixel(x+1, y-1))}
|
|
|
|
|
|
|
|
if img.in_bounds(x, y+1) {pixels.push(img.get_pixel(x, y+1))}
|
|
|
|
if img.in_bounds(x, y-1) {pixels.push(img.get_pixel(x, y-1))}
|
|
|
|
|
|
|
|
if img.in_bounds(x-1, y+1) {pixels.push(img.get_pixel(x-1, y+1))}
|
|
|
|
if img.in_bounds(x-1, y) {pixels.push(img.get_pixel(x-1, y))}
|
|
|
|
if img.in_bounds(x-1, y-1) {pixels.push(img.get_pixel(x-1, y-1))}
|
|
|
|
|
|
|
|
pixels
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
|
|
|
let mut img = image::open("test.jpg").unwrap();
|
|
|
|
let xy = img.dimensions();
|
|
|
|
|
|
|
|
for x in 0..xy.0 {
|
|
|
|
for y in 0..xy.1 {
|
|
|
|
let mut pixel = img.get_pixel(x, y);
|
|
|
|
|
|
|
|
let v = surrounding_pixels(x, y, &img);
|
|
|
|
|
|
|
|
// let mut avg: Pixel;
|
|
|
|
//
|
|
|
|
// for p in v {
|
|
|
|
// avg += p;
|
|
|
|
// }
|
|
|
|
|
|
|
|
pixel.data[0] = 1;
|
|
|
|
|
|
|
|
img.put_pixel(x, y, pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
img.save("fractal.png").unwrap();
|
|
|
|
|
|
|
|
let mut window = RenderWindow::new(
|
|
|
|
(512, 512),
|
|
|
|
"Custom drawable",
|
|
|
|
Style::CLOSE,
|
|
|
|
&Default::default(),
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut timer = Timer::new();
|
|
|
|
let mut input = Input::new();
|
|
|
|
|
|
|
|
|
|
|
|
let mut slider = Slider::new(40.0, None);
|
|
|
|
|
|
|
|
let step_size: f32 = 0.005;
|
|
|
|
let mut elapsed_time: f32;
|
|
|
|
let mut delta_time: f32;
|
|
|
|
let mut accumulator_time: f32 = 0.0;
|
|
|
|
let mut current_time: f32 = timer.elap_time();
|
|
|
|
|
|
|
|
while window.is_open() {
|
|
|
|
|
|
|
|
while let Some(event) = window.poll_event() {
|
|
|
|
match event {
|
|
|
|
Event::Closed => return,
|
|
|
|
Event::KeyPressed { code, .. } => {
|
|
|
|
if code == Key::Escape {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
input.ingest(&event)
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.is_held(Key::W) {
|
|
|
|
}
|
|
|
|
if input.is_held(Key::A) {
|
|
|
|
}
|
|
|
|
if input.is_held(Key::S) {
|
|
|
|
}
|
|
|
|
if input.is_held(Key::D) {
|
|
|
|
}
|
|
|
|
|
|
|
|
elapsed_time = timer.elap_time();
|
|
|
|
delta_time = elapsed_time - current_time;
|
|
|
|
current_time = elapsed_time;
|
|
|
|
if delta_time > 0.02 {
|
|
|
|
delta_time = 0.02;
|
|
|
|
}
|
|
|
|
accumulator_time += delta_time;
|
|
|
|
|
|
|
|
while (accumulator_time - step_size) >= step_size {
|
|
|
|
accumulator_time -= step_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.clear(&Color::BLACK);
|
|
|
|
|
|
|
|
window.draw(&slider);
|
|
|
|
|
|
|
|
window.display();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|