Tianchi sea turtle editor drawing

  1. basic framework

import spen
    spen.set_defaults(canvas=document['canvas'])
    p = spen.Turtle("mouse")
    #code here!

    spen.done()
  1. brush settings

Set speed 0~10 p.speed(5)

set width p.width(5)

Set the line color p.color()

Set the fill color p.fillcolor()

Pen up and down p.up() p.down()

Switch between angles and radians p.degrees() p.radians()

  1. drawing command

Forward and backward p.fd(100) p.bk(100)

Turn left and right p.lt(90) p.rt(90)

Arrived at position p.goto(0,0) p.setx(0) p.sety(0)

Note: The corresponding position of the origin on the ruler is 250,250 when the canvas is not full screen, and 750,750 when it is full screen.

When you want to move to the position where the scale coordinates are 250,250, you only need p.goto(0,0), and so on.

set angle p.seth(90)

Go back to the origin and straighten p.home()

Draw a circle and draw a point p.circle(100,'red') p.dot(10,'green')

Draw text p.write("I love Brython!", font=("Simhei", 20, "normal"),align='center')

  1. get status

Current position p.pos() results such as (0,100)

current x or y position p.xcor() p.ycor()

The current angle p.heading(0,0) results in 90 degrees

The angle p.towards(0,0) of a point connected to the current position is 45 degrees

The distance from the current position to a certain point is p.distance(0,0) and the result is 100

Whether it is in the pen-down state p.isdown()

Guess you like

Origin blog.csdn.net/m0_64087341/article/details/128816322