簡體   English   中英

用隨機旋轉java +處理繪制圖像

[英]draw images with random rotation java + processing

我正在使用 java 繪制箭頭,我可以直接繪制它們,但現在我需要讓箭頭指向不同的方向

在我當前的代碼中,我先畫一個三角形,然后再畫一個正方形。

那么有沒有辦法在繪制后將兩者分組,然后以隨機角度旋轉它們

現在我只能分別旋轉三角形和正方形,造成一些混亂

   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);
 }

不確定這是否正是您的意思,但這里是如何移動事物

push 和 pop matrix 允許您組織應該具有相同翻譯的內容

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

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

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

基本例子

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