Skip to content

Commit

Permalink
screen.h: Factor out the minimal graphics stuff, implement a dumb VT1…
Browse files Browse the repository at this point in the history
…00 mode for POSIX

And clang-format and detab.
And add a Makefile.
And fix all -W -Wall warnings from Clang.
  • Loading branch information
Quuxplusone committed Jan 24, 2021
1 parent 5072419 commit 1788caf
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 330 deletions.
7 changes: 7 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BasedOnStyle: LLVM
Standard: Cpp11
IndentWidth: 4
UseTab: Never
AccessModifierOffset: -4
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
11 changes: 2 additions & 9 deletions Collision.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include "screen.h"
#include "vec2.h"

#define M_PI 3.14159265358979323846

constexpr float G=3.0f;

struct Body
Expand Down Expand Up @@ -34,8 +33,7 @@ struct Body
acc=0;
}

Body(float m,float r)
:m(m),r(r)
Body(float m,float r) : r(r), m(m)
{
pos=0;
vel=0;
Expand Down Expand Up @@ -66,9 +64,6 @@ struct Body

void Plot(const Body& body, Screen& scr) //render the body
{
vec2 O=body.pos;
vec2 X=body.pos + 0.5f*body.vel;

scr.PlotCircle(body.pos.x,body.pos.y,body.r);
}

Expand All @@ -81,12 +76,10 @@ int main()
{
srand (static_cast <unsigned> (time(0)));

setup();
Screen scr(0,0,5);

const int n=20000;
constexpr float dt=1.0/40.0f;
constexpr float r=3.5f,R=30.0f;

/* Initializing first galaxy */
Body Centre1(2000.0f,2.5f);
Expand Down
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CXXFLAGS=-std=c++17

all: ThreeBody Sun-Earth-Moon Collision

ThreeBody: ThreeBody.cpp screen.h vec2.h
$(CXX) $(CXXFLAGS) ThreeBody.cpp -o $@

Sun-Earth-Moon: Sun-Earth-Moon.cpp screen.h vec2.h
$(CXX) $(CXXFLAGS) Sun-Earth-Moon.cpp -o $@

Collision: Collision.cpp screen.h vec2.h
$(CXX) $(CXXFLAGS) Collision.cpp -o $@

clean:
rm -f ThreeBody Sun-Earth-Moon Collision

.PHONY: clean
7 changes: 1 addition & 6 deletions Sun-Earth-Moon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ struct Body
acc=0;
}

Body(float m,float r)
:m(m),r(r)
Body(float m,float r) : r(r), m(m)
{
pos=0;
vel=0;
Expand Down Expand Up @@ -60,15 +59,11 @@ struct Body

void Plot(const Body& body, Screen& scr)
{
vec2 O=body.pos;
vec2 X=body.pos + 0.5f*body.vel;

scr.PlotCircle(body.pos.x,body.pos.y,body.r);
}

int main()
{
setup();
Screen scr(0,0,10);

constexpr float dt=1.0/100.0f;
Expand Down
4 changes: 1 addition & 3 deletions ThreeBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ struct Body
acc=0;
}

Body(float m,float r)
:m(m),r(r)
Body(float m,float r) : r(r), m(m)
{
pos=0;
vel=0;
Expand Down Expand Up @@ -94,7 +93,6 @@ void Plot(const Body& body, Screen& scr)

int main()
{
setup();
Screen scr(0,0,200);

constexpr float dt=1.0/100.0f;
Expand Down
Loading

0 comments on commit 1788caf

Please sign in to comment.