绘制形状后如何更改形状的轮廓颜色(笔画)?

问题描述 投票:0回答:1

我是第一次在Processing中进行编码(以前很熟悉Java),我试图制作一个三角形的网格,当我单击该三角形时,它将填充和笔触更改为另一种颜色。填充发生变化,但笔触仍为默认颜色。这是我的代码:

void setup() {
  size(800, 600); // size of canvas
  triangles = new ArrayList<TriangleClass>();  // Create an empty ArrayList

  int L = 50; // length of triangle side
  double halfStep = L * Math.sqrt(3);

  // all the code about making the grid
} 

void draw() {
  background(0);
  TriangleClass myCurrentTriangle;

  for (int i = 0; i < triangles.size(); i++) {
    // get object from ArrayList
    myCurrentTriangle = triangles.get(i);
    myCurrentTriangle.display();
  } 
} 

void mouseClicked () {
  TriangleClass myCurrentTriangle ;
  for (int i=0; i < triangles.size(); i++) {
    // get object from ArrayList
    myCurrentTriangle = triangles.get(i);
    myCurrentTriangle.mouseOver();
  }
}

class TriangleClass {
  double x1, y1, x2, y2, x3, y3;    // points
  color fill; // fill color
  color stroke; // stroke color
  float mouseSensorX, mouseSensorY;// check point for dist to mouse

  // constructor
  TriangleClass(
    //  ...
    stroke = color(174, 208, 234);
    fill = color(249, 249, 249);
    mouseSensorX = (float) (x1+x2+x3 )/ 3;
    mouseSensorY = (float) (y1+y2+y3 )/ 3;
  }  

  void mouseOver() {
    if (dist(mouseX, mouseY, mouseSensorX, mouseSensorY) < 17) {
      if (fill == color(249, 249, 249)) {
        stroke = color(251, 84, 84);
        fill = color(251,84,84);
      // ... repeated for other colors
    }
  } 

  void display() {
    // show triangle
    stroke(stroke);
    fill(fill);
    triangle((float) x1, (float) y1, (float) x2, (float) y2, (float) x3, (float) y3);
  } 
} 
// =====================================================================
colors processing stroke
1个回答
0
投票

我相信问题是中风重。您所需要做的就是在设置功能的末尾添加以下代码:

strokeWeight(3);

数字越大,轮廓越大。

© www.soinside.com 2019 - 2024. All rights reserved.