在处理中绘制 rhombus/diamond

drawing a rhombus/diamond on processing

我是处理语言的绝对初学者,我正在努力完成一个小任务。

我的任务是创建一个图形,其中每个正方形中有一个菱形,但反之亦然,叠加菱形中有一个正方形。

我查阅了 Processing References 并找到了一些有用的函数,但我正在为菱形形状而苦苦挣扎。

任何提示都会很好,因为我仍在努力学习它

这是一个简单的数学问题,你只需要根据你想要放入的形状计算你的形状的 4 个位置,我在这里做的是一个关于如何在正方形内放置钻石的例子:

float x,y; //x,y coordinate of the square
float w;  //width of the square

void setup() {

  size(500,500);

 //initializing the coordinates of the square to a random position
  x=random(100,300);
  y=random(100,300);
  w=random(50,300);

}

void draw() {

 //draw black background
 background(0);
 
 //setting up the color and stroke of the shapes
 stroke(255);
 strokeWeight(3);
 noFill();
 
 //drawing the rectangle
 rect(x,y,w,w);
 
 //drawing the diamond inside
 //first point is the middle of the upper side
 float x1= (x+(x+w))/2; 
 float y1= y; 
 
 //second point is the middle of the right side
 float x2= x+w; 
 float y2= (y+(y+w))/2; 
 
 //third point is the middle of the lower side
 float x3= x1; 
 float y3= y+w; 
 
 //forth point is the middle of the left side
 float x4= x; 
 float y4= y2; 
 
 //drawing the diamond using those four points
 quad(x1,y1,x2,y2,x3,y3,x4,y4);

}