diff options
-rw-r--r-- | Cargo.lock | 119 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/render.rs | 39 |
4 files changed, 155 insertions, 6 deletions
@@ -15,6 +15,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] name = "cc" version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -42,11 +48,23 @@ dependencies = [ name = "cosin-2025-invite-deck" version = "0.1.0" dependencies = [ + "rand", "rusttype", "sdl2", ] [[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -68,6 +86,63 @@ dependencies = [ ] [[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] name = "rusttype" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -108,13 +183,57 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] +name = "syn" +version = "2.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] name = "ttf-parser" version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd" [[package]] +name = "unicode-ident" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" + +[[package]] name = "version-compare" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +rand = "0.8.5" sdl2 = { version = "0.37.0" } [profile.release] diff --git a/src/main.rs b/src/main.rs index c7a7606..9c65333 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ extern crate sdl2; mod font; + pub mod generated; mod interpolation; mod render; @@ -46,7 +47,6 @@ pub fn main() { _ => {} } } - // The rest of the game loop goes here... canvas.present(); ::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 12000)); diff --git a/src/render.rs b/src/render.rs index c4d207f..938d1ec 100644 --- a/src/render.rs +++ b/src/render.rs @@ -1,6 +1,7 @@ use crate::font::BakedFont; use crate::generated::fonts::{FONT_CHERRY_BOMB_ONE, FONT_GALMURI}; use crate::interpolation::KeyFrame; +use rand::Rng; use sdl2::pixels::{Color, PixelFormatEnum}; use sdl2::rect::Rect; use sdl2::render::{Canvas, Texture, TextureCreator}; @@ -13,9 +14,8 @@ pub fn render( texture_creator: &TextureCreator<WindowContext>, time_seconds: f64, ) { - let movement_per_second = 0.5; - let i = ((time_seconds * 60.0) % 255.0).round() as u8; + let sin_offset = time_seconds * 0.1; canvas.set_draw_color(Color::RGB(12, 12, 12)); canvas.clear(); @@ -26,7 +26,7 @@ pub fn render( canvas .copy( &char - .to_texture(&texture_creator, Color::RGB(255, i, 255 - i)) + .to_texture(&texture_creator, Color::RGB(i, 64, 255 - i)) .unwrap(), None, char.to_rect(offset as i32 + 16, 16), @@ -35,6 +35,26 @@ pub fn render( offset += char.advance_width; } + offset = 0.0; + let mut rng = rand::thread_rng(); + + for c in "sorry for shit demo we have adhd".chars() { + let char = FONT_GALMURI.get_char(c); + canvas + .copy( + &char + .to_texture(&texture_creator, Color::RGB(i, 64, 255 - i)) + .unwrap(), + None, + char.to_rect( + offset as i32 + 18 + rng.gen_range(-2..2), + 16 + 36 * 2 + rng.gen_range(-2..2), + ), + ) + .unwrap(); + offset += char.advance_width / 1.0; + } + { let mut sin_surface = Surface::new(512, 256, PixelFormatEnum::RGBA32).unwrap(); @@ -46,7 +66,7 @@ pub fn render( let f64_w = f64::from(w); let f64_h = f64::from(h); let sin_x = { - let mut sin_x = f64::from(x) + ((time_seconds * movement_per_second) * f64_w); + let mut sin_x = f64::from(x) + (sin_offset * f64_w); if sin_x > f64_w { sin_x = sin_x - f64_w; } @@ -54,13 +74,22 @@ pub fn render( }; let sin_y = ((f64::sin(sin_x * (3.141 * 2.0) / f64_w) + 1.0) * (f64_h / 2.0)).floor() as usize; + // let sin_idx = (sin_y * w as usize + x as usize) * 4; for y in 0..h { let idx = (y * w + x) as usize * 4; f[idx] = 122 - (x / 8) as u8; f[idx + 1] = 255 - (x / 2) as u8; f[idx + 2] = (x / 2) as u8; - f[idx + 3] = if sin_y < y as usize { 255 } else { 0 }; + f[idx + 3] = if sin_y < y as usize { + if idx % 5 == 0 { + 255 + } else { + 122 + } + } else { + 0 + }; } } |