yapalescouleurs
This commit is contained in:
parent
4cec7b86d7
commit
c139f891d7
1 changed files with 21 additions and 14 deletions
33
simulator.py
33
simulator.py
|
@ -1,10 +1,19 @@
|
||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
import typing
|
|
||||||
import time
|
import time
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
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):
|
def parse_speed(text):
|
||||||
|
@ -57,7 +66,7 @@ class Simulator:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
while(True):
|
while True:
|
||||||
with socket.SocketIO(self.s, 'r') as buffer:
|
with socket.SocketIO(self.s, 'r') as buffer:
|
||||||
try:
|
try:
|
||||||
time.sleep(1e-5)
|
time.sleep(1e-5)
|
||||||
|
@ -90,29 +99,27 @@ class Simulator:
|
||||||
|
|
||||||
|
|
||||||
class Douche:
|
class Douche:
|
||||||
colors = [(125, 29, 211), (255, 229, 0)]
|
colors = infinite_colors()
|
||||||
cm = LinearSegmentedColormap.from_list(
|
|
||||||
"Custom", colors, N=42
|
|
||||||
)
|
|
||||||
last_x = None
|
last_x = None
|
||||||
last_y = None
|
last_y = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# We will assume no points are `really` in 3D.
|
# We will assume no points are `really` in 3D.
|
||||||
plt.ion()
|
plt.ion()
|
||||||
fig = plt.figure()
|
self.fig = plt.figure()
|
||||||
self.ax = fig.gca()
|
ax = self.fig.add_subplot(111)
|
||||||
self.xs = []
|
self.xs = []
|
||||||
self.ys = []
|
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):
|
def add_point(self, x, y):
|
||||||
print(x, y)
|
# print(x, y)
|
||||||
self.xs.append(x)
|
self.xs.append(x)
|
||||||
self.ys.append(y)
|
self.ys.append(y)
|
||||||
self.line.set_data(self.xs, self.ys)
|
self.line.set_data(self.xs, self.ys)
|
||||||
plt.draw()
|
self.fig.canvas.draw()
|
||||||
plt.show()
|
self.fig.canvas.flush_events()
|
||||||
|
|
||||||
|
|
||||||
class NaiveSimulator(Simulator, Douche):
|
class NaiveSimulator(Simulator, Douche):
|
||||||
|
|
Loading…
Reference in a new issue