This commit is contained in:
2021-09-07 17:01:44 -07:00
parent 51da4b5f65
commit 4d625f36c4
4 changed files with 38 additions and 14 deletions
Vendored
BIN
View File
Binary file not shown.
+3
View File
@@ -55,6 +55,9 @@ public class Canvas {
} }
public void drawSquare(int radius, int x, int y, int r, int g, int b, int a){ 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 sign = 0; sign < 4; sign ++){
for(int offsetY = 0; offsetY < radius; offsetY ++){ for(int offsetY = 0; offsetY < radius; offsetY ++){
for(int offsetX = 0; offsetX < radius; offsetX ++ ){ for(int offsetX = 0; offsetX < radius; offsetX ++ ){
+35 -14
View File
@@ -4,6 +4,15 @@ import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.Graphics2D; import java.awt.Graphics2D;
// ffmpeg -framerate 60 -i %00d.png -c:v -vf format=yuv420p libx264 output.mp4
// 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 { public class Space {
Body[] bodies; // List of body objects that make up the simulation Body[] bodies; // List of body objects that make up the simulation
@@ -59,7 +68,13 @@ public class Space {
Canvas canvas = new Canvas( (int) this.height, (int) this.width, 255,255,255,255); Canvas canvas = new Canvas( (int) this.height, (int) this.width, 255,255,255,255);
for(int i = 0; i < this.bodies.length; i ++){ for(int i = 0; i < this.bodies.length; i ++){
canvas.drawSquare(5, (int) this.bodies[i].getXpos(), (int) this.bodies[i].getYpos(), 255, 255, 255, 255); if(i ==0){
canvas.drawSquare(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);
}
} }
File f = null; File f = null;
@@ -75,27 +90,33 @@ public class Space {
public static void main(String args[]){ public static void main(String args[]){
Body testBody = new Body(2000000, 375, 375, 0, 0); Body[] bodies = new Body[1000];
Body testBody2 = new Body(2, 500, 400, 0, -.5); bodies[0] = new Body(2000000, 540, 360, 0, 0);
Body testBody3 = new Body(2, 200, 400, 0, .5); // bodies[1] = new Body(2, 500, 400, 0, -.5);
Body testBody4 = new Body(2, 200, 500, .5, 0); // bodies[2] = new Body(2, 200, 400, 0, .5);
Body testBody5 = new Body(2, 200, 200, -.5, 0); // bodies[3] = new Body(2, 200, 500, .5, 0);
Body[] bodies = new Body[5]; // bodies[4] = new Body(2, 200, 200, -.5, 0);
bodies[0] = testBody; // bodies[5] = new Body(2, 150, 150, -.5, .2);
bodies[1] = testBody2; // bodies[6] = new Body(2, 300, 300, -.5, 0);
bodies[2] = testBody3; // bodies[7] = new Body(2, 450, 450, -.5, -.3);
bodies[3] = testBody4; // bodies[8] = new Body(2, 225, 556, -.5, -.5);
bodies[4] = testBody5;
Space space = new Space(bodies, 750, 750, .5); for(int i = 1; i < 1000; i ++){
bodies[i] = new Body(2, Math.random() * 800, Math.random() * 650, Math.random() - 1, Math.random() -1);
}
Space space = new Space(bodies, 1080, 720, 3);
int counter = 0; int counter = 0;
while(true){ for(int i = 0; i < 5000; i ++){
space.updateForces(); space.updateForces();
space.updateVelocities(); space.updateVelocities();
space.updatePositions(); space.updatePositions();
//System.out.println(space); //System.out.println(space);
//space.draw(); //space.draw();
space.save(counter); space.save(counter);
System.out.println(counter);
counter ++; counter ++;
} }
BIN
View File
Binary file not shown.