nord.py

Created by schraf

Created on July 21, 2024

542 Bytes

Explications en vidéo

Version avec kandinsky

Ce programme permet de retrouver (approximativement) le Nord et le Sud à l’aide de la calculatrice. Il suffit pour de préciser l’heure actuelle, si nous sommes en heure d’été ou d’hiver puis d’orienter la machine horizontalement vers le soleil…

Version avec turtle

En rouge la direction du nord et en vert le sud

from turtle import *

def trait(a, c):
  pensize(8)
  color(c)
  penup()
  goto(0,0)
  pendown()
  setheading(a)
  forward(100)
    
def nord():
  hm = input("hh.mm ? ")
  he = input("Heure hiver (o/n) ? ")
  [h,m] = [int(v) for v in hm.split(".")]
  v = h + m / 60 - 1
  if he.upper() == "N" or he == "8": v -= 1
  angle = 15 * v - 90
  trait(90, "black")
  trait(angle, "green")
  trait(angle + 180, "red")
  hideturtle()


from math import *
from kandinsky import *

def trait(a, t=""):
  c=3*(0,) #noir
  for i in range(100):
    x = int(160 + i*cos(a))
    y = int(110 - i*sin(a))
    set_pixel(x, y, c)
    set_pixel(x+2, y+2, c)
  draw_string(t, x-2, y)
    

def nord():
  hm = input("hh.mm ? ")
  he = input("Heure hiver (o/n) ? ")
  [h,m] = [int(v) for v in hm.split(".")]
  v = h + m / 60 - 1
  if he.upper() == "N" or he == "8": v -= 1
  angle = (15 * v - 90) / 180 * pi
  trait(angle, "S")
  trait(angle + pi, "N")
  trait(pi/2, "*")

nord()

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 <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.