Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 在循环中围绕自己的轴旋转每个元素(处理)_Loops_Rotation_Processing_Translate - Fatal编程技术网

Loops 在循环中围绕自己的轴旋转每个元素(处理)

Loops 在循环中围绕自己的轴旋转每个元素(处理),loops,rotation,processing,translate,Loops,Rotation,Processing,Translate,我有一个瓷砖图案,我想绕着它自己的轴旋转每个元素。 现在,我的整个图案都在旋转-围绕左上角第一块瓷砖的轴… 如何设置旋转影响循环中的每个瓷砖? 我试着用translate()等等…但是逻辑完全把我弄糊涂了-我的意思是我没有理解它 谢谢你的任何帮助或想法 int horizontal; int vertical; void setup() { size(730, 1080); } void draw() { background(0); fill(255); for (ve

我有一个瓷砖图案,我想绕着它自己的轴旋转每个元素。 现在,我的整个图案都在旋转-围绕左上角第一块瓷砖的轴… 如何设置旋转影响循环中的每个瓷砖? 我试着用translate()等等…但是逻辑完全把我弄糊涂了-我的意思是我没有理解它

谢谢你的任何帮助或想法

int horizontal;
int vertical;

void setup() {
  size(730, 1080);
}

void draw() {
  background(0);
  fill(255);


  for (vertical = 0; vertical < 5; vertical++) {

    for (horizontal = 0; horizontal <4; horizontal++) {
      float wave = sin(radians(frameCount));
      pushMatrix();
      rectMode(CENTER);
      rotate(radians(wave*10));
      rect(182*horizontal, 216*vertical, 182, 216);
      popMatrix();
    }
  }
}
int水平;
int垂直;
无效设置(){
尺寸(7301080);
}
作废提款(){
背景(0);
填充(255);
用于(垂直=0;垂直<5;垂直++){
for(horizontal=0;horizontal定义一个旋转矩阵,并将当前矩阵乘以旋转矩阵。
rotate
因此导致旋转(0,0)。
必须围绕(0,0)将矩形居中,旋转它,然后使用以下命令将旋转的矩形移动到所需位置:

translate(182*水平+91216*垂直+108);
旋转(弧度(波浪*10));
矩形模式(中心);
rect(0,0,182,216);

完整代码:

void setup(){
尺寸(7301080);
}
作废提款(){
背景(0);
填充(255);
对于(int-vertical=0;vertical<5;vertical++){

对于(int horizontal=0;horizontal AAAH!这就是诀窍!非常感谢你解释并教我逻辑!非常有用–非常感谢!@Cyrill谢谢。你很好。