3

I want to have 360 PNG bitmaps, each bitmap is an arc, and presents for a step in a progress. The following bitmaps present for step 60 (60 degree from top) and step 120.

Step 60 Step 120

How to draw these bitmaps in code?

Edit: I can draw it now but do not know how to set the start point at top instead of bottom

import turtle
wn = turtle.Screen
turtle.hideturtle()
turtle.hideturtle()
turtle.ht()
turtle.speed(0)

turtle.pensize(11)
turtle.color("grey")
turtle.circle(200)

turtle.color("red")
turtle.circle(200, 60, 3600)

cv = turtle.getcanvas()
cv.postscript(file="circle.ps", colormode='color')

turtle.done()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Ngo Thanh Nhan
  • 503
  • 2
  • 5
  • 17

2 Answers2

3

Some simple code that draws arc:

import matplotlib.pyplot as plt
from matplotlib.patches import Arc
plt.figure(figsize=(6, 6)) # set image size
plt.subplots_adjust(0, 0, 1, 1) # set white border size
ax = plt.subplot()
for i in range(1, 361):
    plt.cla() # clear what's drawn last time
    ax.invert_xaxis() # invert direction of x-axis since arc can only be drawn anti-clockwise
    ax.add_patch(Arc((.5, .5), .5, .5, -270, theta2=i, linewidth=5, color='red')) # draw arc
    plt.axis('off') # hide number axis
    plt.savefig(str(i)+'.png', facecolor='black') # save what's currently drawn

You might need to add some more code to get the effect of your pictures. Attaching what the result looks like:

enter image description here

ZisIsNotZis
  • 1,570
  • 1
  • 13
  • 30
2

Using this answer as a guide, first we need a program to draw and dump the images:

from turtle import Screen, Turtle

def save(counter=[1]):  # dangerous default value
    screen.getcanvas().postscript(file="arc{0:03d}.eps".format(counter[0]))
    counter[0] += 1

screen = Screen()
screen.setup(330, 330)
screen.colormode(255)

turtle = Turtle(visible=False)
turtle.speed('fastest')

turtle.penup()
turtle.goto(-150, -150)

turtle.begin_fill()
for _ in range(4):
    turtle.forward(300)
    turtle.left(90)
turtle.end_fill()

turtle.home()
turtle.width(10)
turtle.color(183, 0, 2)
turtle.sety(140)
turtle.pendown()

save()

for _ in range(360):
    turtle.circle(-140, 1)
    save()

I parted with the cited answer at step 6 and switched over to ezgif.com to make this animated PNG:

enter image description here

cdlane
  • 40,441
  • 5
  • 32
  • 81
  • Thanks so much. I can convert the "eps" files to png by ImageMagick tool: `magick mogrify -format png -density 300 -colorspace sRGB -background transparent -units PixelsPerInch -resize 330x330 *.eps` – Ngo Thanh Nhan Oct 24 '18 at 09:58