echiquier.py

Created by ph-moutou

Created on May 18, 2018

692 Bytes

Ce programme trace un échiquier vide: est-ce que quelqu’un saura y dessiner les pièces blanches et noires?


from kandinsky import *
def segmentH(x1,x2,y):
  for i in range(x2-x1):
    set_pixel(x1+i,y,noir) 
def segmentV(x,y1,y2):
  for i in range(y2-y1):
    set_pixel(x,y1+i,noir)
def carre(x,y,c):
  for i in range(20):
    for j in range(20):
      set_pixel(x+i,y+j,c) 

blanc=color(255,255,212)#ivoire
brun=color(139,108,66)#chatain
noir=color(0,0,0)
L=['A','B','C','D','E','F','G','H']
for i in range(8):
  draw_string(L[i],85+i*20,15)
  draw_string(str(8-i),70,32+i*20)
  for j in range(8):
    if i%2==j%2:col=blanc
    else:col=brun
    carre(80+i*20,30+j*20,col)
for i in range(9):
  segmentH(80,240,30+i*20)
  segmentV(80+i*20,30,190)
set_pixel(240,190,noir)#dernier pt

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.