arc()未在Processing 3中绘制

时间:2017-01-18 20:19:45

标签: python processing

我使用Processing for Python制作程序来绘制分形摇摆线,并且弧函数似乎没有绘制任何东西;

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      intent.addCategory(Intent.CATEGORY_OPENABLE);
      intent.setType("*/*");
      String[] mimetypes = {"application/zip", "text/plain"};
      intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
    } else {
      intent.setType("application/zip");
    }
    startActivityForResult(intent, SELECT_ZIP_FILE);

当我运行此代码时,直线绘制完美,具有所需的黑色边缘,因此:

the output

,程序按预期输出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()

然而,正如你所看到的,它并没有画出任何弧线;程序不会中断;弧线根本不是绘制的。为什么会这样,我该如何解决?

1 个答案:

答案 0 :(得分: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))

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