试图为我的绘图应用程序制作画笔效果,但它开始太厚

时间:2014-10-28 09:22:59

标签: processing

作为课程的一部分,我的任务是在Processing中创建一个绘图应用程序,目标是在我的nexus上运行。但是当这段代码运行时,画笔效果对于第一行看起来很棒,但是线条的重量没有正确重置,所以下一行总是开始太厚,任何帮助都会非常感激。

这是我到目前为止所拥有的

float max = 6;
float thickness = 1;
void setup()
{ 
 size(500, 500);
 smooth();
background(255); 
}
void draw() 
{ 
 if(mousePressed) 
{ 
  if(thickness < max) 
    { 
    line(mouseX, mouseY, pmouseX,pmouseY); 
    strokeWeight(thickness); 
    thickness = thickness+0.25; 
    }
   else 
   { 
     line(mouseX, mouseY, pmouseX,pmouseY);
     strokeWeight(max);
   }
} 
}
void mouseReleased() 
{ 
thickness = thickness/thickness; 
}

1 个答案:

答案 0 :(得分:1)

当程序从上到下执行时,您需要在strokeWeight(thickness);之前调用line(),因此它将使用正确的thickness绘制该行。只需改变这个顺序就可以了。

float max = 6;
float thickness = 1;
void setup()
{ 
  size(500, 500);
  smooth();
  background(255);
}
void draw() 
{ 
  if (mousePressed) 
  { 
    if (thickness < max) 
    { 
      strokeWeight(thickness); // <<<<<<<<<<<<<<<< THIS! :)
      line(mouseX, mouseY, pmouseX, pmouseY); 
      thickness = thickness+0.25;
    }
    else 
    { 
      line(mouseX, mouseY, pmouseX, pmouseY);
      strokeWeight(max);
    }
  }
}
void mouseReleased() 
{ 
  thickness = thickness/thickness;
}