diff --git a/_config.yml b/_config.yml index cc6d40f..fa33564 100644 --- a/_config.yml +++ b/_config.yml @@ -1,5 +1,10 @@ theme: jekyll-theme-slate collections: - summaries: - projects: - output: true + summaries: + projects: + output: true +defaults: + - scope: + path: "assets/img" + values: + image: true diff --git a/assets/css/style.scss b/assets/css/style.scss index 9aa5a7a..4861913 100644 --- a/assets/css/style.scss +++ b/assets/css/style.scss @@ -3,6 +3,11 @@ @import "jekyll-theme-slate"; +#header_wrap { + /* Image with a fallback linear gradient. */ + background: center/cover no-repeat url('/assets/img/fractal.jpeg'), linear-gradient(to top, #373737, #212121); +} + .inner-wide { position: relative; max-width: 992px; diff --git a/assets/fractal.rs b/assets/fractal.rs new file mode 100644 index 0000000..d9bc344 --- /dev/null +++ b/assets/fractal.rs @@ -0,0 +1,68 @@ +//! An example of generating julia fractals. +extern crate image; +extern crate num_complex; + +// This is gamma pre-corrected color of the linear gradient background. +const BACKGROUND: u16 = 40; + +// Maximum color saturation (as basically 8-bit). +const MAGNITUDE: u8 = 20; + +fn main() { + let imgx = 3200; + let imgy = 3200/2; + + let scalex = 3.0 / imgx as f32; + let scaley = 1.5 / imgy as f32; + + // Create a new ImgBuf with width: imgx and height: imgy + let mut imgbuf = image::ImageBuffer::new(imgx, imgy); + + // Iterate over the coordinates and pixels of the image + for (x, y, pixel) in imgbuf.enumerate_pixels_mut() { + let r = (0.3 * x as f32) as u8; + let b = (0.3 * y as f32) as u8; + *pixel = image::Rgb([r, 0, b]); + } + + let red = num_complex::Complex::from_polar(&(MAGNITUDE as f32), &0.0); + let green = num_complex::Complex::from_polar(&(MAGNITUDE as f32), &5.25); + let blue = num_complex::Complex::from_polar(&(MAGNITUDE as f32), &2.11); + + // A redundant loop to demonstrate reading image data + for x in 0..imgx { + for y in 0..imgy { + let cx = y as f32 * scalex - 0.75; + let cy = x as f32 * scaley - 1.5; + + let c = num_complex::Complex::new(-0.4, 0.6); + let mut z = num_complex::Complex::new(cx, cy); + + let mut i: u8 = 0; + while i < 255 && z.norm() <= 2.0 { + z = z * z + c; + i += 1; + } + + let pixel = imgbuf.get_pixel_mut(x, y); + *pixel = image::Rgb([ + brightness((z.norm()*red).re as i8, i), + brightness((z.norm()*green).re as i8, i), + brightness((z.norm()*blue).re as i8, i)]); + } + } + + // Save the image as “fractal.png”, the format is deduced from the path + imgbuf.save("fractal.png").unwrap(); +} + +fn brightness(input: i8, iter: u8) -> u8 { + // Available color manipulation depending on iter value. + const ITER_RANGE: u16 = 255 - BACKGROUND; + let input = (input as i16 + 128) as u16; + let iter = u16::from(iter); + let premultiplied = (iter.saturating_sub(32) * input) / 224; + // iter scaled into the iter range. + let in_range = (premultiplied * ITER_RANGE) >> 8; + (in_range + BACKGROUND) as u8 +} diff --git a/assets/img/fractal.jpeg b/assets/img/fractal.jpeg new file mode 100644 index 0000000..abffeac Binary files /dev/null and b/assets/img/fractal.jpeg differ