Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
royrub
royrub's Profile
1
Posts
2
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Rotation and mouse placement
[5 Replies]
29-Jun-2010 10:08 AM
Forum:
Programming Questions
Hello,
I am new to Processing and I apologize in advance if this is very basic, but I just can't figure it out.
I am trying to make a rectangle rotate according to the mouse location. The thing is that I want it to spin from the center.
In other words, imagine a "T" shape in which the top horizontal bar is fixed, and the vertical bar is spinning relatively.
I am copying where I got to thus far (the bottom bar is spinning from the bottom left corner).
Can anybody give me any ideas as to how to resolve it???
MUCH appreciated!
Roy
___________________
float x;
float y;
float angle1 = 0.0;
float rectaLength = 100;
float rectaWidth = 25;
void setup() {
size(250, 250);
smooth();
fill(0);
}
void draw() {
background(255);
float dx = mouseX - x;
float dy = mouseY - y;
angle1 = atan2(dy, dx);
x = mouseX - (cos(angle1) * rectaLength);
x = mouseX - (cos(angle1) * rectaWidth);
y = mouseY - (sin(angle1) * rectaLength);
y = mouseY - (sin(angle1) * rectaWidth);
recta(113, 187, angle1);
rect (75, 62, 100, 25);
}
void recta(float x, float y, float a) {
pushMatrix();
translate(x, y);
rotate(a);
rect(0, 0, rectaLength, rectaWidth);
popMatrix();
}
«Prev
Next »
Moderate user : royrub
Forum