yapalescouleurs

This commit is contained in:
mpboyer 2025-01-15 00:07:34 +01:00
parent 4cec7b86d7
commit c139f891d7

View file

@ -1,10 +1,19 @@
import socket
import os
import typing
import time
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
from colour import Color
c1 = Color("#7d1dd3")
c2 = Color("#ffe500")
colors = list(c1.range_to(c2, 42))
def infinite_colors():
for x in iter(int, 1):
yield colors[x % 42]
def parse_speed(text):
@ -57,7 +66,7 @@ class Simulator:
pass
def loop(self):
while(True):
while True:
with socket.SocketIO(self.s, 'r') as buffer:
try:
time.sleep(1e-5)
@ -90,29 +99,27 @@ class Simulator:
class Douche:
colors = [(125, 29, 211), (255, 229, 0)]
cm = LinearSegmentedColormap.from_list(
"Custom", colors, N=42
)
colors = infinite_colors()
last_x = None
last_y = None
def __init__(self):
# We will assume no points are `really` in 3D.
plt.ion()
fig = plt.figure()
self.ax = fig.gca()
self.fig = plt.figure()
ax = self.fig.add_subplot(111)
self.xs = []
self.ys = []
self.line, = self.ax.plot(self.xs, self.ys)#, color=self.cm)
self.line, = ax.plot(self.xs, self.ys)
def add_point(self, x, y):
print(x, y)
# print(x, y)
self.xs.append(x)
self.ys.append(y)
self.line.set_data(self.xs, self.ys)
plt.draw()
plt.show()
self.fig.canvas.draw()
self.fig.canvas.flush_events()
class NaiveSimulator(Simulator, Douche):
@ -162,7 +169,7 @@ class NaiveSimulator(Simulator, Douche):
z_v = parse_speed(socket.SocketIO(self.s, 'r').readline())
print("Everything parsed")
self.command_spd = np.array([x_v, y_v, z_v])
self.s.send("Realized".encode())
simu = NaiveSimulator("socket.sock")