How to make traer run?
in
Contributed Library Questions
•
2 years ago
Hey Folks,
I am trying to draw Traer Particles on Points.
The points are generated with a noisy Agent class, which is storing them in a Arraylist.
In draw I refer to the arraylist to define the position of the Particles.
Then i draw ellipses on the particles.
Allright so far.
Moreover i made a particle on the mouseposition, which attracts the Ellipsed Particles.
Why does the physic not work?
Sorry for this much code, but I reduced it to the max.
I am trying to draw Traer Particles on Points.
The points are generated with a noisy Agent class, which is storing them in a Arraylist.
In draw I refer to the arraylist to define the position of the Particles.
Then i draw ellipses on the particles.
Allright so far.
Moreover i made a particle on the mouseposition, which attracts the Ellipsed Particles.
Why does the physic not work?
Sorry for this much code, but I reduced it to the max.
- // ---------------------------------------------------------------------------------------- //
- // -- 0. Imports & Variables -------------------------------------------------------------- //
- // ---------------------------------------------------------------------------------------- //
- // Imports
- // -------
- import processing.opengl.*;
-
- import traer.physics.*;
- ParticleSystem physics;
- Particle[] mouse;
- //
- // Variables
- // ---------
- // ------- steemers ------- //
- Steemer1[] steemers1 = new Steemer1[5000];
- //
- // ------- steemers attributes ------- //
- int steemersCount = 1;
- float twirlScale = 750, twirlComplexity = 25, twirlZRange = 4.5;
- float overlayAlpha = 0, steemersAlpha = 15.8, steemersWidth = 0.4;
- //
- // ------- fader ------- //
- float gradient = 255, gradientCount = 0;
- int dir = 1;
- //
- // ------- physics ------- //
- float grav = 10; //GLOBALE GRAVITATION (std 0)
- float drag = 0.6; //GLOBALER LUFTWIDERSTAND (std 0.5)
- // EIGENSCHAFTEN DER PARTIKEL
- float traegheit = 5; //PARTIKELTRÄGHEIT (std 5)
- float PSchwer = 1000000; //ANZIEHUNG AN URSPRÜNGLICHE POSITION (std 1000000)
- float PMinDist = 280; //Traegheit
- // EIGENSCHAFTEN DER MAUS
- float MSchwer = -6100; //ANZIEHUNG AN MAUS
- float MMinDist = 10; //MINIMALE DISTANZ DER ANZIEHUNG DER MAUS (std 1)
- // ------- Global ------- //
- int initSetup = 0;
- ArrayList myListX;
- ArrayList myListY;
- ArrayList Punkte;
- PVector vector;
- Punkt[] punktSammlung_a;
- ArrayList winkelArray;
- // ---------------------------------------------------------------------------------------- //
- // -- 1. Hauptkonstruktor ----------------------------------------------------------------- //
- // ---------------------------------------------------------------------------------------- //
- // function setup()
- // ----------------
- void setup(){
- size(1280,800,OPENGL);
- // hint(DISABLE_OPENGL_2X_SMOOTH); // Turn ON if the graphic sucks
- // hint(DISABLE_DEPTH_TEST); // Turn ON if the graphic sucks
- hint(ENABLE_OPENGL_4X_SMOOTH); // Turn OFF if the graphic sucks
- background(15);
- Punkte = new ArrayList();
- winkelArray = new ArrayList();
- for(int i=0; i<steemers1.length; i++) {
- steemers1[i] = new Steemer1();
- }//END for
- ///////////// PHYSICS
- physics = new ParticleSystem(grav,drag);
- mouse = new Particle[5];
- mouse[0] = physics.makeParticle(-100000, -10000, 0, 0.0);
- mouse[0].setMass(500000);
- mouse[0].makeFixed();
- punktSammlung_a = new Punkt[steemersCount];
- }//END void setup()
- void draw(){
- overlayAlpha = 0;
- background(0);
- fill(0, overlayAlpha);
- noStroke();
- rect(0,0,width,height);
- stroke (gradient, steemersAlpha);
- strokeWeight(steemersWidth);
- physics.tick(4);
- if (initSetup < 1) {
- punktSammlung_a = new Punkt[10000];
- }
- initSetup++;
- mouse[0].position().set( mouseX, mouseY, 0 ); //Set nouse particle
- gradientCount = gradientCount + 1;
- /////// draw agents /////////////////
- for(int i=0; i<steemersCount; i++) {
- steemers1[i].update1();
- }
- ///////////draw PARTICLES (DEFINED in agent class
- for(int j=0; j<Punkte.size(); j++) {
- vector = (PVector)Punkte.get(j);
- //vector = new Punkt(vector.x,vector.y);
- //println( vector.x );
- punktSammlung_a[j] = new Punkt(vector.x,vector.y);
- ellipse(punktSammlung_a[j].base.position().x(),punktSammlung_a[j].base.position().y(),22,22);
- ellipse(punktSammlung_a[j].fly.position().x(),punktSammlung_a[j].fly.position().y(),15,15);
- } //println(gradientCount) ;
- fill(255,0,0,255);
- ellipse(mouseX,mouseY,10,10);
- }
- // ---------------------------------------------------------------------------------------- //
- // -- X.X HELPER -------------------------------------------------------------------------- //
- // ---------------------------------------------------------------------------------------- //
- String timestamp() {
- return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", Calendar.getInstance());
- }
- class Steemer1 {
- PVector p, pOld;
- float stepSize, angle, m;
- boolean isOutside = false;
- float twirlZ, twirlZVelocity = 0.004;
- Steemer1() {
- p = new PVector(random(-100,100)+(width/2),700);
- pOld = new PVector(p.x,p.y);
- stepSize = 1;
- // init twirlZ
- setTwirlZRange(0.4);
- }
- void update1() {
- angle = noise(p.x/twirlScale,p.y/twirlScale,twirlZ) * twirlComplexity;
- winkelArray.add(angle); // add in arrayList
- //println(winkelArray.get(winkelArray.size()-1));
- m = map(angle, 0, 360, 0, 140);
- p.x += cos(m) * stepSize;
- p.y += sin(m) * stepSize;
- // add to arrayList
- Punkte.add(new PVector(p.x, p.y));
- //println(Punkte.get(Punkte.size()-1));
- //println(Punkte);
- //println(Punkte.get);
- /////////// ANGLETEST //////////////
- if (p.y > pOld.y) {
- p.y = 2*pOld.y - p.y;
- }
- ///////////////////CLEAR ARRAYLIST ////////////////
- if (p.y < 200) {
- Punkte.clear();
- //println("cleared");
- }
- pOld.set(p);
- twirlZ += twirlZVelocity;
- isOutside = false;
- }
- void setTwirlZRange(float theTwirlZRange) {
- // small values will increase grouping of the agents
- twirlZ = noise(theTwirlZRange);
- }
- }
- class Punkt {
- Particle fly;
- Particle base;
- float x;
- float y;
- Punkt(float _x, float _y ) {
- x = _x;
- y = _y;
- fly = physics.makeParticle(traegheit, x, y, 90);
- base = physics.makeParticle(1,x,y,8);
- base.makeFixed();
- physics.makeAttraction(fly, base, PSchwer,PMinDist);
- physics.makeAttraction(fly, mouse[0], MSchwer, MMinDist);
- }
- }
1