recaman.py

Created by schraf

Created on June 24, 2025

969 Bytes


from turtle import *
from math import copysign
from kandinsky import fill_rect

fill_rect(0,0,320,222,(0,0,0))

def couleur(n):
    couleurs = (255, 0, 0), (255, 127, 0), (255, 255, 0), (0, 255, 0), (0, 0, 255), (127, 0, 255)
    dizaine = n // 10
    index = dizaine % len(couleurs)
    return couleurs[index]

def demi_cercle(x, y):
    rayon = abs(y - x) // 2
    penup()
    goto(x - 150, 0)
    pendown()
    circle(int(rayon * sens), 180)

def suite_recaman(n_terms):
    global orient, sens
    prev, seen = 0, {0}
    for n in range(1, n_terms + 1):
        suiv = prev - n
        if suiv <= 0 or suiv in seen: suiv = prev + n
        seen.add(suiv)
        setheading(orient)
        sens = - copysign(1,orient)
        if suiv < prev: sens = - sens 
        color(couleur(n))
        demi_cercle(3 * prev, 3 * suiv)
        prev = suiv
        orient = - orient
        
        
speed(0)
pensize(2)
orient = -90
suite_recaman(66)
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.