简体   繁体   English

用随机旋转java +处理绘制图像

[英]draw images with random rotation java + processing

I'm drawing arrows using java and I can draw them straight but now I need to have the arrows pointing in different directions我正在使用 java 绘制箭头,我可以直接绘制它们,但现在我需要让箭头指向不同的方向

in my current code, I draw a triangle and then a square.在我当前的代码中,我先画一个三角形,然后再画一个正方形。

so is there a way to group the two after they've been drawn and then rotate them at a random angle那么有没有办法在绘制后将两者分组,然后以随机角度旋转它们

right now I'm only able to rotate the triangle and square separately, causing some messy thing现在我只能分别旋转三角形和正方形,造成一些混乱

   void setup() {
  size(400, 400);
}

void draw() {
  float r = random(24, 64);
  background(255);
 
drawArrow(r);
//drawPlus(r);
saveFrame("dataArrow/plus####.png");

  if (frameCount == 100) {
    exit();
  }
}
void drawArrow(float r){
 
 
  float base = r * 2;
  float xStart = random(1, width-base - 1);
  float xEnd = xStart + base;
  float k = 0.5 * base;
  float y = random(k, width-k);
  float middleBase = base/2 + xStart;
  float rectSide = 0.5 * base;
  float rectX1 = middleBase - rectSide/2;
  float rectX2 = middleBase + rectSide/2;
 fill(0);
  triangle(xStart, y, xEnd, y, middleBase,  y - k);
  rect(rectX1, y, rectSide, rectSide);
 }

not sure if this exactly what you mean but here is how to move things around不确定这是否正是您的意思,但这里是如何移动事物

push and pop matrix allows you to organize things that should have the same translations push 和 pop matrix 允许您组织应该具有相同翻译的内容

https://processing.org/reference/pushMatrix_.html https://processing.org/reference/pushMatrix_.html

https://processing.org/reference/rotate_.html https://processing.org/reference/rotate_.html

https://processing.org/reference/translate_.html https://processing.org/reference/translate_.html

basic example基本例子

pushMatrix();//start of new translation and rotation things
translate(xAmount,yAmount);//this moves the origin
rotate(angle);//this rotates around origin
//drawing around the point of rotation 0,0 here
//drawing...
popMatrix();//reset all translations and rotations to before

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM