【问题标题】:arc() not drawn in Processing 3在处理 3 中未绘制 arc()
【发布时间】:2017-01-19 05:16:27
【问题描述】:

我正在使用 Processing for Python 制作一个程序来绘制分形摆动线,而 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))

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

【问题讨论】:

    标签: python processing


    【解决方案1】:

    我认为这是因为您必须确保 starth

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

     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))
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-21
      • 2013-08-11
      相关资源
      最近更新 更多