bob.py

Created by stimorol

Created on October 14, 2022

1.14 KB

Petit programme qui dessine un point qui se déplace aléatoirement (il est pas terrible, mais j’avais bien aimé le faire). Il s’affiche rouge si il monte, noir si il descend, vert si il va vers la gauche et bleu vers la droite.


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

def bob(min, max, min2, max2):
  color='pink'
  x=161
  y=111
  reset()
  hideturtle()
  set_pixel(x,y,'black')
  maxx=maxy=1
  minx=miny=-1
  while True:
    newx=randint(minx,maxx)
    newy=randint(miny,maxy)
    if newx == 0 or newy == 0:
      if newx != 0 and newy in [-1,0,1]:
        if newx < 0:
          maxx=max2
          minx=min
          maxy=1
          miny=-1
          color='green'
        else:
          maxx=max
          minx=min2
          maxy=1
          miny=-1
          color='blue'
      elif newx in [-1,0,1] and newy != 0:
        if newy < 0:
          maxy=max2
          miny=min
          maxx=1
          minx=-1
          color='red'
        else:
          maxy=max
          miny=min2
          maxx=1
          minx=-1
          color='black'
      else:
        pass
      x+=newx
      y+=newy
      sleep(0.001)
      print("\nnewx: ",newx,"   newy: ",newy,"\n minx: ",minx,"     maxx: ", maxx,"\n miny: ", miny,"   maxy: ",maxy)
      #set_pixel(x,y,color)
      fill_rect(x,y,2,2,color)
bob(-3, 3, -1, 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.