draw.py

Created by yaya-cout

Created on January 29, 2022

1.78 KB


from time import *
from turtle import *
from ion import *
from random import *

import kandinsky
kandinsky.fill_rect(0,0,320,222,'white')
taille=1
x=0
y=0
vitesse=10
#commandes=input("Mode (1=Fleches) : ")
commandes="1"
if commandes == "1":
  fleches=True
else:
  fleches=False
if commandes == "0123456789":
    fleches=True
    egg=True
else:
  egg=False
showturtle()

def main(fleches=False,taille=1,x=0,y=0,egg=False,vitesse=10):
  if keydown(KEY_EXE) or egg:
    colormode(255)
    color(randint(0,255),randint(0,255),randint(0,255))
    hideturtle()
    showturtle()
  if keydown(KEY_ANS):
    hideturtle()   
    #write(str(kandinsky.get_pixel(int(position()[0]),int(position()[1]))))
    #color(kandinsky.get_pixel(int(position()[0]),int(position()[1])))
    color(255,255,255)
    showturtle()
  if keydown(KEY_BACKSPACE):
    reset()
    kandinsky.fill_rect(0,0,320,222,'white')
    x=0
    y=0
    penup()
    goto(x,y)
  if keydown(KEY_OK):
    if isdown():
      penup()
    else:
      pendown()
    sleep(.5)
  if keydown(KEY_UP):
    y+=1
    if fleches==False:
      forward(1)  
  if keydown(KEY_DOWN):
    y-=1
    if fleches==False:
      backward(1)
  if keydown(KEY_RIGHT):
    x+=1
    if fleches==False:
      right(1)
  if keydown(KEY_LEFT):
    x-=1
    if fleches==False:
      left(1)
  if keydown(KEY_MINUS):
     if taille>1:
       taille-=1
     pensize(taille)
  if keydown(KEY_PLUS):
     taille+=1
     pensize(taille)
  if keydown(KEY_DIVISION):
    if vitesse>1:
      vitesse-=1
    speed(vitesse)
  if keydown(KEY_MULTIPLICATION):
    if vitesse<10:
      vitesse+=1
    speed(vitesse)
  if fleches:
    goto(x,y)
  return x,y,taille,vitesse
print(__name__)
while True:    
  try:
    x,y,taille,vitesse=main(fleches,taille,x,y,egg,vitesse)
  except MemoryError:
    taille-=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.