diff --git a/.DS_Store b/.DS_Store index 8b3bb3a..5a14ec4 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Body.java b/Body.java index 3d9a405..ca4259e 100644 --- a/Body.java +++ b/Body.java @@ -2,7 +2,7 @@ public class Body { - public static final double G = 6.673e-5; + public static final double G = 6.673e-6; private double mass; private double px; private double py; @@ -10,6 +10,10 @@ public class Body { private double vy; private double fx; private double fy; + private int a; + private int r; + private int g; + private int b; public Body(double mass, double px, double py, double vx, double vy){ this.px = px; @@ -17,6 +21,12 @@ public class Body { this.vx = vx; this.vy = vy; this.mass = mass; + + this.a = 255; + this.r = (int) (Math.random() * 255); + this.g = (int) (Math.random() * 255); + this.b = (int) (Math.random() * 255); + } @@ -135,6 +145,18 @@ public class Body { public double getNetYforce(){ return this.fy; } + public int getA(){ + return this.a; + } + public int getR(){ + return this.r; + } + public int getG(){ + return this.g; + } + public int getB(){ + return this.b; + } public static void main(String[] args){ diff --git a/Canvas.java b/Canvas.java index 7f9f122..92cfd16 100644 --- a/Canvas.java +++ b/Canvas.java @@ -14,18 +14,13 @@ public class Canvas { public static void main(String[] args){ Canvas test = new Canvas(500, 500, 255, 255, 255, 255); - int radius = 100; + int radius = 5; int x = 250; int y = 250; int a = 255; - for(int i = 0; i < 50000; i++){ - int r = (int) (Math.random() * 256); - int g = (int) (Math.random() * 256); - int b = (int) (Math.random() * 256); - test.drawSquare(radius, x, y, r, g, b, a); - test.display(); - } + test.drawCircle(x, y, radius, 255, 255, 255, 255); + test.display(); } public Canvas(int height, int width, int r, int g, int b, int a){ @@ -50,14 +45,17 @@ public class Canvas { } public void setPixel(int x, int y, int r, int g, int b, int a){ - int p = (a<<24) | (r<<16) | (g<<8) | b; - this.image.setRGB(x, y, p); + if(x < 0 || y < 0 || y >= this.width || x >= this.height){ + return; + } + else{ + int p = (a<<24) | (r<<16) | (g<<8) | b; + this.image.setRGB(x, y, p); + } } public void drawSquare(int radius, int x, int y, int r, int g, int b, int a){ - if(x > this.height -15 || x < 15 || y > this.width - 15 || y < 15){ - return; - } + for(int sign = 0; sign < 4; sign ++){ for(int offsetY = 0; offsetY < radius; offsetY ++){ for(int offsetX = 0; offsetX < radius; offsetX ++ ){ @@ -77,4 +75,16 @@ public class Canvas { } } } + + public void drawCircle(int radius, int x, int y, int r, int g, int b, int a){ + double i, angle, x1, y1; + + for(i = 0; i < 360; i += 0.1) + { + angle = i; + x1 = radius * Math.cos(angle * Math.PI / 180); + y1 = radius * Math.sin(angle * Math.PI / 180); + this.setPixel((int)(x + x1), (int)(y + y1), 255,255,255,255); + } +} } diff --git a/Space.java b/Space.java index c61a89f..fc72f2a 100644 --- a/Space.java +++ b/Space.java @@ -8,9 +8,9 @@ import java.awt.Graphics2D; // ffmpeg -framerate 60 -start_number 1 -i %00d.png -pix_fmt yuv420p out.mp4 // TODO Add circle render method -// TODO Fix random generation of bodies + // TODO Find good timeslice for annimation -// TODO add out of bounds check to setPixel method + public class Space { @@ -69,12 +69,21 @@ public class Space { Canvas canvas = new Canvas( (int) this.height, (int) this.width, 255,255,255,255); for(int i = 0; i < this.bodies.length; i ++){ if(i ==0){ - canvas.drawSquare(10, (int) this.bodies[i].getXpos(), (int) this.bodies[i].getYpos(), 255, 255, 255, 255); + canvas.drawCircle(10, (int) this.bodies[i].getXpos(), (int) this.bodies[i].getYpos(), 255, 255, 255, 255); } else{ - canvas.drawSquare(2, (int) this.bodies[i].getXpos(), (int) this.bodies[i].getYpos(), 255, 255, 255, 255); + int r = this.bodies[i].getR(); + int g = this.bodies[i].getG(); + int b = this.bodies[i].getB(); + int x = (int) (this.bodies[i].getXpos()); + int y = (int) (this.bodies[i].getYpos()); + + canvas.drawSquare(5,x, y, r, g, b, 255); } + + + } File f = null; @@ -90,26 +99,34 @@ public class Space { public static void main(String args[]){ - Body[] bodies = new Body[1000]; - bodies[0] = new Body(2000000, 540, 360, 0, 0); - // bodies[1] = new Body(2, 500, 400, 0, -.5); - // bodies[2] = new Body(2, 200, 400, 0, .5); - // bodies[3] = new Body(2, 200, 500, .5, 0); - // bodies[4] = new Body(2, 200, 200, -.5, 0); - // bodies[5] = new Body(2, 150, 150, -.5, .2); - // bodies[6] = new Body(2, 300, 300, -.5, 0); - // bodies[7] = new Body(2, 450, 450, -.5, -.3); - // bodies[8] = new Body(2, 225, 556, -.5, -.5); + Body[] bodies = new Body[14]; + bodies[0] = new Body(20000000, 960, 540, 0, 0); + bodies[1] = new Body(2, 960, 520, .5, .0); + bodies[2] = new Body(2, 960, 240, -.5, 0); + bodies[3] = new Body(2, 200, 540, 0, .5); + bodies[4] = new Body(2, 750, 540, 0, -.5); - for(int i = 1; i < 1000; i ++){ + bodies[5] = new Body(2, 700, 540, 0, -.5); + bodies[6] = new Body(2, 640, 540, 0, -.5); + bodies[7] = new Body(2, 800, 540, 0, -.5); + bodies[8] = new Body(2, 100, 540, 0, -.5); + bodies[9] = new Body(2, 50, 540, 0, -.5); + bodies[10] = new Body(2, 960, 100, -.5, 0); + bodies[11] = new Body(2, 960, 300, -.5, 0); + bodies[12] = new Body(2, 960, 800, -.5, 0); + bodies[13] = new Body(2, 960, 600, -.5, 0); - bodies[i] = new Body(2, Math.random() * 800, Math.random() * 650, Math.random() - 1, Math.random() -1); + - } + // for(int i = 1; i < 1000; i ++){ - Space space = new Space(bodies, 1080, 720, 3); + // bodies[i] = new Body(2, Math.random() * 1080, Math.random() * 720, Math.random() -.5, Math.random() -.5); + + // } + + Space space = new Space(bodies, 1920, 1080, 1); int counter = 0; - for(int i = 0; i < 5000; i ++){ + for(int i = 0; i < 50000000; i ++){ space.updateForces(); space.updateVelocities(); space.updatePositions(); diff --git a/SpaceTaskHandaler.java b/SpaceTaskHandaler.java new file mode 100644 index 0000000..fed6124 --- /dev/null +++ b/SpaceTaskHandaler.java @@ -0,0 +1,17 @@ +public class SpaceTaskHandaler implements Runnable { + Space state; + public SpaceTaskHandaler(Space state){ + state = this.state; + } + public static void main(String[] args){ + + } + + @Override + public void run() { + for(int i = 0; i < this.state.bodies.length; i ++){ + this.state.bodies[i].calcNetForce(this.state.bodies); + } + + } +} diff --git a/frames/CirclesRender.mp4 b/frames/CirclesRender.mp4 new file mode 100644 index 0000000..546e4a6 Binary files /dev/null and b/frames/CirclesRender.mp4 differ diff --git a/frames/SquareRender.mp4 b/frames/SquareRender.mp4 new file mode 100644 index 0000000..8fdd45e Binary files /dev/null and b/frames/SquareRender.mp4 differ diff --git a/frames/out.mp4 b/frames/out.mp4 deleted file mode 100644 index 165cf6f..0000000 Binary files a/frames/out.mp4 and /dev/null differ