labeauteducode.py

Created by antarctus

Created on June 07, 2021

1.05 KB


from random import *
from kandinsky import *
from time import *

class Point():
  def __init__(self,coords,vect,colors):
    self.coords=coords
    self.vect=vect
    self.colors=colors
    self.color_act=[0,1]

  def draw(self):
    fill_rect(self.coords[0]-5,self.coords[1]-5,10,10,tuple(self.colors))

  def move(self):
    self.coords[0]+=self.vect[0]
    self.coords[1]+=self.vect[1]

  def rejump(self):
    if not 0<self.coords[0]<320:
      self.vect[0]*=-1
    if not 0<self.coords[1]<220:
      self.vect[1]*=-1

  def change_color(self):
    self.colors[self.color_act[0]]+=self.color_act[1]

  def change_action(self):
    if self.colors[self.color_act[0]]==[None,255,0][self.color_act[1]]:
      self.color_act[1]*=-1
      while True:
        r=(self.color_act[0]+2)%3
        if self.colors[r]==[None,0,255][self.color_act[1]]:
          self.color_act[0]=r
          break

p=Point([0,0],[1,1],[230,0,255])

fill_rect(0,0,320,222,(0,)*3)
while True:
  p.move()
  p.draw()
  p.rejump()
  p.change_color()
  p.change_action()
  sleep(0.01)

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.