简体   繁体   中英

Turtle Graphics displaying pixelated graphics

I created a random spot painting generator program as part of the course that I'm following. My code involves using the turtle.dot() function to create dots anywhere the turtle goes. The actual logic seems to work fine but it's creating pixelated dots, as in, blurred images.

The course videos have perfect outputs - exactly how circles should be.

I switched from VSCode to PyCharm but that didn't help. I also created a bunch of other Turtle Graphics programs - Spirograph generators, Random walk and none of them produce sharp objects on screen, as you'd expect from a 21st century machine.

I cannot figure out what the issue is. Is it the code? display drivers? or some bug?

Here's the code:

import turtle
turtle.colormode(255)

t = turtle.Turtle()
s = turtle.Screen()
t.penup()
t.speed(0)
t.setpos(-200, -200)

for m in range(10):
    for n in range(10):
        t.dot(20, 'red')
        t.forward(50)
    t.setx(-200)
    t.sety(t.ycor()+50)

s.exitonclick()

Notice how the spots look like polygons and not, circles:

注意这些点看起来像多边形而不是圆形。

I'm pretty sure that you should be using something other than python turtle if you want RTX level graphics. That's just how turtle is, it was made to be like the first robot ever invented. named a turtle. http://cyberneticzoo.com/cyberneticanimals/1969-the-logo-turtle-seymour-papert-marvin-minsky-et-al-american/

One thing that you could try though is turtle.shape() and turtle.stamp() like this:

import turtle
turtle.colormode(255)

t = turtle.Turtle()
s = turtle.Screen()
t.penup()
t.speed(0)
t.setpos(-200, -200)

for m in range(10):
    for n in range(10):
        t.shape("circle")
        t.stamp()
        t.forward(50)
    t.setx(-200)
    t.sety(t.ycor()+50)


s.exitonclick()

Its not perfect but you can figure it out.

You may be blaming your code when the problem is actually your environment . Your dot() -based code generates great circles on my system:

在此处输入图片说明

And if we take a closer look, they are nicely anti-alised:

在此处输入图片说明

You teacher may just have a better graphics subsystem and/or display. We can try turtle's circle() method:

turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()

But that doesn't look better than dot() :

在此处输入图片说明

Which the closeup confirms:

在此处输入图片说明

But circle() doesn't try very hard with small radii, which we can override using the steps argument:

turtle.circle(10, steps=180)

在此处输入图片说明

And again in closeup:

在此处输入图片说明

@RobertMcNeil's stamp() suggestion produces even worse results on my system:

在此处输入图片说明

Along with a final closeup:

在此处输入图片说明

I'd say stick with your original design and test it on different systems.

from turtle import Screen, Turtle
from random import random

screen = Screen()

turtle = Turtle()
turtle.hideturtle()
turtle.speed('fastest')

turtle.penup()
turtle.setposition(-200, -200)

for _ in range(10):
    for _ in range(10):
        turtle.dot(20, (random(), random(), random()))
        turtle.forward(50)
    turtle.setx(-200)
    turtle.sety(turtle.ycor() + 50)

screen.exitonclick()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM