Pointing Squares
26 Nov
In this sketch, I’m using the atan2() function to determine the angle from each grid square to the mouse.
This angle is then used to rotate a thick short line so that each square is oriented towards the mouse.
Wave the mouse over the sketch to see the effect of this.
Here’s the main loop:
for (int y = 0; y < nbrRows; ++y) { for (int x = 0; x < nbrCols; ++x) { float px = leftMargin + x*cellWidth + cellWidth/2; float py = topMargin + y*cellHeight + cellHeight/2; float angle = atan2(mouseY-py,mouseX-px); pushMatrix(); translate(px, py); rotate(angle); line(0,0,cellWidth/2,0); popMatrix(); } }