Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Два шарика в квадрате
''' В прямоугольнике атомы, случайно расположенные в нём. Программа находит их взаимное положение, при котором атомы максимально удалены друг от друга и максимально удалены и от ближайших стенок. ''' import turtle as t import random as rnd l, r, d, u = -300, 300, -300, 300 t1 = t.Pen(shape='circle') t2 = t.Pen(shape='square') term = t.Pen() term.pencolor('green') term.pensize(3) term.ht() term.pu() term.goto(l, u) term.down() term.goto(l, d) term.goto(r, d) term.goto(r, u) term.goto(l, u) term.goto(r, d) term.goto(r, u) term.goto(l, d) term.forward(100) t1.setpos(rnd.randint(l+10, r-10), rnd.randint(d+10, u-10)) t2.setpos(rnd.randint(l+10, r-10), rnd.randint(d+10, u-10)) while True: if abs (t1.xcor() - l) < abs(t1.xcor() - t2.xcor()): t1.goto(t1.xcor() + 1, t1.ycor()) else: t1.goto(t1.xcor() - 1, t1.ycor()) if abs (t2.xcor() - r) < abs(t1.xcor() - t2.xcor()): t2.goto(t2.xcor() - 1, t2.ycor()) else: t2.goto(t2.xcor() + 1, t2.ycor()) if abs (t1.ycor() - d) < abs(t1.ycor() - t2.ycor()): t1.goto(t1.xcor(), t1.ycor() + 1) else: t1.goto(t1.xcor(), t1.ycor() - 1) if abs (t2.ycor() - u) < abs(t1.ycor() - t2.ycor()): t2.goto(t2.xcor(), t2.ycor() - 1) else: t2.goto(t2.xcor(), t2.ycor() + 1) lx = min(abs(t1.xcor()-l), abs(t1.xcor()-r)) ly = min(abs(t1.ycor()-u), abs(t1.ycor()-d)) rx = min(abs(t2.xcor()-l), abs(t2.xcor()-r)) ry = min(abs(t2.ycor()-u), abs(t2.ycor()-d)) # print(t1.distance(t2) + lx + ly + rx + ry)
run
|
edit
|
history
|
help
0
8
("Hello,world!")
Calender 2019
teretere
Dont know, Dont care
Page 353 ex 42
3-6.격자판 최대합
inerse_matrix_gauss_jordan
PyDIP
Python: Stack Simple I