Skip to content

Instantly share code, notes, and snippets.

View randrews's full-sized avatar

Ross Andrews randrews

View GitHub Profile
@randrews
randrews / main.rs
Created July 24, 2025 17:39
LTDC working and spitting pixels
#![no_std]
#![no_main]
use defmt::info;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{AfType, Flex, OutputType, Speed};
use embassy_stm32::ltdc::{B7Pin, ClkPin, DePin, G7Pin, HsyncPin, Ltdc, LtdcConfiguration, LtdcLayer, LtdcLayerConfig, PixelFormat, PolarityActive, PolarityEdge, R7Pin, VsyncPin};
use embassy_stm32::pac::LTDC;
use embassy_stm32::peripherals::LTDC;
use embassy_stm32::rcc;
#![no_std]
#![no_main]
use defmt::info;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{AfType, Flex, OutputType, Speed};
use embassy_stm32::ltdc::{B7Pin, ClkPin, DePin, G7Pin, HsyncPin, Ltdc, LtdcConfiguration, LtdcLayer, LtdcLayerConfig, PixelFormat, PolarityActive, PolarityEdge, R7Pin, VsyncPin};
use embassy_stm32::peripherals::LTDC;
use embassy_stm32::rcc;
use embassy_stm32::rcc::Pll;
@randrews
randrews / main.rs
Created June 16, 2025 05:08
Atkinson dithering in Rust (with the Shepard Fairey Obama poster palette)
fn main() {
let input = image::load_from_memory(include_bytes!("atkinson.png")).unwrap().into_luma16();
let (width, height) = (input.width(), input.height());
let mut output = image::RgbImage::new(width, height);
let mut error_rows = vec![vec![0.0; width as usize]; 3];
let palette: Vec<image::Rgb<u8>> = vec![
[0xe4, 0x2b, 0x19].into(),
[0, 0x40, 0x62].into(),
[0x82, 0xa7, 0xaf].into(),
@randrews
randrews / cargo.toml
Last active June 15, 2025 04:58
Floyd-Steinberg dithering in Rust
[package]
name = "dither"
version = "0.1.0"
edition = "2024"
[dependencies]
image = "0.25.6"
@randrews
randrews / cargo.toml
Last active April 11, 2025 17:12
Generating a MIDI file of changes
[package]
name = "carillon"
version = "0.1.0"
edition = "2024"
[dependencies]
midi_file = "0.0.6"
@randrews
randrews / primmaze2.rs
Last active November 10, 2024 17:57
Prim's Algorithm + a solver in Rust
use std::collections::VecDeque;
use std::env;
use std::fmt::{Display, Formatter};
use std::ops::{Index, IndexMut};
use rand::RngCore;
use crate::Dir::*;
fn main() {
let args: Vec<_> = env::args().collect();
let dimension = if args.len() < 2 {
@randrews
randrews / primmaze.rs
Created October 23, 2024 04:08
Prim's Algorithm in Rust
use std::env;
use std::fmt::{Display, Formatter};
use std::ops::{Index, IndexMut};
use rand::RngCore; // cargo add rand
use crate::Dir::*;
fn main() {
let args: Vec<_> = env::args().collect();
let dimension = if args.len() < 2 {
println!("No dimension, defaulting to 20");
@randrews
randrews / bouncy.rs
Created March 27, 2023 04:57
Bouncing circle in Rust
use std::arch::aarch64::float32x4x4_t;
use std::f32::consts::PI;
use std::thread::sleep;
use std::time::Duration;
use pixels::{Pixels, PixelsBuilder};
use pixels::wgpu::TextureFormat;
use raqote::{DrawOptions, DrawTarget, Path, PathBuilder, SolidSource, Source};
use winit::dpi::LogicalSize;
use winit::event::{Event, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use std::f32::consts::PI;
use pixels::{Pixels, PixelsBuilder};
use pixels::wgpu::TextureFormat;
use raqote::{DrawOptions, DrawTarget, Path, PathBuilder, SolidSource, Source};
use winit::dpi::LogicalSize;
use winit::event::{Event, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::WindowBuilder;
fn main() -> ! {
Three arguments: dest, src, mode
Mode is a word of three bytes, separated into three one-byte sub-args
The sub-args are:
- High byte: mode arg
- Mid / low bytes are a 16-bit limit arg
- (Some end modes only use the low byte)
Mode arg is three fields:
- how the src is interpreted / incremented