christmas.py

Created by alain-busser

Created on April 30, 2018

630 Bytes

draws the christmas balls (without the tree). The positions, colors and sizes of the balls are more or less random. To create a drawing, just type xmas(); a more impressive effect is obtained with for k in range(10): xmas()


from math import *
from kandinsky import *
from random import *
def ball(cx=160,cy=100,r=80,rc=2):
  for x in range(int(cx-r),int(cx+r+1)):
    for y in range(int(cy-r),int(cy+r+1)):
      cr=(x-cx)**2+(y-cy)**2
      cr /= r**2
      if cr<1:
        k=sqrt(1-cr)
        if rc==0:
          cc=color(int(k*255),int(k*255),0)
        elif rc==1:
          cc=color(0,int(k*255),int(k*255))
        else:
          cc=color(int(k*255),0,int(k*255))
        set_pixel(x,y,cc)
def xmas():
  for x in range(8):
    for y in range(5):
      ball(40*x+20+randint(-8,8),40*y+30+randint(-8,8),randint(8,16),randrange(3))

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.