加工3中未绘制弧()

2024-05-09 17:29:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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()

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

the output

程序按预期输出((100, 200), 270, 0, (200, 200))。你知道吗

但是,正如您所看到的,它不会绘制任何弧;程序不会中断;这些弧根本不会绘制。为什么会这样,我该怎么解决?你知道吗


Tags: selfdef绘制sincoscoordssketchcentre
1条回答
网友
1楼 · 发布于 2024-05-09 17:29:46

我认为这是因为您必须确保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))

我希望它能解决你的问题:)

相关问题 更多 >