donut.py

Created by alex-juge84

Created on April 01, 2020

1.43 KB


#Import Modules
from math import *
from turtle import *
from random import *


# Tracé d'une épicycloïde
# ou d'une hippocycloïde (si rayon négatif)

#----------------------------
# Le nom du script(donut)
# vient du fait
# qu'avec des rayons (PPCM) suffisament
# éloignés, la figure tend 
# vers une forme en 'donut'
#------------------------------

#------------------------------
#Liste des combinaisons de paramètres interessantes
# (21,31,0.5,30) Donut classique
# (31,41,0.5,41) Grand Donut
# (15,21,0.5,9)  Rosace
# (31,32,0.5,10) Anneaux 
# (61,11,0.5,2)  Soleil 
#------------------------------

def epi(r1,r2,pas,tours) :
  penup()
  speed(10)
  
  inc = pas * pi / 180 #conversion radians
  rapport = r1 / r2 #Thalès
  angle1 = 0 #setup angles départ
  angle2 = pi 
  
  #Test valeurs incorrectes
  if pas <= 0.1 or tours < 1 :
    return("Valeurs incorrectes")
    
  
  while angle1 < (2 * pi * tours) :
    

    angle1 = angle1 + inc  #avancéee angle petit cercle
    
    #Calcul des coordonées dans le cercle 1
    x1 = cos(angle1) * (r1 + r2)
    y1 = sin(angle1) * (r1 + r2)
    

    angle2 = angle2 - (inc * rapport) #avancée angle grand cercle
    
    #Calcul des coordonées du point 
    #qui va être tracé (cercle 2)
    x2 = (cos(angle2) * r2) + x1
    y2 = (sin(angle2) * r2) + y1
    
    #Tracé du points
    color(100, 100, 255)
    goto(x2, y2) 
    pendown()
    
  hideturtle()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.