wip
This commit is contained in:
parent
237e4534bf
commit
f6e64b6e0b
3 changed files with 91 additions and 16 deletions
51
src/main.rs
51
src/main.rs
|
|
@ -12,7 +12,7 @@ const QUEUE_LEN: usize = 1000;
|
|||
const MSG_PAYLOAD_SIZE: usize = 7 * 211;
|
||||
const MSGSIZE: usize = 2 + MSG_PAYLOAD_SIZE;
|
||||
|
||||
const DISPLAY_HOST: &str = "100.65.0.2";
|
||||
const DISPLAY_HOST: &str = "100.65.13.2";
|
||||
const DISPLAY_PORT: u16 = 5005;
|
||||
const DISPLAY_WIDTH: i32 = 1920;
|
||||
const DISPLAY_HEIGHT: i32 = 1080;
|
||||
|
|
@ -95,7 +95,7 @@ impl BouncingImage {
|
|||
let index = (sy * self.img.width + sx) as usize * 4;
|
||||
let rgba = &self.img.pixels[index..index + 4];
|
||||
if rgba[3] > 0 { // Check alpha channel
|
||||
//display.set_pixel((x + sx as i32) as u16, (y + sy as i32) as u16, rgba[0], rgba[1], rgba[2]);
|
||||
display.set_pixel((x + sx as i32), (y + sy as i32), rgba[0], rgba[1], rgba[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -126,13 +126,17 @@ impl Drawable for BouncingImage {
|
|||
struct Circle {
|
||||
x: Arc<Mutex<u32>>,
|
||||
y: Arc<Mutex<u32>>,
|
||||
set: Arc<Mutex<bool>>,
|
||||
radius: u32
|
||||
}
|
||||
impl Circle {
|
||||
|
||||
fn new(x:Arc<Mutex<u32>>, y: Arc<Mutex<u32>>) -> Self {
|
||||
fn new(x:Arc<Mutex<u32>>, y: Arc<Mutex<u32>>, set: Arc<Mutex<bool>>) -> Self {
|
||||
Circle {
|
||||
x,
|
||||
y
|
||||
y,
|
||||
set,
|
||||
radius:0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -190,17 +194,27 @@ impl Drawable for Circle {
|
|||
}
|
||||
|
||||
/// Helper method to draw the 8 symmetric points for a given (x, y) offset.
|
||||
fn draw_and_move(&mut self, display: &mut Display,tick:u32) {
|
||||
fn draw_and_move(&mut self, display: &mut Display,tick:u32){
|
||||
// if(*self.set.lock().unwrap()){
|
||||
self.radius = 150;
|
||||
// *self.set.lock().unwrap() = false;
|
||||
//}
|
||||
|
||||
//if(self.radius != 0){
|
||||
let hsv_color = color::Hsv {
|
||||
h: ((tick/200)%360).try_into().unwrap(),
|
||||
h: ((tick)%360).try_into().unwrap(),
|
||||
s: 1.0,
|
||||
v: 1.0,
|
||||
};
|
||||
let rgb: color::Rgb = hsv_color.into();
|
||||
let draw_y =*self.x.lock().unwrap();
|
||||
let draw_x = *self.y.lock().unwrap();
|
||||
let radius = (tick/30) % (300/2);
|
||||
self.draw_circle(display,draw_y,draw_x,radius.try_into().unwrap(),rgb.r,rgb.g,rgb.b);
|
||||
//let radius = (tick/30) % (300/2);
|
||||
let radius = self.radius;
|
||||
self.radius = self.radius -1;
|
||||
for i in 0..10 {
|
||||
self.draw_circle(display,draw_y,draw_x,radius-i,rgb.r,rgb.g,rgb.b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -311,9 +325,12 @@ fn main() {
|
|||
let y:Arc<Mutex<u32>>= Arc::new(Mutex::new(0));
|
||||
let y_thread = y.clone();
|
||||
|
||||
let circle = Box::new(Circle::new(x,y));
|
||||
let set:Arc<Mutex<bool>> = Arc::new(Mutex::new(false));
|
||||
let set_thread = set.clone();
|
||||
|
||||
let circle = Box::new(Circle::new(x,y,set));
|
||||
let mut images:Vec<Box<dyn Drawable>> = vec![
|
||||
// Box::new(BouncingImage::new("images/unicorn_cc.png", 13, -10, 1, -1, -1)),
|
||||
// Box::new(BouncingImage::new("images/unicorn_cc.png", 13, -10, 2, -1, -1)),
|
||||
// Box::new(BouncingImage::new("images/windows_logo.png", -8, 3, 2, -1, -1)),
|
||||
// Box::new(BouncingImage::new("images/spade.png", 32, -12, 1, 0, 0)),
|
||||
// Box::new(BouncingImage::new("images/dvdvideo.png", 20, 6, 5, 1000, 800)),
|
||||
|
|
@ -323,12 +340,13 @@ fn main() {
|
|||
|
||||
let mut display = Display::new(DISPLAY_HOST, DISPLAY_PORT);
|
||||
let mut frame_counter: u32 = 0;
|
||||
|
||||
thread::spawn(move || {
|
||||
let bind_address = format!("0.0.0.0:12345");
|
||||
let socket = Socket::new(Domain::IPV4, Type::DGRAM, None).unwrap();
|
||||
socket.set_reuse_address(true).unwrap();
|
||||
//socket.set_nonblocking(true).unwrap();
|
||||
socket.join_multicast_v4(&Ipv4Addr::new(239, 1, 1, 1), &Ipv4Addr::new(0, 0, 0, 0)).unwrap();
|
||||
//socket.join_multicast_v4(&Ipv4Addr::new(239, 1, 1, 1), &Ipv4Addr::new(0, 0, 0, 0)).unwrap();
|
||||
socket.bind(&"0.0.0.0:1234".parse::<SocketAddr>().unwrap().into()).unwrap();
|
||||
// Bind the UDP socket to the specified address and port.
|
||||
let socket: UdpSocket = socket.into();
|
||||
|
|
@ -337,7 +355,7 @@ fn main() {
|
|||
|
||||
// Create a buffer to hold incoming data. 4 bytes for two u16 values.
|
||||
let mut buf = [0u8; 4];
|
||||
|
||||
|
||||
loop {
|
||||
// Wait for a packet to arrive.
|
||||
match socket.recv_from(&mut buf) {
|
||||
|
|
@ -349,12 +367,13 @@ fn main() {
|
|||
// Unpack the buffer into coordinates.
|
||||
if let Some((x_rev, y_rev)) = unpack_coordinates(&buf) {
|
||||
|
||||
println!("Received Coordinates: X = {}, Y = {}", x_rev, y_rev); let x_32:u32 = x_rev.into();
|
||||
println!("Received Coordinates: X = {}, Y = {}", x_rev, y_rev);
|
||||
let x_32:u32 = x_rev.into();
|
||||
let y_32:u32 = y_rev.into();
|
||||
*x_thread.lock().unwrap() = x_32;
|
||||
*y_thread.lock().unwrap() = y_32;
|
||||
|
||||
|
||||
*set_thread.lock().unwrap() = true;
|
||||
|
||||
} else {
|
||||
// This case should ideally not be reached if number_of_bytes is 4.
|
||||
eprintln!("Error: Failed to unpack coordinate data.");
|
||||
|
|
@ -390,7 +409,7 @@ fn main() {
|
|||
frame_counter += 1;
|
||||
|
||||
// A small delay to control the frame rate
|
||||
//std::thread::sleep(Duration::from_millis(16));
|
||||
std::thread::sleep(Duration::from_millis(16));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue