mirror of
https://github.com/NohamR/Stage-2023.git
synced 2026-01-09 23:58:18 +00:00
Initial commit
This commit is contained in:
15
test/color.py
Normal file
15
test/color.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from colour import Color
|
||||
|
||||
def rainbow_gradient(num_colors):
|
||||
colors = []
|
||||
base_color = Color("red")
|
||||
gradient = list(base_color.range_to(Color("violet"), num_colors))
|
||||
for color in gradient:
|
||||
hex_code = color.hex_l
|
||||
colors.append(hex_code)
|
||||
return colors
|
||||
|
||||
num_colors = 10
|
||||
gradient = rainbow_gradient(num_colors)
|
||||
|
||||
print(gradient)
|
||||
45
test/model.py
Normal file
45
test/model.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import time
|
||||
|
||||
t0 = 0
|
||||
tf = 20
|
||||
# tf=3
|
||||
dt = 1
|
||||
t = t0
|
||||
|
||||
|
||||
U = 1.25 # vitesse m.s-¹
|
||||
Wm = 0.3 # distance minimale entre la voiture et celle qui la précède m
|
||||
Ws = 0.9 # m
|
||||
|
||||
ww = np.linspace(0, 10, 200)
|
||||
|
||||
def phi(ww): # prend en entrée la distance entre les deux véhicules
|
||||
PHI = (U*(1 - np.exp(- (ww-Wm)/Ws)))
|
||||
return (ww >= Wm)* PHI # retourne la vitesse du véhicule
|
||||
|
||||
y = np.linspace(0, 0, 11)
|
||||
xxbase = np.linspace(0, 1, 11)
|
||||
|
||||
def position(fposition):
|
||||
dist = np.diff(fposition)
|
||||
vitesses = phi(dist)
|
||||
newv = np.insert(vitesses, 10, 1.25)
|
||||
newp = fposition + newv * dt
|
||||
return newp
|
||||
|
||||
xxold = xxbase.copy()
|
||||
|
||||
while(t<tf):
|
||||
plt.figure(1,figsize=[16,9])
|
||||
plt.clf()
|
||||
plt.xlim([-1,10])
|
||||
xx = position(xxold)
|
||||
color = ['#ff0000', '#ff5300', '#ffa500', '#ffd200', '#ffff00', '#80c000', '#008000', '#004080', '#0000ff', '#2600c1', '#4b0082']
|
||||
plt.scatter(xx, y, c=color)
|
||||
plt.draw()
|
||||
# plt.savefig(str(t)+'.png')
|
||||
plt.pause(0.1)
|
||||
t += dt
|
||||
xxold = xx.copy()
|
||||
BIN
test/phi(ww).png
Normal file
BIN
test/phi(ww).png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 133 KiB |
18
test/phi(ww).py
Normal file
18
test/phi(ww).py
Normal file
@@ -0,0 +1,18 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
U = 1.25 # vitesse m.s-¹
|
||||
Wm = 0.3 # distance minimale entre la voiture et celle qui la précède m
|
||||
Ws = 0.9 # m
|
||||
ww = np.linspace(0, 10, 200)
|
||||
|
||||
def phi(ww):
|
||||
PHI = (U*(1 - np.exp(- (ww-Wm)/Ws)))
|
||||
return (ww >= Wm)* PHI
|
||||
|
||||
plt.figure(figsize=[16,9])
|
||||
plt.xlabel('distance w en m')
|
||||
plt.ylabel('vitesse en m.s-¹')
|
||||
plt.plot(ww, phi(ww))
|
||||
plt.savefig('phi(ww).png', dpi=300)
|
||||
plt.show()
|
||||
59
test/polaire.py
Normal file
59
test/polaire.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import time
|
||||
|
||||
t0 = 0
|
||||
tf = 100
|
||||
dt = 0.5
|
||||
t = t0
|
||||
|
||||
U = 1.25 # vitesse m.s-¹
|
||||
Wm = 0.3 # distance minimale entre la voiture et celle qui la précède m
|
||||
Ws = 0.9 # m
|
||||
|
||||
def phi(ww): # prend en entrée la distance entre les deux véhicules
|
||||
PHI = (U*(1 - np.exp(- (ww-Wm)/Ws)))
|
||||
return (ww >= Wm)* PHI # retourne la vitesse du véhicule
|
||||
|
||||
y = np.linspace(1, 1, 11)
|
||||
xxbase = np.linspace(0, 1, 11)
|
||||
|
||||
def position(fposition, newv):
|
||||
newp = fposition + newv * dt
|
||||
return newp
|
||||
|
||||
def vitesses(fposition):
|
||||
print('fposition', fposition)
|
||||
dist = np.diff(fposition)
|
||||
print('distance : ', dist)
|
||||
vitesses = phi(dist)
|
||||
newv = np.insert(vitesses, 10, 1.25)
|
||||
return newv
|
||||
|
||||
xxold = xxbase.copy()
|
||||
|
||||
while(t<tf):
|
||||
plt.figure(1,figsize=[16,9])
|
||||
plt.clf()
|
||||
|
||||
nb = 360
|
||||
|
||||
r=np.linspace(1,1,nb)
|
||||
theta=np.linspace(0,2*np.pi,nb)
|
||||
|
||||
plt.polar(theta, r)
|
||||
# plt.scatter(1*np.pi, 0.5)
|
||||
|
||||
vt = vitesses(xxold)
|
||||
print('vitesses : ', vt)
|
||||
|
||||
xx = position(xxold, vt)
|
||||
print('position : ', xx)
|
||||
|
||||
color = ['#ff0000', '#ff5300', '#ffa500', '#ffd200', '#ffff00', '#80c000', '#008000', '#004080', '#0000ff', '#2600c1', '#4b0082']
|
||||
plt.scatter(xx/10*np.pi, y, c=color)
|
||||
|
||||
plt.draw()
|
||||
plt.pause(0.00001)
|
||||
t += dt
|
||||
xxold = xx.copy()
|
||||
34
test/status.py
Normal file
34
test/status.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from colour import Color
|
||||
|
||||
def rainbow_gradient(distances):
|
||||
num_colors = len(distances)
|
||||
colors = []
|
||||
base_color = Color("green")
|
||||
target_color = Color("red")
|
||||
|
||||
luminance_start = base_color.get_luminance()
|
||||
luminance_end = target_color.get_luminance()
|
||||
|
||||
for i in range(num_colors):
|
||||
moydist = distances[i]
|
||||
t = i / (num_colors - 1) # Interpolation paramètre t
|
||||
|
||||
adjusted_luminance = luminance_start + (luminance_end - luminance_start) * (1 - t) * (moydist - 1) / 18
|
||||
color = Color(rgb=(base_color.rgb[0] * (1 - t) + target_color.rgb[0] * t,
|
||||
base_color.rgb[1] * (1 - t) + target_color.rgb[1] * t,
|
||||
base_color.rgb[2] * (1 - t) + target_color.rgb[2] * t))
|
||||
color.set_luminance(adjusted_luminance)
|
||||
|
||||
hex_code = color.hex_l
|
||||
colors.append(hex_code)
|
||||
|
||||
return colors
|
||||
|
||||
distances = [0.05263158, 0.05263158, 0.05263158, 0.05263158, 0.05263158,
|
||||
0.05263158, 0.05263158, 0.05263158, 0.05263158, 0.05263158,
|
||||
0.05263158, 0.05263158, 0.05263158, 0.05263158, 0.05263158,
|
||||
0.05263158, 0.05263158, 0.05263158, 19.0]
|
||||
|
||||
gradient = rainbow_gradient(distances)
|
||||
|
||||
print(gradient)
|
||||
Reference in New Issue
Block a user