kerst.py

Created by numworks-nl

Created on December 16, 2021

1.84 KB


from math import *
from kandinsky import *

rood=color(255,25,0)
geel=color(255,215,0)
groen=color(0,128,0)
wit=color(255,255,255)
roze=color(199,21,133)
bruin=color(110,80,60)

def fillEllipsis(centerI, centerJ, a, b, theta, R, color):
  a2 = a*a
  b2 = b*b
  for i in range(centerI-3*R,centerI+3*R):
    for j in range(centerJ-3*R,centerJ+3*R):
      deltaI = i-centerI
      deltaJ = j-centerJ
      x = cos(theta)*deltaI + sin(theta)*deltaJ
      y = sin(theta)*deltaI - cos(theta)*deltaJ
      if (x*x/a2+y*y/b2 <= R):
        set_pixel(i, j, color)

#Cadeau roze en geel
fillEllipsis(155,115, 2, 5, 4, 3,geel)
fillEllipsis(145,115, 5, 2, 4, 3,geel)
fill_rect(120,120,60,60,roze)
fill_rect(120,147,60,5,geel)
fill_rect(147,120,5,60,geel)

#Cadeau rood en bruin
fillEllipsis(77,160, 2, 5, 4, 3,bruin)
fillEllipsis(67,160, 5, 2, 4, 3,bruin)
fill_rect(50,165,60,60,rood)
fill_rect(50,200,60,5,bruin)
fill_rect(70,165,5,60,bruin)

#Cadeau groen en rood
fillEllipsis(233,135, 2, 5, 4, 3,rood)
fillEllipsis(223,135, 5, 2, 4, 3,rood)
fill_rect(200,140,60,60,groen)
fill_rect(200,168,60,5,rood)
fill_rect(225,140,5,60,rood)

def fill_triangle(a, b, c, col, right):
  h = abs(b[1]-a[1])
  for i in range(0, h):
    w = (int)(abs(b[0]-c[0])*(i/h))
    if right:
      if a[1] < b[1]:
        fill_rect(a[0]-w,a[1]+i, abs(w)+1, 1, col)
      else:
        fill_rect(a[0]-w,a[1]-i, abs(w)+1, 1, col)
    else:
      if a[1] < b[1]:
        fill_rect(a[0],a[1]+i, abs(w)+1, 1, col)
      else:
        fill_rect(a[0],a[1]-i, abs(w)+1, 1, col)
  return    



#kerstboom
fill_rect(0,145,30,120,bruin)
fill_triangle((0,0),(0,50),(57,53),groen,False)
fill_triangle((0,50),(0,100),(57,53),groen,False)
fill_triangle((0,100),(0,150),(57,53),groen,False)



#kerstballen
fillEllipsis(51,50, 4, 4, 4, 3,rood)
fillEllipsis(51,100, 4, 4, 4, 3,geel)
fillEllipsis(51,148,4,4,4,3,roze)