Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed Grid display.

  • Loading branch information...
commit a4c4b704d22db5aab78640eed70b482d0342280f 1 parent 999464e
Josh Long authored

Showing 3 changed files with 18 additions and 43 deletions. Show diff stats Hide diff stats

  1. +1 1  Attractor.pde
  2. +11 37 Attractors.pde
  3. +6 5 Planet.pde
2  Attractor.pde
@@ -44,7 +44,7 @@ class Attractor{
44 44 // Using the distance of the force vector determine the correct magnitude
45 45 float distance = force.mag();
46 46
47   - float forceMagnitude = (this.density * this.density) / pow(distance, .5);
  47 + float forceMagnitude = (this.density) / pow(distance, .5);
48 48 force.normalize();
49 49 force.mult(forceMagnitude);
50 50
48 Attractors.pde
@@ -9,7 +9,7 @@ int sizeX, sizeY ;
9 9 int gridSizeX, gridSizeY;
10 10
11 11 Attractor gF[] = new Attractor[3];
12   -Planet pl[] = new Planet[1000];
  12 +Planet pl[] = new Planet[10000];
13 13 Grid grid;
14 14
15 15 boolean showAccelerationVectors = false;
@@ -24,7 +24,7 @@ boolean RESET = false;
24 24 void setup(){
25 25 if(! RESET){
26 26 // size(800, 600, OPENGL);
27   - size(1200, 800, P3D);
  27 + size(800, 800, P3D);
28 28
29 29 sizeX = width; sizeY = height;
30 30 gridSizeX = int((sizeX + sizeY)/2) ;
@@ -37,23 +37,6 @@ void setup(){
37 37 cam.setMaximumDistance(50000);
38 38 cam.setRotations( -0.7301672, -0.274728, 0.30156484);
39 39 } // end if(! RESET)
40   -
41   - //------------------------------------------------------------------------------------------
42   - // initialize Grid
43   - int res = 7;
44   - int gridPointsX = gridSizeX / res;
45   - int gridPointsY = gridSizeY / res;
46   - grid = new Grid(gridPointsX, gridPointsY);
47   - float s = 1.5; // scale Grid
48   - for(int i = 0; i < gridPointsY; i++){
49   - for(int j = 0; j < gridPointsX; j++){
50   - int index = i*gridPointsX + j;
51   - float x = j * res * s + (sizeX - gridSizeX*s) / 2;
52   - float y = i * res * s + (sizeY - gridSizeY*s) / 2;
53   - float z = 0;
54   - grid.setGridPoint(index, x, y, z);
55   - } // end for j
56   - } // end for i
57 40
58 41 int border = 0;
59 42 //------------------------------------------------------------------------------------------
@@ -65,13 +48,13 @@ void setup(){
65 48 float radius = random(20, 40);
66 49 color col = color( random(200,255), random(200,255), random(1));
67 50 Attractor nextAttractor = new Attractor(id, new PVector(x,y), radius, col);
68   - nextAttractor.setDensity(15);
  51 + nextAttractor.setDensity(100);
69 52 //nextAttractor.setMinimumDistance(100);
70 53 gF[i] = nextAttractor;
71 54 } // end for i
72 55
73   - this.sun = new Attractor(99, new PVector((width/2), (height/2)), 1, color(200,200,1));
74   - this.sun.setDensity(5);
  56 + this.sun = new Attractor(99, new PVector((width/2), 0), 1, color(200,200,1));
  57 + this.sun.setDensity(10);
75 58
76 59 //------------------------------------------------------------------------------------------
77 60 // initialize Planets
@@ -82,7 +65,7 @@ void setup(){
82 65 float radius = random(5,10);
83 66 color col = color( random(110, 255), random(110, 255), random(110, 220));
84 67 Planet newPlanet = new Planet(id, initialLocation, initialVelocity, radius, col);
85   - newPlanet.setMaxSpeed(100);
  68 + newPlanet.setMaxSpeed(50);
86 69 newPlanet.assignAttractor(gF[0]);
87 70 pl[i] = newPlanet;
88 71 } // end for i
@@ -123,28 +106,19 @@ void draw(){
123 106 PVector normalAcceleration = this.sun.getForce(pl[i].currentLocation);
124 107 pl[i].addAcceleration(normalAcceleration);
125 108
126   - //for(int j = 0; j < pl.length; j++){ if( j != i) pl[i].setNewDirection(pl[j].x, pl[j].y, pl[j].radius, 2000, 1); }
127   -
128 109 pl[i].calculatePosition();
129 110
130 111
131   - //if(frameCount % 500 == 0)
132   - //{
133   - // pl[i].assignAttractor(gF[1]);
134   - //}
  112 + if(frameCount % 500 == 0)
  113 + {
  114 + pl[i].assignAttractor(gF[2]);
  115 + }
135 116
136 117 } // end for i
137 118
138 119
139   - // calculate the grid deformation
140   - grid.REsetGridPointPositionZ();
141   - for(int i = 0; i < gF.length; i++) grid.setGridPointPositionZ( gF[i].location.x, gF[i].location.y, gF[i].radius );
142   - for(int i = 0; i < pl.length; i++) grid.setGridPointPositionZ( pl[i].x, pl[i].y, pl[i].radius );
143   -
144   -
145   - //grid.drawGrid(); // draw grid
  120 +
146 121 for(int i = 0; i < gF.length; i++) gF[i].drawSphere(20, 30); // draw Attractors
147   - //for(int i = 0; i < pl.length; i++) pl[i].drawSphere(10, 20); // draw Planets
148 122 for(int i = 0; i < pl.length; i++) pl[i].drawPSphere();
149 123
150 124 if (showAttractorLabel) for(int i = 0; i < gF.length; i++) gF[i].drawLabel(); // draw AttractorsLabel
11 Planet.pde
@@ -77,15 +77,16 @@ class Planet{
77 77
78 78 void drawPSphere(){
79 79 fill(col);
80   - //stroke(col);
81   - noStroke();
  80 + stroke(col);
  81 + strokeWeight(2);
  82 + //noStroke();
82 83 pushMatrix();
83 84 translate(this.currentLocation.x, this.currentLocation.y, this.currentLocation.z);
84   - sphereDetail(25);
85   - sphere(radius);
  85 + //sphereDetail(25);
  86 + //sphere(radius);
86 87 //ellipse(0,0, radius, radius);
87 88
88   - //point(0,0,0);
  89 + point(0,0,0);
89 90 popMatrix();
90 91 } // end void draw
91 92

0 comments on commit a4c4b70

Please sign in to comment.
Something went wrong with that request. Please try again.