Is it possible to change the course of the turtle?

I need to draw a histogram using Python turtle graphics, and I thought it would be easier to just make the pen a thick square so that I can draw such bars, and don’t have to worry about creating dozens of rectangles and filling them in.

When I set the shape of the turtle with turtle.shape('square'), but it changes the appearance of the pen, but does not affect the actual drawing:

enter image description here

Is there a way to get the turtle to draw a rectangular stroke, either through built-in methods or by modifying the turtle file?

I do NOT want rounded edges, for example:

enter image description here

+4
source share
4 answers

, , , .

screen.register_shape("bar",( (width/2,0),(-width/2,0),(-width/2,height),(width/2,height) )), , .

, turtle.stamp , .

+4

, . turtle.shape('square') , . . , .

+3

, .

- . , screen.register_shape() , turtle.turtlesize() , :

from turtle import Turtle, Screen

STAMP_SIZE = 20  # size of the square turtle shape

WIDTH, LENGTH = 25, 125

yertle = Turtle(shape="square")
yertle.penup()

yertle.turtlesize(WIDTH / STAMP_SIZE, LENGTH / STAMP_SIZE)

yertle.goto(100 + LENGTH//2, 100)  # stamps are centered, so adjust X

yertle.stamp()

screen = Screen()
screen.exitonclick()

, , , tkinter, :

from turtle import Turtle, Screen
import tkinter as _

_.ROUND = _.BUTT

WIDTH, LENGTH = 25, 125

yertle = Turtle()
yertle.width(WIDTH)
yertle.penup()

yertle.goto(100, 100)

yertle.pendown()

yertle.forward(LENGTH)

screen = Screen()
screen.exitonclick()
+1

, ?

turtle.width(...)

, , .

0

All Articles