kandinsky2.py

Created by antarctus

Created on July 25, 2022

798 Bytes

Bibliothèque pour améliorer kandinsky. Permet d’utiliser draw_line et fill_circle.

Date d’Avril 2022.


from kandinsky import *
from time import *

def fill_circle(x,y,r,c):
  rr=int(r*0.7071067811865475)
  r2=r**2
  fill_rect(x-rr,y-rr,2*rr,2*rr,c)
  for xx in range(x-rr-1,x+rr+1):
    for yy in list(range(y-r-1,y-rr))+list(range(y+rr,y+r+1)):
      if ((yy-y)**2+(xx-x)**2)<=r2:
        set_pixel(xx,yy,c)
  for yy in range(y-rr-1,y+rr+1):
    for xx in list(range(x-r-1,x-rr))+list(range(x+rr,x+r+1)):
      if ((yy-y)**2+(xx-x)**2)<=r2:
        set_pixel(xx,yy,c)


def draw_line(x1,y1,x2,y2,c):
  width=x2-x1
  height=y2-y1
  if abs(width)>=abs(height):
    div=height/width
    for i in range(0,width,(width>0)*2-1):
      set_pixel(x1+i,y1+int(div*i+0.5),c)
  else:
    div=width/height
    for i in range(0,height,(height>0)*2-1):
      set_pixel(x1+int(div*i+0.5),y1+i,c)

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.