lentille.py

Created by schraf

Created on June 18, 2022

1.26 KB

Sur une idée de Fabien Beyaert

Tapez go() puis entrez les valeurs de AB, OA et f’ (par exemple 5, 25, 15 ou 7, 40, 10)

La machine affiche OA’ et A’B’. Appuyez sur EXE pour voir le diagramme.


from turtle import *
from kandinsky import draw_string

hideturtle()
speed(0)

def fleche(x1, y1, a, d, coul='black'):
    color(coul)
    penup()
    goto(x1, y1)
    pendown()
    setheading(a)
    forward(d)
    for v in [a + 135, a - 135]:
     setheading(v)
     forward(5)
     forward(-5)

def go():
    data = [0, 0, 0]
    for i,c in enumerate(['AB','OA','f\'']):
        data[i] = float(input('{} = ? '.format(c)))
    [AB, OA, fp] = data
    OAp = 1 / (1 / fp - 1 / OA)
    ApBp = AB * OAp / OA
    print('-' * 10)
    print('OA\' =', OAp)
    print('A\'B\' = ',ApBp)
    print('-' * 10)
    c = input('Appuyez sur EXE')
    # position X de l'origine
    a = 280 / (OA + OAp)
    b = int(140 - a * OAp)
    # position Y de l'origine
    c = 200 / (AB + ApBp)
    d = int(100 - c * AB)
    pensize(1)
    fleche(-150,d,0,300)
    fleche(b,110,-90,220)
    fleche(b,-110,90,220)
    color('red')
    pensize(2)
    penup()
    goto(-140, 100)
    pendown()
    goto(b, 100)
    goto(140, d - c * ApBp)
    penup()
    goto(-140, 100)
    pendown()
    goto(140, d - c * ApBp)
    fleche(-140, d, 90, c * AB, 'blue')
    fleche(140, d, -90, c * ApBp, 'blue')
    draw_string("A", 10, 115 - d)
    draw_string("A'", 290, 90 - d )
    draw_string("O", b + 145, 115 - d )