arc() 未在 Processing 3 中绘制

arc() not drawn in Processing 3

我正在使用 Python 的 Processing 来制作一个程序来绘制分形波浪线,但 arc 函数似乎没有绘制任何东西;

size(400,400)
noFill()
strokeCap(SQUARE)
import copy
roadcolour=(255,255,255)
edgecolour=(0,0,0)
roadwidth=10
edgewidth=1
coords=(100,100)
h=0

class Straight:

    def __init__(self,l):
        self.l=l

    def sketch(self):
        newcoords=(coords[0]+(cos(radians(h))*self.l),coords[1]+(sin(radians(h))*self.l))
        strokeWeight(roadwidth+edgewidth)
        stroke(*edgecolour)
        line(coords[0],coords[1],newcoords[0],newcoords[1])
        strokeWeight(roadwidth)
        stroke(*roadcolour)
        line(coords[0],coords[1],newcoords[0],newcoords[1])
        return newcoords,h

class Arc:

    def __init__(self,direction,degs,r):
        self.r=r
        self.dir=direction
        self.degs=degs

    def sketch(self):
        if self.dir=="R":
            centre=(coords[0]+(cos(radians(h+90))*self.r),coords[1]+(sin(radians(h+90))*self.r))
            starth=(h-90)%360
            endh=(starth+self.degs)%360
            newcoords=(centre[0]+(cos(radians(endh))*self.r),centre[1]+(sin(radians(endh))*self.r))
        else:
            centre=(coords[0]+(cos(radians(h-90))*self.r),coords[1]+(sin(radians(h-90))*self.r))
            endh=(h+90)%360
            starth=(endh-self.degs)%360
            newcoords=(centre[0]+(cos(radians(starth))*self.r),centre[1]+(sin(radians(starth))*self.r))
        centre=roundcoords(centre)
        newcoords=roundcoords(newcoords)
        print(centre,starth,endh,newcoords)
        strokeWeight(roadwidth+edgewidth)
        stroke(*edgecolour)
        arc(centre[0],centre[1],self.r*2,self.r*2,radians(starth),radians(endh))
        strokeWeight(roadwidth)
        stroke(*roadcolour)
        arc(centre[0],centre[1],self.r*2,self.r*2,radians(starth),radians(endh))
        return newcoords,h

def roundcoords(coords):
    return (int(coords[0]+0.5),int(coords[1]+0.5))

a=Arc('R',90,100)
a.sketch()
s=Straight(100)
s.sketch()

当我 运行 这段代码时,直线绘制完美,带有所需的黑边,因此:

并且程序按预期输出 ((100, 200), 270, 0, (200, 200))

但是,如您所见,它没有绘制任何弧线;程序不会中断;根本没有绘制弧线。为什么会这样,我该如何解决?

我认为这是因为您必须确保 starth < endh,而在您的示例中并非如此。

相反,您可以绘制这两条弧线之一:

 arc(centre[0],centre[1],self.r*2,self.r*2,radians(endh),radians(starth))    
 arc(centre[0],centre[1],self.r*2,self.r*2,radians(starth),2*PI+radians(endh))

希望能解决你的问题:)