color based on time

This commit is contained in:
Brandon Thomas
2021-01-14 20:41:40 -05:00
parent e01d1500f7
commit 29938fd712
+22 -2
View File
@@ -6,7 +6,7 @@ mod color;
use point::Point; use point::Point;
use std::thread; use std::thread;
use zmq::{Error, Socket, Context, DONTWAIT}; use zmq::{Error, Socket, Context, DONTWAIT};
use std::time::Duration; use std::time::{Duration, SystemTime, UNIX_EPOCH};
use crate::color::Color; use crate::color::Color;
const SOCKET_ADDRESS : &'static str = "tcp://127.0.0.1:8888"; const SOCKET_ADDRESS : &'static str = "tcp://127.0.0.1:8888";
@@ -29,9 +29,11 @@ fn main() {
let mut reconnect = false; let mut reconnect = false;
let mut fail_count = 0; let mut fail_count = 0;
let mut messaging_state = MessagingState::Sending; let mut messaging_state = MessagingState::Sending;
let mut color = Color::Blue;
loop { loop {
let point = Point::at_random_range(-1000.0f32, 1000.0f32, Color::Blue); let color = get_color();
let point = Point::at_random_range(-1000.0f32, 1000.0f32, color);
let bytes = point.to_bytes(); let bytes = point.to_bytes();
//println!("Point : {}", point.debug_string()); //println!("Point : {}", point.debug_string());
@@ -113,4 +115,22 @@ fn reconnect_socket(context: &Context, socket: Socket, address: &str) -> Socket
} }
return socket; return socket;
}
fn get_color() -> Color {
let start = SystemTime::now();
let timestamp = start
.duration_since(UNIX_EPOCH)
.expect("Time should work.");
let seconds = timestamp.as_secs();
match seconds % 10 {
0 | 1 => Color::Black,
2 | 3 => Color::Blue,
4 | 5 => Color::Red,
6 | 7 => Color::Green,
8 | 9 => Color::White,
_ => Color::White,
}
} }