Failing due to weird float to int conversation not wokring
Some checks failed
CI / Rust project (push) Failing after 1m6s

This commit is contained in:
fabolous005 2023-11-24 21:07:12 +01:00
parent 6426f59f1a
commit 40d962edb1
3 changed files with 56 additions and 48 deletions

View File

@ -7,6 +7,4 @@ edition = "2021"
[dependencies]
image = "0.24.7"
footile = "0.7.0"
pix = "0.13.3"
imageproc = "0.23.0"
rand = "0.8.5"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1,56 +1,66 @@
use image::{RgbImage, Rgb};
use pix::{matte::Matte8, Raster};
use footile::{FillRule, Path2D, Plotter};
use image::{ImageBuffer};
use imageproc::drawing::draw_line_segment_mut;
use std::env;
use rand::Rng;
use image::Rgb;
use image::RgbImage;
use image::ImageBuffer;
fn main() {
let mut img = RgbImage::new(2000, 2000);
// let mut args = vec![];
// for arg in env::args() {
// args.push(arg);
// }
let mut img = get_image();
for x in 15..=17 {
for y in 8..24 {
img.put_pixel(x, y, Rgb([255, 0, 0]));
img.put_pixel(y, x, Rgb([255, 0, 0]));
}
let mut colors= vec![];
let points = [0.1, 0.2, 0.3, 0.4, 0.5];
// function = f(x) = 3x^2
// ableitungsquotient = 6a
for point in points {
let color = [generate_random(0, 255), generate_random(0, 255), generate_random(0, 255)];
colors.push(color);
img.put_pixel((point * 1000.0).round_ties_even() as u32, (get_point(point as i32) * 1000.0).round() as u32, Rgb(color));
}
let fish = Path2D::default()
.relative()
.pen_width(3.0)
.move_to(112.0, 24.0)
.line_to(-32.0, 24.0)
.cubic_to(-96.0, -48.0, -96.0, 80.0, 0.0, 32.0)
.line_to(32.0, 24.0)
.line_to(-16.0, -40.0)
.close()
.finish();
let raster = Raster::with_clear(128, 128);
let mut p = Plotter::new(raster);
p.fill(FillRule::NonZero, &fish, Matte8::new(255));
let width = 2000;
let height = 2000;
let mut img: ImageBuffer<Rgb<u16>, Vec<u16>> = ImageBuffer::new(width, height);
// Define grid parameters
let grid_spacing = 50;
let grid_color = Rgb([0, 0, 0]); // Black color
// Draw vertical grid lines
for x in (0..width).step_by(grid_spacing) {
draw_line_segment_mut(&mut img, (x as f32, 0.0), (x as f32, height as f32), grid_color);
}
// Draw horizontal grid lines
for y in (0..height).step_by(grid_spacing) {
draw_line_segment_mut(&mut img, (0.0, y as f32), (width as f32, y as f32), grid_color);
}
// Save the image
// img.save_with_format("grid_image.png", image::ImageFormat::Jpeg).expect("Failed to save image");
img.save("grid_image.png").expect("Failed to save image");
}
fn get_pitch_quotient() -> u32 {
6
}
fn get_point(x: i32) -> f64 {
(3 * x.pow(2)) as f64
}
fn generate_random(start: u8, end: u8) -> u8 {
let mut rng = rand::thread_rng();
// rng.gen_range(std::char::from_u32(start).unwrap()..=std::char::from_u32(end).unwrap())
rng.gen_range(start..=end)
}
fn get_image() -> ImageBuffer<Rgb<u8>, Vec<u8>> {
let width = 1000;
let height = 1000;
let mut img = RgbImage::new(width, height);
let grid_spacing = 50;
let grid_color = Rgb([255, 9, 255]); // Black colo
for x in (0..width).step_by(grid_spacing) {
for y in 0..height {
img.put_pixel(x, y, grid_color);
}
}
for y in (0..height).step_by(grid_spacing) {
for x in 0..width {
img.put_pixel(x, y, grid_color);
}
}
img
}