为什么导入时python中的乌龟不起作用?

时间:2019-04-01 11:58:58

标签: python turtle-graphics

这是我的代码

float sensitivity = 10f;
Vector3 firstPressPos;
Vector3 secondPressPos;
float minRotationX = 45;
float maxRotationX = 100;
float minRotationY = 30;
float maxRotationY = 30;

void Update () {

    if (Input.GetMouseButtonDown(0))
    {
        //save began touch 2d point
        firstPressPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y);
    }

    if (Input.GetMouseButton(0))
    {
        //save ended touch 2d point
        secondPressPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y);

        if (firstPressPos != secondPressPos)
        {
            float RotX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
            float RotY = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
            transform.RotateAround(Vector3.up, RotX);
            transform.RotateAround(Vector3.right, -RotY);

            Vector3 angles = transform.eulerAngles;
            angles.x = Mathf.Clamp(angles.x, minRotationX, maxRotationX);
            angles.y = Mathf.Clamp(angles.y, -minRotationY, maxRotationY);
            angles.z = 0;
            transform.eulerAngles = angles;
        }

    }

}

这是我得到的错误

Import turtle

t = turtle.pen()

t.forward(50)

2 个答案:

答案 0 :(得分:0)

Turtle.pen用于设置/获取龟的笔属性,但不用于绘制(有关更多信息,请参见help(turtle.pen)),以便绘制某些内容,您需要按以下方式获取Turtle对象:

import turtle
tur=turtle.Turtle();
tur.forward(50);

答案 1 :(得分:0)

正确的答案是在“ pen”中大写“ P”