testvec.py

Created by fime

Created on October 16, 2021

534 Bytes

Un petit programme de test qui permet de mettre en application le mouvement avec des vecteurs definis par une direction et un norme.

Peut etre utilisé comme une tortue de tracé avec un peu d’adaptation.


from math import *
from kandinsky import *
from time import *
from random import randint

def vec(s,a):
  a=radians(a)
  x=s*cos(a)
  y=s*sin(a)
  return x,y
  
def simp(a):
  return a%360 
  
def collide(a1,a2):
  a_i=simp(a1-a2)
  return a2-a_i
  
x1,y1=101,101
v=1
a=0
fill_rect(x1,y1,1,1,(0,0,0))

while True:
  a=simp(a)
  x2,y2=vec(v,a)
  x1,y1=x1+x2,y1+y2
  fill_rect(int(x1),int(y1),1,1,(0,0,0))
  if y1<100 or y1>200:
    a=collide(a,180)+randint(-5,5)
  if x1<100 or x1>200:
    a=collide(a,270)+randint(-5,5)

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.