#!usr/bin/env python
from turtle import Turtle
timmy = Turtle #A turtle called Timmy.
pointA = None
pointB = None
backgroundColour = (255,255,255)
penColour = (0,0,0) #So I can just say penColour, as opposed to (0,0,0)
graphicsWindowHeight = 640
graphicsWindowWidth = 640
equation = str(input("What is the equation as y=mx+c?Do not use spaces, please, it messes up the code"))
if len(equation) != 6:
print("You have broken my code. It is not perfect") #Short explanation
#(equation[3]) is gradient, and (equation[5]) is y-intercept, and x-intercept is equation[5] / equation[3]
def calculateAndDrawLine(pointA, pointB):
#CALCULATE WHAT TO DRAW
#y = 10 here
pointA = ((equation[3]/-10)+10)*32,0
#y = -10 here
pointB = ((equation[3]/-10)*-1)+10*32,640
#DRAW IT
timmy.pencolor(penColour)
timmy.penwidth(10)
timmy.pendown()
timmy.setpos(pointA[0],pointA[1])
timmy.seth(pointB[0],pointB[1])
def drawAxis():
timmy.setpos(320,-640)
timmy.pencolor(penColour)
timmy.penwidth(10)
timmy.seth(320,0)
timmy.setpos(320,0)
timmy.seth(320,-320)
drawAxis()
calculateAndDrawLine()
这是我的代码,还没有完成。我试着让它在输入的方程上画一条直线,用海龟图形。但是当我运行它时,我得到了这个错误。我能做些什么吗?在
^{pr2}$
您需要创建
Turtle
对象的实例:注意
()
调用部分。如果没有调用,timmy
上的所有方法都是未绑定的,并且不会自动提供它们的self
参数。结果,您最终将320
作为self
传入,但这不起作用。在相关问题 更多 >
编程相关推荐