boite_outils_graphiques.py

Created by telpe51

Created on July 06, 2018

1.32 KB

Quelques fonctions graphiques : segment(coordonnées des extrémités, [couleur]), quadrilatère(4 points donnés par leurs couples de coordonnées), cercle(coordonnées du centre, rayon), vecteur(coordonnées des extrémités), somme vecteur, multiplication par un réel, … sera complétée …


from math import *
from kandinsky import *
def seg(xa,ya,xb,yb,r=250,v=0,b=250):
  col=color(r,v,b)
  if xa==xb :
    if ya<yb:
      y=ya
      bs=yb
    else :
      y=yb
      bs=ya
    while y<=bs:
      set_pixel(int(xa),int(y),col)
      y=y+1
  else:
    m=(yb-ya)/(xb-xa)
    p=ya-m*xa
    if xa<xb:
      x=xa
      bs=xb
    else :
      x=xb
      bs=xa
    while x<=bs:
      y=m*x+p
      set_pixel(int(x),int(y),col)
      x=x+1
def cercle(xc, yc, R, r=255, v=0, b=255):
  x=1
  y=R
  col=color(r,v,b)
  while y>=x:
    set_pixel(xc+x,yc+y,col)
    set_pixel(xc+x,yc-y+1,col)
    set_pixel(xc-x+1,yc+y,col)
    set_pixel(xc-x+1,yc-y+1,col)
    set_pixel(xc+y,yc+x,col)
    set_pixel(xc+y,yc-x+1,col)
    set_pixel(xc-y+1,yc+x,col)
    set_pixel(xc-y+1,yc-x+1,col)
    if (R-0.5)**2<(x+1)**2+y**2<(R+0.5)**2:
      x=x+1
    elif (R-0.5)**2<x**2+(y-1)**2<(R+0.5)**2:
      y=y-1
    else:
      x=x+1
      y=y-1
def carre(A,c):
    B=(A[0]+c,A[1])
    C=(B[0],B[1]+c)
    D=(A[0],C[1])
    return (A,B,C,D)
def quadri(A,B,C,D): 
    quadr=[A,B,C,D,A]
    for i in range(4):
        seg(quadr[i][0],quadr[i][1],quadr[i+1][0],quadr[i+1][1])
def vect(A,B):
    return (B[0]-A[0],B[1]-A[1])
def somme(poin,vec):
    return (poin[0]+vec[0],poin[1]+vec[1])
def mult(reel,vec):
    return (reel*vec[0],reel*vec[1])

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.