From: MegaBrutal Date: Sat, 17 Dec 2022 21:30:00 +0000 (+0100) Subject: Experimental implementation of /gen/4 X-Git-Url: http://git.megabrutal.com/?p=litoprism.git;a=commitdiff_plain;h=c0d7087d8fabfdd737ab60d47bd1fb735386daf2 Experimental implementation of /gen/4 --- diff --git a/src/main.rs b/src/main.rs index 7bd6bfe..b9b9dfe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,18 +5,18 @@ use std::fmt::Display; use std::fmt; use std::borrow::BorrowMut; use std::sync::{Arc, Mutex}; -use log::LevelFilter; +use log::{debug, warn, LevelFilter}; use num_traits::Zero; use num_traits::cast::AsPrimitive; use percent_encoding::percent_decode_str; use actix_web::{middleware::Logger, get, web, App, HttpServer, HttpRequest, HttpResponse, Responder, ResponseError, Result}; use actix_web::body::BoxBody; use actix_web::http::StatusCode; +use actix_web::cookie::time::OffsetDateTime; use image::{ImageBuffer, ColorType, Rgb, RgbImage, write_buffer_with_format}; use image::ImageOutputFormat::Png; use image::imageops::{FilterType, overlay, resize}; use image::error::{LimitError, LimitErrorKind}; -use actix_web::cookie::time::OffsetDateTime; const TIMEAVATAR_SIZE_U32: u32 = 6; @@ -296,6 +296,37 @@ async fn img_gen3(req: HttpRequest, path: web::Path) -> Result) -> Result { + let scale = path.into_inner(); + let signal = &mut extract_header!(req, "user-agent").bytes(); + let mut resimg: RgbImage = ImageBuffer::new(1600, 600); + let mut x: f32 = 0.0; + let max_x: f32 = (resimg.width() - 1) as f32; + //let max_y: f32 = (resimg.height() - 1) as f32; + let run: f32 = 20.0; + let amplitude: f32 = 200.0; + let wave_offset: f32 = (resimg.height() / 2) as f32 + amplitude / 2.0 - 1.0; + let freq_base: f32 = 50.0; + while x < max_x { + let px = x; + let s = signal.next().unwrap_or(0); + warn!("Next char: {:>1} {:#02X}", s as char, s); + while ((x - px) < run) && (x < max_x) { + let y = if s != 0 { + (x / (freq_base / s as f32)).sin() * amplitude + wave_offset + } + else { wave_offset }; + x += 0.001; + debug!("{x}, {y}"); + resimg.put_pixel(x as u32, y as u32, Rgb([255, 255, 255])); + resimg.put_pixel(x as u32, s.into(), Rgb([255, 0, 0])); + } + } + let cursor = image_to_cursor(resimg, scale)?; + Ok(response_image!(cursor)) +} + #[get("/pgen/0/{data}")] async fn img_pgen0(req: HttpRequest, canvas0: web::Data>>) -> Result { let data = extract_data!(req, 3); @@ -390,6 +421,7 @@ async fn main() -> std::io::Result<()> { .service(img_gen1) .service(img_gen2) .service(img_gen3) + .service(img_gen4) .service(img_pgen0) .service(img_pgen1) .service(img_pgen2)