Created
May 17, 2024 18:00
-
-
Save joaofig/d8c2b1c6d867b6b2da9e628176fbfe27 to your computer and use it in GitHub Desktop.
Paints a single tile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn paint_tile(pixels: Vec<TilePixel>, | |
color_grad: Gradient, | |
range: LevelRange) -> RgbaImage { | |
let mut bitmap = make_rgba_tile(0, 0, 0, 0); | |
if range.width() > 0.0 { | |
for pixel in pixels { | |
let intensity = (pixel.get_c() - range.min()).ln() / range.width().ln(); | |
let rgba = color_grad.at(intensity); | |
let pix = Rgba::from(rgba.to_rgba8()); | |
bitmap.put_pixel(pixel.get_x() as u32, | |
pixel.get_y() as u32, | |
pix); | |
} | |
} else { | |
let rgba = color_grad.at(1.0); | |
let pix = Rgba::from(rgba.to_rgba8()); | |
for pixel in pixels { | |
bitmap.put_pixel(pixel.get_x() as u32, | |
pixel.get_y() as u32, | |
pix); | |
} | |
} | |
bitmap | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment