Inserting mouseX & mouseY: please help
in
Programming Questions
•
1 year ago
"hello world" (this is my first processing sketch and post this forum)
i watched a couple hours worth of processing tutorials on youtube (processing 101 series)
that's how i came to code the sketch shown below.
i've tried putting mouseX and mouseY in a variaty of spots but to now avail. could somebody please reply with an example how this can be done?
need this for a class in 4 hours.
i watched a couple hours worth of processing tutorials on youtube (processing 101 series)
that's how i came to code the sketch shown below.
i've tried putting mouseX and mouseY in a variaty of spots but to now avail. could somebody please reply with an example how this can be done?
need this for a class in 4 hours.
- // my first sketch: yay!
void setup(){
size (500,300);
background(0);
stroke(255);
smooth();
noLoop();
}
//my Variables
float x1,y1,x2,y2,rad1,rad2,srad;
int numSides,increment,sx,sy;
void draw(){
for (int deg1=0; deg1<360; deg1=deg1+10)
{
srad=radians(deg1);
sx=int(sin(srad)*100+width/2);
sy=int(cos(srad)*100+height/2);
polygon(5,50,50,sx,sy);
}
}
//my polygon function
void polygon(int sides,int xradius,int yradius,int xcent,int ycent)
{
numSides=sides;
increment=int(360/numSides);
for (int deg=0; deg<360; deg=deg+increment)
{
rad1=radians(deg);
rad2=radians(deg+increment);
x1=sin(rad1)*xradius+xcent;
y1=cos(rad1)*yradius+ycent;
x2=sin(rad2)*xradius+xcent;
y2=cos(rad2)*yradius+ycent;
line(x1,y1,x2,y2);
}
}
1