Войти
или
Зарегистрироваться
Маркетплейс
Курсы
Учебник
Учебник 2.0
ОГЭ/ЕГЭ
Олимпиады
Рубрикатор
Компилятор
Онлайн Компилятор
Компилятор Python (lite)
Редактор HTML Code
Статья Автор:
Юровский Егор
Сетка и пунктир
import turtle as tr import math def dashed_segment(tr, segment, d): (x1, y1), (x2, y2) = segment if d%2==0: d=d+1 if d>0: dash_length = d gap_length = d tr.penup() tr.goto(x1, y1) tr.pendown() dx, dy = x2 - x1, y2 - y1 length = math.sqrt(dx**2 + dy**2) angle = math.degrees(math.atan2(dy, dx)) tr.setheading(angle) drawn = 0 while drawn < length: step = min(dash_length, length - drawn) tr.forward(step) drawn += step if drawn < length: tr.penup() step = min(gap_length, length - drawn) tr.forward(step) drawn += step tr.pendown() elif d==0: tr.up() tr.setpos((x1, y1)) tr.down() tr.goto((x2, y2)) else: d=abs(d) dx, dy = x2 - x1, y2 - y1 length = math.sqrt(dx ** 2 + dy ** 2) angle = math.degrees(math.atan2(dy, dx)) tr.setheading(angle) dash_length = length/d gap_length = length/d tr.penup() tr.goto(x1, y1) tr.pendown() drawn = 0 while drawn < length: step = min(dash_length, length - drawn) tr.forward(step) drawn += step if drawn < length: tr.penup() step = min(gap_length, length - drawn) tr.forward(step) drawn += step tr.pendown() dashed_segment(tr, ((0,0), (100, 100)), 11) tr.done()
×
import turtle as tr import math def dashed_segment(tr, segment, d): (x1, y1), (x2, y2) = segment if d%2==0: d=d+1 if d>0: dash_length = d gap_length = d tr.penup() tr.goto(x1, y1) tr.pendown() dx, dy = x2 - x1, y2 - y1 length = math.sqrt(dx**2 + dy**2) angle = math.degrees(math.atan2(dy, dx)) tr.setheading(angle) drawn = 0 while drawn < length: step = min(dash_length, length - drawn) tr.forward(step) drawn += step if drawn < length: tr.penup() step = min(gap_length, length - drawn) tr.forward(step) drawn += step tr.pendown() elif d==0: tr.up() tr.setpos((x1, y1)) tr.down() tr.goto((x2, y2)) else: d=abs(d) dx, dy = x2 - x1, y2 - y1 length = math.sqrt(dx ** 2 + dy ** 2) angle = math.degrees(math.atan2(dy, dx)) tr.setheading(angle) dash_length = length/d gap_length = length/d tr.penup() tr.goto(x1, y1) tr.pendown() drawn = 0 while drawn < length: step = min(dash_length, length - drawn) tr.forward(step) drawn += step if drawn < length: tr.penup() step = min(gap_length, length - drawn) tr.forward(step) drawn += step tr.pendown() #dashed_segment(tr, ((0,0), (100, 100)), 11) def edge(x, y): tr.up() tr.setpos(x,y) tr.down() tr.goto(x,y) x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) m=int(input()) d=0 tr.speed(100000) for i in range(x1,x2,10): print(i) dashed_segment(tr, ((i,y1), (i, y2)), m) tr.up() tr.goto(d, 0) tr.down() for i in range(y1,y2,10): print(i) dashed_segment(tr, ((x1,i), (x2, i)), m) tr.up() tr.goto(0, d) tr.down() tr.done()
×
import turtle as tr from turtle import speed import math def dashed_segment(tr, segment, d): (x1, y1), (x2, y2) = segment if d%2==0: d=d+1 if d>0: dash_length = d gap_length = d tr.penup() tr.goto(x1, y1) tr.pendown() dx, dy = x2 - x1, y2 - y1 length = math.sqrt(dx**2 + dy**2) angle = math.degrees(math.atan2(dy, dx)) tr.setheading(angle) drawn = 0 while drawn < length: step = min(dash_length, length - drawn) tr.forward(step) drawn += step if drawn < length: tr.penup() step = min(gap_length, length - drawn) tr.forward(step) drawn += step tr.pendown() elif d==0: tr.up() tr.setpos((x1, y1)) tr.down() tr.goto((x2, y2)) else: d=abs(d) dx, dy = x2 - x1, y2 - y1 length = math.sqrt(dx ** 2 + dy ** 2) angle = math.degrees(math.atan2(dy, dx)) tr.setheading(angle) dash_length = length/d gap_length = length/d tr.penup() tr.goto(x1, y1) tr.pendown() drawn = 0 while drawn < length: step = min(dash_length, length - drawn) tr.forward(step) drawn += step if drawn < length: tr.penup() step = min(gap_length, length - drawn) tr.forward(step) drawn += step tr.pendown() tr.speed(0) x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) m=20 tr.setup(width=abs(x1-x2), height=abs(y1-y2)) tr.speed(0) d=0 for i in range(x1,x2,m): dashed_segment(tr, ((i,y1), (i, y2)), 2) tr.up() tr.goto(d, 0) tr.down() for i in range(y1,y2,m): dashed_segment(tr, ((x1,i), (x2, i)), 2) tr.up() tr.goto(0, d) tr.down() #добавить offest из другой тетради tr.forward(4*m) tr.done()
×
Чтобы оставить комментарий нужна авторизация
Печать