cercle.py

Created by ph-moutou

Created on May 01, 2018

877 Bytes

Tracer un cercle de centre O, de rayon R, d’épaisseur e.


from kandinsky import *
from math import *
def cercle(x0,y0,r,c,e):
  for i in range(2*e):
    xd=x0-int((r-i*0.5)/sqrt(2))
    xf=x0+int((r-i*0.5)/sqrt(2))
    for x in range(xd,xf+1):
      x1=x
      y1=y0+int(sqrt((r-i*0.5)**2-(x-x0)**2))
      set_pixel(x,y1,c)
      for j in range(3):
        x2=x0+y1-y0
        y2=y0+x0-x1
        set_pixel(x2,y2,c)
        x1,y1=x2,y2

def cercle_plein(x0,y0,r,c1,e,c2):
  cercle(x0,y0,r,c1,e)
  cercle(x0,y0,r-e,c2,r-e)
  #draw_string('e='+str(e),x0-15,y0-7)

def cercle_grade(x0,y0,R,c1,e,c2): 
  for i in range(R):
    r=c1[0]+i*(c2[0]-c1[0])//R
    g=c1[1]+i*(c2[1]-c1[1])//R
    b=c1[2]+i*(c2[2]-c1[2])//R
    cercle(x0,y0,i,color(r,g,b),1)
    
cExt=[210,255,212]
cInt=[139,68,66]
cint=color(255,255,0)#ivoire
cbor=color(0,0,0) #chatain
#cercle_plein(160,111,50,cbor,10,cint)
cercle_grade(160,111,50,cExt,10,cInt)

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.