Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Два шарика в квадрате
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
''' В прямоугольнике атомы, случайно расположенные в нём. Программа находит их взаимное положение, при котором атомы максимально удалены друг от друга и максимально удалены и от ближайших стенок. ''' 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)
[
+
]
Show input
edit mode
|
history
|
discussion