Note that there are some explanatory texts on larger screens.

plurals
  1. POPython turtle.setup() truncates canvas to screen size - how to avoid that?
    primarykey
    data
    text
    <p>To measure the rotation speed of a rod, I need to make a dial with a large number of alternating dark / transparent segments arranged in a circle. The rotating dial will interrupt the light on a photosensor, and then I only need to measure the frequency of light pulses. Python turtle graphics seems like a good idea for drawing this dial.</p> <p>I need to draw this image very large, so as to avoid the stair-step effect on the edges of the segments - I need smooth edges. But if I do turtle.setup(x, y) with either x or y bigger than the screen, the canvas is truncated to fit the screen. How to avoid that?</p> <p>My code is included at the end. See here a screenshot with the truncated canvas for x = y = 1420</p> <p><img src="https://i.stack.imgur.com/Z1CuM.png" alt="truncated canvas screenshot"></p> <p><strong>EDIT:</strong> Just to make it clear - getscreen() / getcanvas() at the end capture this truncated canvas image and save it as-is (truncated) into an EPS file. That's what bothers me. I need the whole circle captured in a high-resolution image file.</p> <p>I am using python-2.7.4 on Ubuntu 13.04</p> <p>This is the code:</p> <pre><code>#!/usr/bin/python # set this to 1 to troubleshoot debug = 0 import turtle import math # image file with the result fname="dial.eps" # number of lines n = 100 # external radius r2 = 700 # length of each line l = round(r2 / 10) r1 = r2 - l # pen thickness # tuned for 50% fill factor at the inner end of each line # (dark stripe and transparent stripe have equal width there) thick = 2 * math.pi * r1 / float(2 * n) print "thickness =", thick # setup screen size to contain the whole circle, plus a little extra border = 20 + thick turtle.setup(2 * r2 + border, 2 * r2 + border) dot = turtle.Turtle() dot.speed(0) dot.hideturtle() # draw crosshairs in the center dot.setpos(l, 0) dot.setpos(-l, 0) dot.home() dot.setpos(0, l) dot.setpos(0, -l) dot.penup() # thickness of lines dot.pensize(thick) for step in range(0, n): a = 360.0 * step / float(n) arad = math.radians(a) x1 = r1 * math.cos(arad) y1 = r1 * math.sin(arad) x2 = r2 * math.cos(arad) y2 = r2 * math.sin(arad) if debug == 1: print "a =", a, "\t x1 =", x1, "\t y1 =", y1, "\t x2 =", x2, "\t y2 =", y2 dot.penup() dot.setpos(x1, y1) dot.pendown() dot.setpos(x2, y2) ts = turtle.getscreen() ts.getcanvas().postscript(file=fname) print "Saved image to: ", fname print "All done. Click image to exit." turtle.exitonclick() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload