BTS−SIO:DOC 9
Une correction du TD 9
2017-2018Rantanplan et les trois Dalton !
Une
orretion
import turtle as t from random import*
def triangle3freres():
t.setup(1000,900) t.penup()
t.goto(0,400) t.pendown()
t.write(" Joe",font=("Book Antigua",20)) t.goto(400,-200)
t.write("Jack",font=("Book Antigua",20)) t.goto(-400,-300)
t.write("William",font=("Book Antigua",20)) t.goto(0,400)
t.penup()
def DemiParcours(xd,yd,xa,ya,couleur):
t.goto(xd,yd) xm=(xa+xd)/2 ym=(ya+yd)/2 t.goto(xm,ym) t.pendown() t.dot(8,couleur) t.penup()
return [xm,ym]
def PositionRantanplan():
x=randint(-400,400) y=randint(-400,400) return [x,y]
def CarteTrousRantanplan(n):
t.speed(200) triangle3freres()
On peut également astreindre la fonction PositionRantanplan() à renvoyer une position de Rantanplan à l’intérieur du triangle formé par les trois Dalton. On a besoin dans ce cas de déterminer les équations des droites
« supportant » les côtés du triangle.
Moyennant l’utilisation de formules vues au lycée, on détermine les trois équations : y = 1
8 x−250 ; y = 7 4 x+400 et y = −
3
2 x + 400. D’où la fonction possible :
def PositionRantanplan():
L=[]
x=randint(-400,400) y=randint(-400,400)
while y<1/8*x-250 or y>7/4*x+400 or y>-3/2*x+400 : x=randint(-400,400)
y=randint(-400,400) L.extend([x,y])
return L
My Maths Space 1 sur 1