π
<-
Chat plein-écran
[^]

Scripts concours dessin Noël Casio Graph Python

Scripts concours dessin Noël Casio Graph Python

Message non lude critor » 19 Jan 2021, 10:45

Du 9 au 15 Décembre 2020, Casio France avait organisé à l'attention des enseignants un concours de Noël fort intéressant et joliment doté.
Il fallait programmer un dessin de Noël au choix :
  • sur calculatrice fx-92+ Spéciale Collège ou son émulateur (langage à la Scratch/Logo)
  • en Python sur Graph 35+E II, Graph 90+E ou leur émulateur

13237Nous t'avions partagé les scripts Python Graph 90+E gracieusement fournis par 3 participants dont les 2 grands gagnants. :D

Florian Allard alias Afyu, grand gagnant, utilisait le module de tracés relatifs turtle sur Graph 90+E.

Il nous dessinait une scène de Noël très complète. Tout y était, exploitant à fond le large écran de la Graph 90+E : :bj:
  • le sapin décoré de guirlandes et coiffé d'une étoile
  • le renne tirant un traineau recevant une pluie de cadeaux

Etaient tracés dans l'ordre par le code ci-après :
  1. le renne avec :
    1. sa patte arrière droite
    2. son dos
    3. ses oreilles
    4. ses bois
    5. sa tête
    6. son torse
    7. sa patte avant droite
    8. sa patte avant gauche
    9. son abdomen
    10. sa patte arrière gauche
  2. le traineau
  3. le harnais
  4. le sapin avec :
    1. son feuillage
    2. ses guirlandes
    3. ses boules
    4. son étoile
  5. les 4 paquets cadeaux avec pour chacun :
    1. la boîte
    2. le ruban

Remarquable, on ne repérait quasiment pas d'élément géométrique remarquable, témoin du soin et de la précision apportés au tracé ! :bj:

Code: Tout sélectionner
from turtle import *
hideturtle()
penup()
goto(-110,-50)
pendown()
#4  me patte
rt(40)
penup()
for i in range(30):
  fd(1/4)
  lt(1/2)
pendown()
for i in range(30):
  fd(1)
  rt(3-i/15)
for j in range(4):
  for i in range(10):
    fd(1/2)
    lt(3)
  lt(60)
lt(120)
for i in range(10):
  fd(1/2)
  rt(3)
lt(110)
for i in range(20):
  fd(1)
  rt(1.5)
#fd(30)
lt(50)
for i in range(25):
  fd(0.6)
  rt(2)
for i in range(15):
  fd(1)
  lt(3)
for i in range(30):
  rt(12)
  fd(1/2)
for i in range(15):
  fd(1)
  lt(4)
