change transparent line example to wiping_clear
This commit is contained in:
		
							parent
							
								
									35ae1f20ce
								
							
						
					
					
						commit
						0e393896d3
					
				
					 5 changed files with 53 additions and 59 deletions
				
			
		
							
								
								
									
										20
									
								
								examples/Cargo.lock
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										20
									
								
								examples/Cargo.lock
									
										
									
										generated
									
									
									
								
							| 
						 | 
				
			
			@ -219,16 +219,6 @@ dependencies = [
 | 
			
		|||
 "servicepoint2",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "moving_transparent_line"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "clap",
 | 
			
		||||
 "env_logger",
 | 
			
		||||
 "log",
 | 
			
		||||
 "servicepoint2",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "num"
 | 
			
		||||
version = "0.4.3"
 | 
			
		||||
| 
						 | 
				
			
			@ -524,3 +514,13 @@ name = "windows_x86_64_msvc"
 | 
			
		|||
version = "0.52.5"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "wiping_clear"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "clap",
 | 
			
		||||
 "env_logger",
 | 
			
		||||
 "log",
 | 
			
		||||
 "servicepoint2",
 | 
			
		||||
]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,6 @@ members = [
 | 
			
		|||
    "announce",
 | 
			
		||||
    "game_of_life",
 | 
			
		||||
    "moving_line",
 | 
			
		||||
    "moving_transparent_line",
 | 
			
		||||
    "wiping_clear",
 | 
			
		||||
    "random_brightness",
 | 
			
		||||
]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,47 +0,0 @@
 | 
			
		|||
use std::thread;
 | 
			
		||||
use std::time::Duration;
 | 
			
		||||
 | 
			
		||||
use clap::Parser;
 | 
			
		||||
 | 
			
		||||
use servicepoint2::{BitVec, Connection, PIXEL_HEIGHT, PIXEL_WIDTH, PixelGrid};
 | 
			
		||||
use servicepoint2::Command::{BitmapLinearOr, BitmapLinearXor};
 | 
			
		||||
 | 
			
		||||
#[derive(Parser, Debug)]
 | 
			
		||||
struct Cli {
 | 
			
		||||
    #[arg(short, long, default_value = "localhost:2342")]
 | 
			
		||||
    destination: String,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
    env_logger::builder()
 | 
			
		||||
        .filter_level(log::LevelFilter::Debug)
 | 
			
		||||
        .init();
 | 
			
		||||
 | 
			
		||||
    let connection = Connection::open(Cli::parse().destination).unwrap();
 | 
			
		||||
 | 
			
		||||
    loop {
 | 
			
		||||
        let mut last = BitVec::new(PIXEL_WIDTH as usize * PIXEL_HEIGHT as usize);
 | 
			
		||||
        for x_offset in 0..PIXEL_WIDTH as usize {
 | 
			
		||||
            let mut pixels = PixelGrid::max_sized();
 | 
			
		||||
            pixels.fill(false);
 | 
			
		||||
 | 
			
		||||
            for y in 0..PIXEL_HEIGHT as usize {
 | 
			
		||||
                pixels.set((y + x_offset) % PIXEL_WIDTH as usize, y, true);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // this works because the pixel grid has max size
 | 
			
		||||
            let pixel_data: Vec<u8> = pixels.into();
 | 
			
		||||
            let bit_vec = BitVec::load(&*pixel_data);
 | 
			
		||||
 | 
			
		||||
            // remove pixels from last iteration
 | 
			
		||||
            connection.send(BitmapLinearXor(0, last)).unwrap();
 | 
			
		||||
            // reduces dropped packages
 | 
			
		||||
            thread::sleep(Duration::from_millis(1));
 | 
			
		||||
            // add pixels from this iteration
 | 
			
		||||
            connection.send(BitmapLinearOr(0, bit_vec.clone())).unwrap();
 | 
			
		||||
 | 
			
		||||
            last = bit_vec;
 | 
			
		||||
            thread::sleep(Duration::from_millis(1000));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
[package]
 | 
			
		||||
name = "moving_transparent_line"
 | 
			
		||||
name = "wiping_clear"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
edition = "2021"
 | 
			
		||||
publish = false
 | 
			
		||||
							
								
								
									
										41
									
								
								examples/wiping_clear/src/main.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								examples/wiping_clear/src/main.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,41 @@
 | 
			
		|||
use std::thread;
 | 
			
		||||
use std::time::Duration;
 | 
			
		||||
 | 
			
		||||
use clap::Parser;
 | 
			
		||||
 | 
			
		||||
use servicepoint2::{BitVec, Connection, PIXEL_HEIGHT, PIXEL_WIDTH, PixelGrid};
 | 
			
		||||
use servicepoint2::Command::BitmapLinearAnd;
 | 
			
		||||
 | 
			
		||||
#[derive(Parser, Debug)]
 | 
			
		||||
struct Cli {
 | 
			
		||||
    #[arg(short, long, default_value = "localhost:2342")]
 | 
			
		||||
    destination: String,
 | 
			
		||||
    #[arg(short, long = "duration-ms", default_value_t = 5000)]
 | 
			
		||||
    time: u64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
    env_logger::builder()
 | 
			
		||||
        .filter_level(log::LevelFilter::Info)
 | 
			
		||||
        .init();
 | 
			
		||||
    let cli = Cli::parse();
 | 
			
		||||
 | 
			
		||||
    let connection = Connection::open(cli.destination).unwrap();
 | 
			
		||||
    let sleep_duration = Duration::from_millis(cli.time / PIXEL_WIDTH as u64);
 | 
			
		||||
 | 
			
		||||
    let mut enabled_pixels = PixelGrid::new(PIXEL_WIDTH as usize, PIXEL_HEIGHT as usize);
 | 
			
		||||
    enabled_pixels.fill(true);
 | 
			
		||||
 | 
			
		||||
    for x_offset in 0..PIXEL_WIDTH as usize {
 | 
			
		||||
        for y in 0..PIXEL_HEIGHT as usize {
 | 
			
		||||
            enabled_pixels.set(x_offset % PIXEL_WIDTH as usize, y, false);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // this works because the pixel grid has max size
 | 
			
		||||
        let pixel_data: Vec<u8> = enabled_pixels.clone().into();
 | 
			
		||||
        let bit_vec = BitVec::load(&*pixel_data);
 | 
			
		||||
 | 
			
		||||
        connection.send(BitmapLinearAnd(0, bit_vec)).unwrap();
 | 
			
		||||
        thread::sleep(sleep_duration);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue