我正在尝试使用合适的 OOP 方法来让对象在网格单元格内单独旋转。我当前的结果是围绕 0, 0 参考点旋转所有对象,而不是每个对象在其自己的单元格内旋转。
当然,需要的是一个正确的翻译函数,但是当我尝试在innerSquare函数中应用它时translate(x, y); - 这会导致更奇怪的行为。
我仍处于学习的早期阶段 - 任何帮助将不胜感激!
代码可以在这里查看: https://editor.p5js.org/knectar/sketches/BJpI5_BG4
或者直接:
var cols, rows;
var w = 50;
var grid = [];
function setup() {
createCanvas(400, 400);
// load the col / row vars with values that dynamically read from the canvas.
cols = floor(width/w);
rows = floor(height/w);
// load the the array with generic row and column values
for (var j = 0; j < rows; j++){
for (var i = 0; i < …Run Code Online (Sandbox Code Playgroud)