Mouse position problem
in
Programming Questions
•
2 years ago
Hi !
I'm new with Processing and mostly with programing, I try to create an animation that I saw few month earlier on a website : you click somewhere, a circle begin to grow, then you click somewhere else, another circle begin to grow and when they meet, a sound is made.
So I started to type some code to make circles and sound, discovering Processing aswell, but I have a problem : when i specify coordinates to my circle, the circle follow the mouse... so i tried to specify the x;y in another way (like vars somewhere that grab mouseX and mouseY) but it seems to put the values to 0,0 because my circle appears on the top left corner.
I need some help :p
Here is the code :
- import beads.*;
- AudioContext ac;
- float launch;
- Cercle cercle1;
- void setup() {
- background(192, 64, 0);
- size(400, 400);
- ac = new AudioContext();
- }
- void draw() {
- if (launch == 1) {
- background(192, 64, 0);
- cercle1.display();
- cercle1.drive();
- }
- }
- void mousePressed ()
- {
- cercle1 = new Cercle(1,1,0);
- launch = 1;
- WavePlayer wp = new WavePlayer(ac, (float)Math.random() * 500 + 100, Buffer.SINE);
- Gain g = new Gain(ac, 1, new Envelope(ac, 0.1));
- ((Envelope)g.getGainEnvelope()).addSegment(0, 800, new KillTrigger(g));
- g.addInput(wp);
- ac.out.addInput(g);
- ac.start();
- }
- class Cercle {
- // data
- float largeur;
- float hauteur;
- float swap;
- // constructor
- Cercle (float largeur, float hauteur, float swap){}
- // fonctions
- void display() {
- ellipseMode(CENTER);
- ellipse(mouseX,mouseY,largeur,hauteur);
- }
- void drive() {
- if(largeur < 60)
- {
- if(swap == 0)
- {
- largeur++;
- hauteur++;
- }
- else
- {
- largeur--;
- hauteur--;
- if(largeur == 1)
- { swap = 0; }
- }
- }
- if(largeur == 60)
- {
- swap = 1;
- largeur--;
- hauteur--;
- }
- }
- }
1