mirror of
https://github.com/storytold/point-generator.git
synced 2026-10-09 00:09:43 +00:00
color based on time
This commit is contained in:
+22
-2
@@ -6,7 +6,7 @@ mod color;
|
||||
use point::Point;
|
||||
use std::thread;
|
||||
use zmq::{Error, Socket, Context, DONTWAIT};
|
||||
use std::time::Duration;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use crate::color::Color;
|
||||
|
||||
const SOCKET_ADDRESS : &'static str = "tcp://127.0.0.1:8888";
|
||||
@@ -29,9 +29,11 @@ fn main() {
|
||||
let mut reconnect = false;
|
||||
let mut fail_count = 0;
|
||||
let mut messaging_state = MessagingState::Sending;
|
||||
let mut color = Color::Blue;
|
||||
|
||||
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();
|
||||
//println!("Point : {}", point.debug_string());
|
||||
|
||||
@@ -114,3 +116,21 @@ fn reconnect_socket(context: &Context, socket: Socket, address: &str) -> 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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user