how do i make shape move relatively on another shape p5.js

假如想象 提交于 2021-01-29 15:35:10

问题


i want to make square shape to be able to move on rectangle shape below it relative to it rotation. please check my code here https://editor.p5js.org/saidabdul80/sketches/-Adu8HzFZ


回答1:


@Said Abdulsalam I think the answer to your question is this. you should move the one object with the same vareable as the the other.

eg:

 //rot for object 1
 int rotY =0;
 
 
 void draw (){
  // object 1
  rectMode(center);
  popmatrix();
  rotate(rotY);
  rect(X,Y,20,20);
  pushMatrix();
  // object moving relative to object 1
  rect(rotY,500,20,20);
  rotY++;
 }

this will rotate rect 1 and move rect2.



来源:https://stackoverflow.com/questions/65923743/how-do-i-make-shape-move-relatively-on-another-shape-p5-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!