for i in range(30):
  fd(1)
  rt(i//10)
lt(30)
for i in range(40):
  fd(1/2)
  rt(i//10)
setheading(0)
penup()
fd(-15/2)
pendown()#les oreilles
for i in range(40):
  fd(((400-10*i)//160)/2)
  lt(4)
lt(290)
#for i in range(42):
  #fd((10*i)//160)
  #lt(4.2)
#penup()
#for i in range(42):
  #fd(-(10*(28-i))//160)
  #lt(-4.2)
#pendown()
for i in range(40):
  fd(((10*i)//160)/2)
  lt(4)
penup()
rt(90)
#fd(5)
lt(90)
fd(-5/2)
pendown()
#les bois
#penup()
rt(110)
fd(1)
#pendown()
rt(90)
for i in range(20):
  fd(1)
  rt(1)
lt(20)
for j in range(3):
  rt(90)
  #for i in range(20):
    #fd(3)
    #lt(2+20-2*i)
  for i in range(10):
    fd(3/2)
    lt(2+10-i)
  for i in range(4):
    fd(1/2)
    lt(36)
  lt(10)
  for i in range(9):
    fd(1)
    rt(1+2*i)
lt(40)   
for i in range(80):
  fd(1/2)
  rt(2)
for i in range(10):
  fd(1/2)
  lt(18)
for i in range(30):
  fd(1/2)
  lt(1)
for i in range(20):
  fd(1/2)
  rt(3)
#fin des bois
penup()
setheading(-90)
fd(15/2)
lt(90)
fd(1)
pendown()
setheading(240)
pensize(2)
for j in range(2):
  for i in range(40):
    fd(1/12)
    rt(3)
  rt(60)
pensize(1)
setheading(90)
penup()
fd(15/2)
lt(90)
fd(1)
lt(75)

pendown()
rt(60)
for i in range(20):
  fd(1/2)
  lt(2)
lt(40)
for i in range(30):
  fd(1/2)
  rt((30-i)//7)
lt(70)
for j in range(4):
  for i in range(10):
    fd(1/2)
    lt(5)
  lt(40)
rt(0)
#for j in [1,-1]:
  #for i in range(30):
    #fd(j)
    #lt(4*j)
fd(5/2)
rt(50)
fd(1)
lt(70)
for i in range(25):
  fd(1)
  lt((50-5*i)/3.7)
lt(70)
for j in range(2):
  for i in range(10):
    fd(1)
    rt(2)
  lt(40)
rt(50)
fd(7/2)
fd(-7/2)
rt(40)
#1  re patte
for j in range(2):
  for i in range(30):
    fd(1/2)
    rt(1)
  lt(70)
lt(20)
fd(5)
rt(200)
for j in range(4):
  for i in range(10):
    fd(1/2)
    lt(3)
  lt(60)
lt(100)
for j in range(2):
  for i in range(30):
    fd(-1/2)
    rt(-1)
  rt(70)
  penup()
#2  me patte
#lt(90)
fd(15/2)
#pendown()
lt(100)
pendown()
for j in range(2):
  for i in range(30):
    fd(1/2)
    rt(1)
  lt(50)
lt(30)
fd(5)
rt(190)
for j in range(4):
  for i in range(10):
    fd(1/2)
    lt(3)
  lt(60)
lt(100)
for j in range(2):
  for i in range(30):
    fd(-1/2)
    rt(-1)
  rt(60)
#bas du corps
rt(90)
fd(5/2)
fd(-5/2)
rt(120)
for i in range(50):
  fd(1/2)
  lt(1/4)
lt(90)
penup()
fd(15/2)
pendown()
rt(190)
#3  me patte
for i in range(40):
  fd(1/2)
  lt(2-i/20)
rt(0)
for i in range(30):
  fd(1/2)
  rt((100-3*i)/30)
lt(0)
for j in range(4):
  for i in range(10):
    fd(1/2)
    lt(3)
  lt(60)
lt(120)
for i in range(10):
  fd(1/2)
  rt(3)
lt(90)
for i in range(30):
  fd(1/2)
  lt(1)
lt(10)
for i in range(30):
  fd(1/2)
  rt(1+i//15)
rt(20)
for i in range(30):
  fd(1/2)
  lt(1+i//15)



from turtle import *
hideturtle()
penup()
setheading(0)
pencolor([120/255,60/255,0])
pensize(3)
goto(-80,-40)
pendown()
rt(35)
for i in range(45):
  fd(1/2)
  rt(1)
rt(90)
#bois
pensize(3)
pencolor([120/255,60/255,0])
for i in range(30):
  fd(1)
  lt(6)
rt(10)
fd(5)
lt(90)

for i in range(4):
  fd(10)
  rt(90)
  fd(3.5)
  rt(90)
  fd(10)
  lt(90)
  fd(20)
  lt(90)

rt(90)
for i in range(10):
  fd(0.6)
  rt(18)

fd(47*2+5)

for i in range(28):
  fd(1.45)
  rt(6)

rt(84)
for i in range(20):
  fd(1/2)
  rt(1)
fd(7/2)

setheading(0)
fd(90)

#arri  re
lt(90)
for i in range(30):
  fd(3/2)
  rt(i//10)

setheading(0)
for i in range(17):
  fd(1/2)
  lt(10)
fd(3/2)
penup()
fd(-3/2)
for i in range(17):
  fd(-1/2)
  lt(-10)
pendown()
setheading(160)
for i in range(38):
  fd(3)
  lt((15-i)/2)
for i in range(40):
  fd(1/2)
  lt((15-i))
 
penup()
setheading(0)
fd(105)
lt(90)
fd(20)
pendown()

setheading(160)
for i in range(38):
  fd(3)
  lt((15-i)/2)
for i in range(42):
  fd(1/2)
  lt((15-i))

lt(70)
fd(15/2)

pensize(2)
setheading(203)
for i in range(34):
  fd(3)
  rt(2-i/40)



from turtle import *
setheading(-30)
penup()
goto(110,-80)
hideturtle()
#pendown()
pencolor([0,205/255,0])
pensize(2)
for k in [-1,1]:
  penup()
  goto(110,-80)
  setheading(90)
  fd(15)
  setheading(90-120*k)
  fd(16)
  pendown()
  for j in range(4):
    for i in range(30):
      fd(1-j/5)
      lt(k*(1+i//20))
    rt(50*k)
    for i in range(10):
      fd(-1+j/5)
      lt(k*(-1-i//20))

    lt(50*k)
    for i in range(50):
      fd(1-j/5)
      lt(k*(i/30))
    rt(40*k)
    for i in range(40):
      fd(-1+j/5)
      lt(k*(-i//20))

    lt(70*k)
    for i in range(10):
      fd(1-j/5)
      lt(k*(1+i//20))
    rt(30*k)
    for i in range(40):
      fd(-1+j/5)
      lt(k*(-1-i//30))
    setheading(90-90*k-30*k+30*j*k)
  setheading(90-50*k)
  for i in range(30):
    fd(1/2)
    lt(k*(1+i//20))
  rt(40*k)
  for i in range(20):
    fd(-1/3)
    lt(k*(-1-i//20))

  lt(50*k)
  for i in range(30):
    fd(1/2)
    lt(k*(i/10))
  rt(60*k)
  for i in range(30):
    fd(-1/3)
    lt(k*(i/20))

  lt(20*k)
  for i in range(30):
    fd(1/2)
    lt(k*(1+i//20))
#guirlandes
penup()
goto(120,50)
pendown()
pencolor([1,0,0])

setheading(-140)
for i in range(6):
  pensize(5)
  fd(3)
  pensize(2)
  fd(3)
  rt(5)

setheading(-50)
for i in range(10):
  pensize(5)
  fd(3)
  pensize(2)
  fd(3)
  lt(6)
 
setheading(-150)
for i in range(12):
  pensize(5)
  fd(3)
  pensize(2)
  fd(3)
  rt(4)
 
setheading(-60)
for i in range(13):
  pensize(5)
  fd(3)
  pensize(2)
  fd(3)
  lt(6)
 
setheading(-120)
for i in range(15):
  pensize(5)
  fd(3)
  pensize(2)
  fd(3)
  rt(6)
 
setheading(-50)
for i in range(13):
  pensize(5)
  fd(3)
  pensize(2)
  fd(3)
  lt(6)

#boules
from random import randint
for coord in [(17,32),(-17,24),(-60,-10),(15,0),(-30,-40),(40,-50)]:
  penup()
  goto(coord[0]+110,coord[1]-10)
  pensize(20)
  pencolor([randint(1,10)/10,randint(1,10)/10,randint(1,10)/10])
  pendown()
  fd(1)

#etoile
penup()
goto(100,80)
pendown()
pencolor([220/255,220/255,40/255])
pensize(5)
setheading(0)
for i in range(5):
  fd(20)
  rt(72*2)




#paquets
from random import randint
for coord in [(0,20),(-30,-10),(-70,10),(-30,50)]:
  penup()
  goto(coord[0],coord[1])
  pendown()
  pensize(7/2)
  pencolor([randint(1,10)/10,randint(1,10)/10,randint(1,10)/10])
  setheading(randint(1,60)-30)
  for i in range(4):
    fd(20)
    lt(90)
  fd(20)
  lt(45)
  fd(15/2)
  lt(45)
  fd(20)
  lt(135)
  fd(15/2)
  fd(-15/2)
  rt(45)
  fd(20)
  lt(45)
  fd(15/2)
 
 
  penup()
  lt(45)
  pencolor([randint(1,10)/10,randint(1,10)/10,randint(1,10)/10])
  pensize(7/2)
  fd(10)
  #pendown()
  lt(90)
  fd(20)
  lt(45)
  fd(15/2)
 
  fd(-7/2)
  pendown()
  pensize(5/2)
  lt(45)
  fd(-10)
  fd(20)
  lt(90)
  fd(20)
  fd(-20)
  rt(90)
  fd(-10)
  rt(45)
  pensize(7/2)
  penup()
  fd(-4)
  rt(45)
  fd(-10)
  pendown()
  lt(90)
  fd(-10)
  fd(20)
  #ruban
  rt(45)
  fd(7/2)
  rt(15)
  for j in range(2):
    for i in range(30):
      fd(1/2)
      lt(2)
    lt(120)
    for i in range(30):
      fd(1/2)
      lt(2)
    rt(180)

13236Thomas Fontaine, 2ème grand gagnant qui s'était déjà illustré au 3ème défi de notre concours de rentrée 2019, utilise également le module turtle sur Graph 90+E.

Il nous dessinait cette fois-ci un buste de renne.

Un tracé façon 3D fil de fer, décomposant très artistiquement le tout en triangles et quadrilatères telle une sculpture sur bois.

Le script profitait avantageusement en taille de la symétrie verticale, n'ayant donc à décrire que le demi-buste qui sera itéré 2 fois.

Le plus remarquable était qu'une fois le tracé de chaque demi-buste commencé après un goto() et un couple penup/pendown() initial, à aucun moment la tortue ne se téléportait ou ne levait le stylo, superbe arabesque ! :D

Sur chaque demi-buste, étaient tracés dans l'ordre par le code reproduit ci-après:
  1. tête
  2. oreille
  3. cou
  4. poitrail
  5. bois

Code: Tout sélectionner
from turtle import *
pensize(2)
for k in [-1,1]:
  penup()
  goto(0,-50)
  pendown()
  hideturtle()

  setheading(90-90*k+30*k)
  fd(19)
  lt(90*k)
  fd(10)

  lt(60*k)
  fd(10)
  fd(-10)
  lt(40*k)
  fd(12)
  fd(-12)
  rt(100*k)

  rt(15*k)
  fd(10)
  rt(15*k)
  fd(10)
  rt(40*k)
  fd(15)
  lt(140*k)
  fd(17)
  fd(-17)
  rt(40*k)
  fd(20)
  fd(-20)
  rt(100*k)
  #oreille
  lt(15*k)
  fd(10)
  lt(60*k)
  fd(7)
  lt(100*k)
  fd(7)
  fd(-7)
  rt(210*k)
  fd(25)
  rt(163*k)
  fd(25)
  fd(-25)
  lt(48*k)
  fd(8)
  rt(65*k)
  fd(20)
  fd(-20)
  lt(50*k)
  fd(20)
  rt(115*k)
  fd(15)
  fd(-15)
  lt(30*k)
  fd(16)
  fd(-16)
  lt(30*k)
  fd(13)

  lt(90*k)
  fd(5)
  rt(110*k)
  fd(10)
  lt(30*k)
  fd(10)
  fd(-10)
  rt(30*k)
  fd(-10)
  lt(90*k)
  fd(20)
  rt(120*k)
  fd(7)
  lt(10*k)
  fd(12)
  fd(-12)
  rt(10*k)
  fd(-7)
  lt(130*k)
  fd(9)

  rt(60*k)
  fd(5)
  lt(45*k)
  fd(50)

  rt(165*k)
  fd(52)
  fd(-52)
  lt(165*k)
  #cou
  lt(140*k)
  fd(35)
  lt(70*k)
  fd(42)
  fd(-42)
  rt(30*k)
  fd(29)
  lt(45*k)
  fd(32)

  rt(40*k)
  fd(5)
  lt(22*k)
  fd(13)
  lt(20*k)
  fd(15)
  lt(40*k)
  fd(11)
  lt(108*k)
  fd(49)
  fd(-49)
# on est en haut de la tete
#bois
  rt(108*k)
  fd(-13)
  #debut des bois
  rt(110*k)
  fd(10)
  lt(90*k)
  fd(6)
  fd(-6)
  rt(130*k)
  fd(30)
  lt(90*k)
  fd(5)
  fd(-5)
  rt(60*k)
  fd(20)
  lt(90*k)
  fd(5)
  fd(-5)
  rt(40*k)
  fd(25)
  lt(165*k)
  fd(25)
  rt(43*k)
  fd(15)
  rt(24*k)
  fd(20)
  fd(-20)
  rt(120*k)
  fd(15)
  lt(90*k)
  fd(5)
  fd(-5)
  rt(45*k)
  fd(25)
  lt(165*k)
  fd(25)
  rt(45*k)
  fd(15)
  rt(45*k)
  fd(5)
  rt(90*k)
  fd(10)
  lt(90*k)
  fd(4)
  fd(-4)
  rt(120*k)
  fd(15)
  lt(165*k)
  fd(15)
  lt(30*k)
  fd(15)
  rt(75*k)
  fd(15)
  fd(-5)
  rt(70*k)
  fd(12)
  lt(160*k)
  fd(12)
  rt(30*k)
  fd(10)

1323413235Voici ci-contre ma propre participation, une forêt de Noël, envoyée juste pour le plaisir. ;)
Je ne souhaitais piquer de lot à personne et je l'ai bien dit, et c'est parfait puisque je gagne bien le seul lot de participation. :)

Ce script disposait d'un mode monochrome, et était compatible à la fois Graph 35+E II et Graph 90+E, même si c'était sur cette dernière qu'il révélait son plein potentiel.

Voici l'astuce utilisée pour détecter le type d'écran :
Code: Tout sélectionner
def init_casioplot():
  global color_screen, screen_w, screen_h
  set_pixel(0, 0, (0, 0, 255))
  col = get_pixel(0, 0)
  color_screen = col[0] != col[2]
  screen_w, screen_h = color_screen and (384, 192) or (128, 64)


Dans l'ordre, mon script utilisant la bibliothèque de tracé par pixels casioplot :
  1. faisait tomber la nuit : Il utilise ici 2 dégradés dans les tons de bleu pour représenter le sol et le ciel.
  2. allumait les étoiles (pixels blancs)
  3. plantait une forêt de sapins - nous allons y revenir
  4. décorait mon plus beau sapin : des disques de rayon 2 selon 3 couleurs de remplissage alternées, avec une couleur voisine pour la bordure rajoutant un peu de relief
  5. saupoudrait le tout de neige : des disques de rayon 1

La bibliothèque casioplot offre un nombre assez restreint de fonctions de tracé :
  • clear_screen() pour effacer l'écran en blanc
  • set_pixel(x,y,couleur) pour allumer un pixel dans une couleur (R,G,B) au choix
  • draw_string(x,y,string,couleur,taille) pour écrire du texte dans une couleur RGB et selon une taille de police au choix ("small", "medium" ou "large")

Ce n'est absolument pas un défaut, au contraire cela permet un travail absolument passionnant : la construction et optimisation de fonctions pour tracer chaque primitive. J'avais donc rajouté de quoi tracer des cercles, disques, mais également segments pour les sapins :
Code: Tout sélectionner
def draw_line(x1, y1, x2, y2, c):
  m, a1, b1, a2, b2 = 0, int(x1), int(y1), int(x2), int(y2)
  if (x2 - x1) ** 2 < (y2 - y1) ** 2:
    m, a1, a2, b1, b2 = 1, b1, b2, a1, a2
  if min(a1, a2) != a1: a1, b1, a2, b2 = a2, b2, a1, b1
  for k in range(a2 - a1 + 1):
    a, b = a1 + k, int(b1 + (b2 - b1) * k / ((a2 - a1) or 1))
    set_pixel((a, b)[m], (b, a)[m], c)

def draw_ellipse(x, y, rx, ry, c):
  for h in range(-int(ry), int(ry)+1):
    w = sqrt(max(0, rx*rx*(1-h*h/ry/ry)))
    x1, x2 = int(x - w), int(x + w)
    yc = int(y + h)
    set_pixel(x1, yc, c)
    set_pixel(x2, yc, c)
  for w in range(-int(rx), int(rx)+1):
    h = sqrt(max(0, ry*ry*(1-w*w/rx/rx)))
    y1, y2 = int(y - h), int(y + h)
    xc = int(x + w)
    set_pixel(xc, y1, c)
    set_pixel(xc, y2, c)

def fill_ellipse(x, y, rx, ry, c):
  for h in range(-int(ry), int(ry)+1):
    w = sqrt(max(0, rx*rx*(1-h*h/ry/ry)))
    x1, x2 = int(x - w), int(x + w)
    yc = int(y + h)
    draw_line(x1, yc, x2, yc, c)

def draw_circle(x, y, r, c):
  draw_ellipse(x, y, r, r, c)

def fill_circle(x, y, r, c):
  fill_ellipse(x, y, r, r, c)


La construction des sapins utilisait des similitudes, transformations géométriques conservant les rapports de distances.
Une similitude peut se décomposer en une isométrie (transformation conservant les distances : translation, rotation, ...) la plupart du temps suivie d'une homothétie (agrandissement ou réduction).

Plus précisément, en partant d'un couple de seulement 2 points que l'on va appeler le tronc, 5 similitudes étaient appliquées pour créer 5 branches (en bas à gauche, à gauche, en haut, à droite, en bas à droite).

En itérant le même processus sur chacune de ces branches, on faisait ainsi pousser l'arbre, le développant dans ces 5 directions.

Par exemple, sur la capture couleur ci-contre, nous avons de gauche à droite des arbres avec :
  • 1 itération
  • 3 itérations
  • 5 itérations (profitant pleinement des 1 Mio de mémoire de tas Python ;) )
  • 4 itérations
  • 3 itérations

Pour l'exécution sur Graph 35+E II nous avions dû limiter le nombre d'itérations afin de ne pas exploser la mémoire de tas Python (heap) ici limitée à 100 Kio. Nous avons ici de gauche à droite :
  • 0 itération (donc le tronc initial nu)
  • 1 itération (donc le tronc avec ses 5 branches initiales)
  • 3 itérations
  • 2 itérations
  • 0 itération

Code: Tout sélectionner
from math import pi, sin, cos, exp, sqrt
import matplotlib.pyplot as plt
from random import *
from casioplot import *

def init_casioplot():
  global color_screen, screen_w, screen_h
  set_pixel(0, 0, (0, 0, 255))
  col = get_pixel(0, 0)
  color_screen = col[0] != col[2]
  screen_w, screen_h = color_screen and (384, 192) or (128, 64)

def transform(x, y):
  f = screen_h * 45 // 64
  return (x*f,screen_h-1-y*f)

def draw_line(x1, y1, x2, y2, c):
  m, a1, b1, a2, b2 = 0, int(x1), int(y1), int(x2), int(y2)
  if (x2 - x1) ** 2 < (y2 - y1) ** 2:
    m, a1, a2, b1, b2 = 1, b1, b2, a1, a2
  if min(a1, a2) != a1: a1, b1, a2, b2 = a2, b2, a1, b1
  for k in range(a2 - a1 + 1):
    a, b = a1 + k, int(b1 + (b2 - b1) * k / ((a2 - a1) or 1))
    set_pixel((a, b)[m], (b, a)[m], c)

def draw_ellipse(x, y, rx, ry, c):
  for h in range(-int(ry), int(ry)+1):
    w = sqrt(max(0, rx*rx*(1-h*h/ry/ry)))
    x1, x2 = int(x - w), int(x + w)
    yc = int(y + h)
    set_pixel(x1, yc, c)
    set_pixel(x2, yc, c)
  for w in range(-int(rx), int(rx)+1):
    h = sqrt(max(0, ry*ry*(1-w*w/rx/rx)))
    y1, y2 = int(y - h), int(y + h)
    xc = int(x + w)
    set_pixel(xc, y1, c)
    set_pixel(xc, y2, c)

def fill_ellipse(x, y, rx, ry, c):
  for h in range(-int(ry), int(ry)+1):
    w = sqrt(max(0, rx*rx*(1-h*h/ry/ry)))
    x1, x2 = int(x - w), int(x + w)
    yc = int(y + h)
    draw_line(x1, yc, x2, yc, c)

def draw_circle(x, y, r, c):
  draw_ellipse(x, y, r, r, c)

def fill_circle(x, y, r, c):
  fill_ellipse(x, y, r, r, c)

def horiz_gradient(x, y, w, h, col1, col2):
  for k in range(h):
    draw_line(x, y + k, x + w - 1, y + k, [col1[i] + (col2[i] - col1[i])*k//(h-1) for i in range(3)])

def cmath_exp(a):
  return exp(a.real) * (cos(a.imag) + 1j*sin(a.imag))

def similitude(u, v):
    v = 1j * (u - v)
    return lambda z: v*z + u

def generer_arbre(n):
  lf = (
    similitude(.2j, .2j + .5*cmath_exp(1j * pi / 7)),
    similitude(.22j, .22j + .45j*cmath_exp(1j * pi / 3)),
    similitude(.55j, .55j + .35*cmath_exp(1j * pi / 6)),
    similitude(.57j, .57j + .3j*cmath_exp(1j * pi / 3)),
    similitude(.7j, 1.2j - .01)
  )
  lz = [0j, 0.7j]
  lz1 = lz[:]
  for _ in range(n):
    lz2 = []
    for f in lf:
      lz2.extend([f(z) for z in lz1])
    lz.extend(lz2)
    lz1 = lz2
  return lz

def rotate_color(c):
  return (c[1], c[2], c[0])
   
def trace(d, nb_trees, nb_balls, nb_stars, nb_flakes):

  color_black = (0,) * 3
  color = color_screen and (255,) * 3 or color_black

  # fait tomber la nuit
  colors = (color_black, (0, 0, 127), (0, 127, 255))
  dy = screen_h / (len(colors))
  if color_screen:
    for k in range(len(colors) - 1):
      horiz_gradient(0, round(dy*k), screen_w, round(dy), colors[k], colors[k + 1])
    horiz_gradient(0, screen_h - 1 - round(dy), screen_w, round(dy), (0, 63, 127), color_black)
  dx = (screen_w - 1) / 2 / (nb_trees - 1)

  # allume les etoiles
  for k in range(nb_stars):
    set_pixel(randint(0, screen_w - 1), randint(0, screen_h - 1 - round(dy)), color)

  # plante une foret de sapins
  for p in range(d - nb_trees, d + 1):
    x0 = screen_w // 2 + (p < d and dx * ((d - p) % 2 and d + 1 - p or p - d))
    dy = screen_h / (len(colors)) * (d - p) / nb_trees
    lz = generer_arbre(p)
    for k in range(0, len(lz), 2):
      x1, y1 = transform(lz[k].real, lz[k].imag)
      x2, y2 = transform(lz[k+1].real, lz[k+1].imag)
      x1 += x0
      x2 += x0
      draw_line(x1, y1 - dy, x2, y2 - dy, (0, 160 * (1 - (d - p)//(nb_trees - 1)), 0))

  # decore mon plus beau sapin
  if color_screen:
    lz, r, color_in, color_out = lz[1::max(1, len(lz)//nb_balls)], 2, (0, 255, 255), (0, 0, 255)
    for z in lz:
      x, y = transform(z.real, z.imag)
      x += x0
      fill_circle(x, y, r, color_in)
      draw_circle(x, y, r, color_out)
      color_in, color_out = rotate_color(color_in), rotate_color(color_out)

  # saupoudre de neige
  if color_screen:
    for k in range(nb_flakes):
      fill_circle(randint(0, screen_w - 1), randint(0, screen_h - 1), 1, color)

init_casioplot()
trace(color_screen and 5 or 3, 5, 30, 100, 40)
show_screen()

Et puis c'était tout. Nous supposions qu'il y avait eu plus que 3 participants, mais les autres ne nous avaient à la différence et à notre connaissance rien partagé, ni en public ni en privé. :'(

13442Et bien tu n'attendras pas plus longtemps, Casio nous publie enfin aujourd'hui les scripts Python du concours. Et voici donc de suite ceux qui nous manquaient. :)

Isabelle Vanacker retourne à l'utilisation du module turtle et nous dresse un sapin sous une nuit étoilée.

On note la répétition de motifs identiques ou similaires (étoiles et triangles du sapin).

Mais c'est codé proprement puisque les répétitions sont tracées par appels d'une même fonction.

Voici par exemple la fonction pour les triangles du feuillage du sapin, en fait des triangles rectangles isocèles :
Code: Tout sélectionner
def triangle(t):
  forward(t/2)
  left(135)
  forward(sqrt((t*t)/2))
  left(90)
  forward(sqrt((t*t)/2))
  left(135)
  forward(t/2)


Ou encore la fonction pour les étoiles :
Code: Tout sélectionner
def etoile(x,y):
  up()
  goto(x,y)
  down() 
  for i in range(6):
    forward(10)
    left(120)
    forward(10)
    left(-60)



Le script suivant trace donc dans l'ordre :
  1. le sapin avec :
    1. les triangles de son feuillage, de haut en bas
    2. son tronc
  2. les étoiles

Code: Tout sélectionner
from turtle import *

pencolor("green")
pensize(5)

def triangle(t):
  forward(t/2)
  left(135)
  forward(sqrt((t*t)/2))
  left(90)
  forward(sqrt((t*t)/2))
  left(135)
  forward(t/2)

def arbre():
  pencolor("green")
  pensize(5)
  for i in range(4):
    triangle(50+20*i)
    up()
    goto(0,30-40*i)
    down()
  pencolor("brown")
  forward(10)
  left(90)
  forward(40)
  left(90)
  forward(20)
  left(90)
  forward(40)
  left(90)
  forward(10)

def etoiles():
  pencolor("yellow")
  pensize(2)
  etoile(-150,60)
  etoile(-100,10)
  etoile(-120,-40)
  etoile(-60,-80)
  etoile(100,50)
  etoile(140,30)
  etoile(160,-30)
  etoile(100,-70)
   
def etoile(x,y):
  up()
  goto(x,y)
  down() 
  for i in range(6):
    forward(10)
    left(120)
    forward(10)
    left(-60)

up()
goto(0,60)
down()
arbre()

up()
goto(-50,20)
down()
etoiles()

13441Et voici enfin le cadeau offert par Isabelle Duval, toujours tracé avec le module turtle sur Graph 90+E.

Son script suivant trace dans l'ordre :
  1. la boîte
  2. le ruban avec :
    1. son noeud
    2. le reste

Code: Tout sélectionner
from turtle import *

for i in range(4):
  forward(50)
  right(90)
forward(25)
circle(10)
right(90)
forward(25)
for j in range(3):
  right(90)
  forward(25)
  right(180)
  forward(25)
right(90)

Merci à tous et merci Casio, un concours très réussi qui a encouragé la création de très beaux scripts. :favorite:
A quand un concours similaire ouvert aux élèves, que l'on voit si ils sont capables de faire mieux ? ;)


Téléchargements :
  1. script de Florian Allard / Afyu
  2. script de Thomas Fontaine
  3. script de Xavier Andréani / Critor
  4. script d'Isabelle Vanacker
  5. script d'Isabelle Duval

Source : https://www.casio-education.fr/contenus ... -plus-loin
Image
Avatar de l’utilisateur
critorAdmin
Niveau 19: CU (Créateur Universel)
Niveau 19: CU (Créateur Universel)
Prochain niv.: 41.4%
 
Messages: 41455
Images: 14353
Inscription: 25 Oct 2008, 00:00
Localisation: Montpellier
Genre: Homme
Calculatrice(s):
MyCalcs profile
YouTube: critor3000
Twitter/X: critor2000
GitHub: critor

Retourner vers News Casio

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 6 invités

-
Rechercher
-
Social TI-Planet
-
Sujets à la une
Comparaisons des meilleurs prix pour acheter sa calculatrice !
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
Phi NumWorks jailbreak
123
-
Faire un don / Premium
Pour plus de concours, de lots, de tests, nous aider à payer le serveur et les domaines...
Faire un don
Découvrez les avantages d'un compte donateur !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partenaires et pub
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
461 utilisateurs:
>446 invités
>10 membres
>5 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Autres sites intéressants
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)