maths_pythagore.py

Created by antarctus

Created on November 21, 2021

1.34 KB

Utiliser Exe pour calculer la nouvelle valeur du côté sélectionnée.
Utiliser Ok pour en définir une nouvelle.
Le petit carré est vert si Pythagore est respecté, rouge sinon.


from math import *
from kandinsky import *
from ion import *
from time import *

BACK_COLOR=(0,)*3
COLOR=(255,)*3

cote=[3,4,5]
selected=0

def draw_all():
  fill_rect(0,0,320,222,BACK_COLOR)
  if sqrt(cote[0]**2+cote[1]**2)==cote[2]:
    c=(0,255,0)
  else:
    c=(255,0,0)
  fill_rect(50,138,12,12,(c[0]//2,c[1]//2,0))
  fill_rect(50,140,10,10,c)

  fill_rect(50,50,1,100,COLOR)
  fill_rect(50,150,150,1,COLOR)
  for x in range(150):
    set_pixel(50+x,int(x/150*100)+50,COLOR)
  c=[BACK_COLOR,]*3
  c[selected]=(200,200,0)
  #(50;50) (50;150) (200;150) 
  for i in range(3):
    draw_string(str(cote[i]),[40,125,145][i],[100,151,80][i],COLOR,c[i])


def calcul():
  global cote
  a,b,c=cote
  if selected==0:
    cote=[sqrt(c**2-b**2),b,c]
  if selected==1:
    cote=[a,sqrt(c**2-a**2),c]
  if selected==2:
    cote=[a,b,sqrt(a**2+b**2)]
  for i in range(3):
    n=10
    while cote[i]==round(cote[i],n): 
      cote[i]=round(cote[i],n)
      if n==0:
        cote[i]=int(cote[i])
      n-=1


while keydown(KEY_OK):
  pass

draw_all()

while True:
  if keydown(KEY_EXE) or keydown(KEY_OK) or keydown(KEY_UP) or keydown(KEY_DOWN):
    selected+=keydown(KEY_DOWN)-keydown(KEY_UP)
    selected%=3
    if keydown(KEY_OK):
      cote[selected]=eval(input("Nouvelle valeur : "))
    elif keydown(KEY_EXE):
      calcul()
    draw_all()
  sleep(0.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.