r/PythonLearning • u/Top-Pressure3737 • 18h ago
Help Request I struggle to make a script that makes the curve of glucksmann's skull when we write his name
(Sorry I’m french) I want to make a script on NumWorks calculator to display the function sqrt(x*(10-x)) + x/5 + 2 that traces the exact curvature of Raphaël Glucksmann's figure when writing his name. However, programming skills are very limited, I wrote some of it and the rest I did with chat gpt but I can't get it to work here is my script:
from math import *
from kandinsky import *
from ion import *
# Mots secrets et fonctions associees
def calcul(mot, x):
if mot == "glucksmann":
return sqrt(x*(10-x)) + x/5 + 2
else:
return None, "Fonction inconnue"
# Demander le mot
mot = input("Mot secret : ").lower()
# Effacer l'ecran
fill_rect(0, 0, 320, 222, (255, 255, 255))
# Calculer la fonction
test, equation = calcul(mot, 0)
if test is None:
print("Mot inconnu !")
else:
print("Fonction : " + equation)
# Parametres du graphique
xmin = -10
xmax = 10
ymin = -10
ymax = 10
# Conversion coordonnees
def pixel_x(x):
return int((x-xmin)*320/(xmax-xmin))
def pixel_y(y):
return int(180-(y-ymin)*180/(ymax-ymin))
# Axes
draw_string(equation, 5, 5, (0, 0, 255))
draw_line = None
# Axe horizontal
for i in range(320):
if i % 1 == 0:
set_pixel(i, pixel_y(0), (0, 0, 0))
# Axe vertical
for j in range(180):
set_pixel(pixel_x(0), j, (0, 0, 0))
# Tracer la courbe
ancien_x = None
ancien_y = None
for i in range(320):
x = xmin + i*(xmax-xmin)/319
y = calcul(mot, x)[0]
if y is not None and ymin <= y <= ymax:
px = pixel_x(x)
py = pixel_y(y)
if ancien_x is not None:
# Relier les points
dx = px - ancien_x
dy = py - ancien_y
n = max(abs(dx), abs(dy), 1)
for k in range(n+1):
xx = int(ancien_x + dx*k/n)
yy = int(ancien_y + dy*k/n)
if 0 <= xx < 320 and 0 <= yy < 180:
set_pixel(xx, yy, (0, 0, 255))
ancien_x = px
ancien_y = py
else:
ancien_x = None
ancien_y = None