Particle add and drag
in
Programming Questions
•
1 year ago
Hello,
I have problem with my lock particle...I want forbiden the creation of particle when this one is lock for the drag.
I white a note on the Sketch where the problem is.
Thank you
I have problem with my lock particle...I want forbiden the creation of particle when this one is lock for the drag.
I white a note on the Sketch where the problem is.
Thank you
- Molecule mlcl ;
color colorAtom = color( 0, 0, 0, 255) ; // blanc
void setup() {
size (400, 400) ; frameRate(25) ;
mlcl = new Molecule() ;
}
void draw() {
background(255, 30, 30) ;
// fonction class Molecule
// call Molecule for Atom
mlcl.displayAtomMolecule2D(25, colorAtom) ; // class.void(diameter of atome)
mlcl.updateAtomMolecule2D(25) ;
mlcl.mvtAtomMolecule2D() ;
// call Molecule
mlcl.drawMolecule2D() ;
}
void mousePressed()
{
mlcl.addAtomMolecule2D(mouseX, mouseY ) ;
}
class Molecule
{
Atome atm ;
ArrayList<Atome> listeA; // Crée une liste d'après une class ou une librairie.
Molecule()
{
listeA = new ArrayList<Atome>();
}
//::::::::::::::::::::::::::::::::::
////////////////////////THE PROBLE IS HERE\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//::::::::::::::::::::ATOME:::::::::::::::
//:::::::::::add point to molecul
void addAtomMolecule2D(float nAX, float nAY)
{
atm = new Atome(nAX, nAY, 0);
listeA.add(atm) ;
for (int i=0 ; i < listeA.size() ; i++ )
{
atm = (Atome) listeA.get(i) ;
println(atm.lock) ;
}
//if (lockA()) {println("true") ; } else{ println("false"); }
//println(atm.lock_()) ;
}
//::::::::::::::::::::Display / Update / Mvt
void displayAtomMolecule2D(int diam, color cA)
{
for (int i=0 ; i < listeA.size() ; i++ )
{
atm = (Atome) listeA.get(i) ; // acces to everything in the list
atm.displayClassAtome2D(diam, cA) ;
}
}
//::::::::::::::::::::::::update
void updateAtomMolecule2D(int diam)
{
for (int i=0 ; i < listeA.size() ; i++ )
{
atm = (Atome) listeA.get(i) ; // acces to everything in the list
atm.updateClassAtome2D(diam) ;
println(atm.lock_()) ;
}
}
//:::::::::::::::mouvement
void mvtAtomMolecule2D()
{
for (int i=0 ; i < listeA.size() ; i++ )
{
atm = (Atome) listeA.get(i) ; // acces to everything in the list
atm.mvtAtom2D(2.0 , 2.0) ;
}
}
//::::::::::::MOLECULE::::::::::::::::::::::::::::::::::::
//::::::draw molecul
void drawMolecule2D()
{
//draw molecule
fill(0,0,0,30) ;
stroke(255,255,255,255) ;
strokeWeight(1) ;
beginShape() ;
for (Atome a: listeA ) { vertex(a.x, a.y) ; }
endShape(CLOSE) ;
}
//::::::update atome
//::::::::::::::::::
}
class Atome
{
float x, y, z ;
boolean inside, lock ;
color inAtom = color (255, 255, 255, 255) ; // noir
Atome (float aX, float aY, float aZ )
{
x = aX ; y = aY ; z = aZ ;
}
// Detection the cursor is on the atom
boolean detection2D (int d)
{
float disX = x - mouseX ;
float disY = y - mouseY ;
if (sqrt(sq(disX) + sq(disY)) < d / 2 ) { return true ; } else { return false ; }
}
// return if Atom is lock or not
boolean lock_()
{
if (lock) { return true ; } else { return false ; }
}
//::::::::::2D
void mvtAtom2D ( float aMX, float aMY)
{
float nx = random( -aMX, aMX );
float ny = random( -aMY, aMY );
x = x +nx ;
y = y +ny ;
}
// update atome ( position, detection...)
void updateClassAtome2D ( int diam ) {
strokeWeight(diam) ;
if(detection2D(diam)) { inside = true ; } else { inside = false ; }
if(mousePressed && inside) { lock = true; }
if(!mousePressed) { lock = false; }
if(lock) { x = mouseX; y = mouseY; }
}
// Display the property of Atome
void displayClassAtome2D ( int diam, color cA ) {
strokeWeight(diam) ;
if(inside) {
fill(cA) ; stroke(cA) ;
} else {
fill(inAtom) ; stroke(inAtom) ;
inside = false ;
}
point (x, y) ;
// test
//if(!lock_()) { println ("false") ; } else { println ("true") ; }
}
//:::::::::::::::
}
1