FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   circle thats follows mousepoint
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: circle thats follows mousepoint  (Read 246 times)
kemo

Email
circle thats follows mousepoint
« on: Sep 29th, 2003, 2:40am »

Could someone hint/advise me how to let this code follow the mousepointer? Where should i implement mouseX, MouseY etc?
 
 
 
void setup()
{
  size(300,300);
  background(102);
  noStroke();
  smooth();
  fill(203,90,70);
  ellipseMode(CENTER_DIAMETER);
}
 
  boolean groei = true;
  float a = 100;
  int x;
  int y;
   
 
void loop()
{
  x = width/2;
  y = height/2;
  ellipse(x, y, a, a);
 
  if (groei==true)
  {
    a=a*1.02;
    if(a>200)
    {
 groei=false;
    }
  }
  else
  {
    if (a>100)
    {
 a=a*0.99;
    }
    else
    {
 
 groei=true;
    }
  }
 
}
 
 
 
benelek

35160983516098 WWW Email
Re: circle thats follows mousepoint
« Reply #1 on: Sep 29th, 2003, 3:24am »

if you mean that you want the centre of the circle to be drawn at (mouseX,mouseY), then the following will work:
 
Code:
void setup()  
{  
  size(300,300);  
  background(102);  
  noStroke();  
  smooth();  
  fill(203,90,70);  
  ellipseMode(CENTER_DIAMETER);  
}  
 
  boolean groei = true;  
  float a = 100;  
  int x;  
  int y;  
   
 
void loop()  
{  
  x = mouseX;   //modified line  
  y = mouseY;   //modified line
  ellipse(x, y, a, a);  
 
  if (groei==true)  
  {  
    a=a*1.02;  
    if(a>200)  
    {  
 groei=false;  
    }  
  }  
  else  
  {  
    if (a>100)  
    {  
 a=a*0.99;  
    }  
    else  
    {  
   
 groei=true;  
    }  
  }  
 
}
 
Bijeoma

myloveiloved
Re: circle thats follows mousepoint
« Reply #2 on: Sep 29th, 2003, 4:28am »

or were you wanting the inner circle to scale in response to mouse movement?
 
bryan
 
kemo

Email
Re: circle thats follows mousepoint
« Reply #3 on: Sep 29th, 2003, 9:23am »

It works just fine! But i want the circle to begin in the middle of the screen. Where it then follows the mousepointer.
 
Must it be done in a seperate function?
 
toxi

WWW
Re: circle thats follows mousepoint
« Reply #4 on: Sep 29th, 2003, 2:52pm »

this is how my version would look like, using the sin() function to modulate the circle's radius...
 
Code:
float xpos,ypos;
float angle;
 
void setup() {
  size(300,300);
  xpos=width/2;
  ypos=height/2;
  noStroke();
  smooth();
  fill(203,90,70);
  ellipseMode(CENTER_DIAMETER);  
}
 
void loop() {
  background(224);
  xpos+=(mouseX-xpos)*0.1;
  ypos+=(mouseY-ypos)*0.1;
  angle+=0.05;
  float radius=100+100*sin(angle);
  ellipse(xpos,ypos,radius,radius);
}
 

http://toxi.co.uk/
Pages: 1 

« Previous topic | Next topic »