查看海龟 circle() 绘图中使用的所有坐标
See all the coordinates used in a turtle circle() drawing
我想用它的氮碱基绘制 1 条 DNA 链:一小段链,一个碱基,一小段链,另一个碱基,依此类推。按照这个顺序。
但是,当您打断 circle()
(在本例中为半圆,股线)以绘制其他东西时,例如直线(即底线),circle()
角度会发生变化。而且我想不出办法把它改回来。
所以,更简单的方法,画一个半圆,画一条线,继续半圆,好像就是goto()
一个坐标,画你想要的东西就可以了。
但是要计算一个圆的所有精确坐标,对于每个不同的圆,以防我需要更多,会很长。
有什么方法可以让turtle,或者任何其他的stuff/software,以return作为输出我drew/coded的一个圆的所有坐标?
比如,如果我画这个 circle()
:
from turtle import *
t = Turtle()
t.seth(45)
t.circle(100,90)
t.circle(-100,90)
乌龟可以return用来制作它的坐标吗?
下面是我所说的仅使用坐标创建圆的示例:
from turtle import *
t = Turtle()
def got(x,y,d) : # to use goto more easily
t.penup()
t.goto(x,y)
t.pendown()
t.seth(d)
x=0
y=0
d=0
megalist = [5,5,5,5,5,5,5,5,5,5,5,5,1,1,1,1,1,1,1,1,1,1,-1,0,0,0,0,0-1,-1,-1,-1,-1,-1,-1,-1,-1,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,]
for i in megalist :
x = x + i
y= y +4
got(x,y,d)
t.forward(-1)
would be possible for turtle to return the coordinates used to make it?
是的。有一些 *_poly()
方法,通常用于创建自定义游标,可用于执行您描述的操作:
from turtle import Screen, Turtle
screen = Screen()
turtle = Turtle(visible=False)
turtle.penup()
turtle.seth(45)
turtle.begin_poly()
turtle.circle(100, 90)
turtle.circle(-100, 90)
turtle.end_poly()
polygon = turtle.get_poly()
print(polygon)
for point in polygon:
turtle.goto(point)
turtle.pendown()
screen.exitonclick()
控制台输出
> python3 test.py
((0.00,0.00), (13.96,17.51), (23.68,37.68), (28.66,59.51), (28.66,81.91),
(23.68,103.74), (13.96,123.91), (0.00,141.42), (-13.96,158.93),
(-23.68,179.10), (-28.66,200.94), (-28.66,223.33), (-23.68,245.16),
(-13.96,265.34), (0.00,282.84))
>
屏幕输出
when you interrupt a circle(), (...) to draw something else,like a
straight line (...), the circle() angle is changed. And i can't think
a way to change it back.
我相信你可以通过小范围循环来中断circle()
,保存位置和航向,做你的绘图,并恢复之前的位置和航向下一个圆范围迭代。这是一个简单的例子,它只是在绘图本身放回位置时保存和恢复标题:
from turtle import Screen, Turtle
screen = Screen()
turtle = Turtle(visible=False)
turtle.speed('fastest') # because I have no patience
turtle.setheading(45)
for extent in range(9):
turtle.circle(100, 10)
heading = turtle.heading()
turtle.setheading(0)
turtle.forward(10)
turtle.backward(10)
turtle.setheading(heading)
for extent in range(9):
turtle.circle(-100, 10)
heading = turtle.heading()
turtle.setheading(180)
turtle.forward(10)
turtle.backward(10)
turtle.setheading(heading)
screen.exitonclick()
屏幕输出
我想用它的氮碱基绘制 1 条 DNA 链:一小段链,一个碱基,一小段链,另一个碱基,依此类推。按照这个顺序。
但是,当您打断 circle()
(在本例中为半圆,股线)以绘制其他东西时,例如直线(即底线),circle()
角度会发生变化。而且我想不出办法把它改回来。
所以,更简单的方法,画一个半圆,画一条线,继续半圆,好像就是goto()
一个坐标,画你想要的东西就可以了。
但是要计算一个圆的所有精确坐标,对于每个不同的圆,以防我需要更多,会很长。
有什么方法可以让turtle,或者任何其他的stuff/software,以return作为输出我drew/coded的一个圆的所有坐标?
比如,如果我画这个 circle()
:
from turtle import *
t = Turtle()
t.seth(45)
t.circle(100,90)
t.circle(-100,90)
乌龟可以return用来制作它的坐标吗?
下面是我所说的仅使用坐标创建圆的示例:
from turtle import *
t = Turtle()
def got(x,y,d) : # to use goto more easily
t.penup()
t.goto(x,y)
t.pendown()
t.seth(d)
x=0
y=0
d=0
megalist = [5,5,5,5,5,5,5,5,5,5,5,5,1,1,1,1,1,1,1,1,1,1,-1,0,0,0,0,0-1,-1,-1,-1,-1,-1,-1,-1,-1,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,]
for i in megalist :
x = x + i
y= y +4
got(x,y,d)
t.forward(-1)
would be possible for turtle to return the coordinates used to make it?
是的。有一些 *_poly()
方法,通常用于创建自定义游标,可用于执行您描述的操作:
from turtle import Screen, Turtle
screen = Screen()
turtle = Turtle(visible=False)
turtle.penup()
turtle.seth(45)
turtle.begin_poly()
turtle.circle(100, 90)
turtle.circle(-100, 90)
turtle.end_poly()
polygon = turtle.get_poly()
print(polygon)
for point in polygon:
turtle.goto(point)
turtle.pendown()
screen.exitonclick()
控制台输出
> python3 test.py
((0.00,0.00), (13.96,17.51), (23.68,37.68), (28.66,59.51), (28.66,81.91),
(23.68,103.74), (13.96,123.91), (0.00,141.42), (-13.96,158.93),
(-23.68,179.10), (-28.66,200.94), (-28.66,223.33), (-23.68,245.16),
(-13.96,265.34), (0.00,282.84))
>
屏幕输出
when you interrupt a circle(), (...) to draw something else,like a straight line (...), the circle() angle is changed. And i can't think a way to change it back.
我相信你可以通过小范围循环来中断circle()
,保存位置和航向,做你的绘图,并恢复之前的位置和航向下一个圆范围迭代。这是一个简单的例子,它只是在绘图本身放回位置时保存和恢复标题:
from turtle import Screen, Turtle
screen = Screen()
turtle = Turtle(visible=False)
turtle.speed('fastest') # because I have no patience
turtle.setheading(45)
for extent in range(9):
turtle.circle(100, 10)
heading = turtle.heading()
turtle.setheading(0)
turtle.forward(10)
turtle.backward(10)
turtle.setheading(heading)
for extent in range(9):
turtle.circle(-100, 10)
heading = turtle.heading()
turtle.setheading(180)
turtle.forward(10)
turtle.backward(10)
turtle.setheading(heading)
screen.exitonclick()
屏幕输出