christmas1.py

Created by schraf

Created on December 02, 2022

1.32 KB


from turtle import *
from random import *
from kandinsky import fill_rect

fill_rect(0,0,320,222,(230,)*3)

NB = 10

svg = ['M',166,38,'C',170,38,178,40,174,42,169,44,160,43,163,46,166,48,171,47,180,49,178,52,160,53,159,56,159,59,175,58,189,59,176,63,159,62,151,69,156,74,182,73,208,71,199,77,131,81,139,83,147,85,202,87,222,86,210,89,116,106,116,106,116,106,226,100,233,102,222,107,109,117,99,119,124,120,231,115,244,115,226,123,111,134,100,140,128,138,237,136,250,137,242,149,82,153,65,167,103,166,277,151,288,160,261,170,75,183,60,193,83,198,128,190,145,204,'M',156,38,'C',156,38,164,16,165,12,170,16,176,24,177,34,169,28,159,28,150,23,162,21,169,20,183,18,172,24,156,38,156,38,'Z']

def move(x,y): 
  goto(x-160,110-y)

def coord(a,b,c,d,t):
  return a*(1-t)**3+3*b*t*(1-t)**2+3*c*t*t*(1-t)+d*t**3

def bezier(l):
  pendown()
  t = 0
  for i in range(NB+1):
    x = coord(l[0],l[2],l[4],l[6],t)
    y = coord(l[1],l[3],l[5],l[7],t)
    move(x,y)
    t += 1/NB

speed(0)
i = 0
color(30,140,0)
tt = len(svg)
print(tt)
while i<tt:
  pensize(1 + int(12 * i / tt) if i < 120 else 2)
  if svg[i] == "M":
    l = [svg[i+1],svg[i+2]]
    penup()
    move(l[0], l[1])
    i += 3
  elif svg[i] == "Z" or svg[i] == "C": i += 1
  else:  
    for j in range(6): l.append(svg[i+j])
    bezier(l)
    l = [svg[i+4],svg[i+5]]
    i += 6
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 <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.