-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rocket_Simulator.pde
76 lines (67 loc) · 1.57 KB
/
Rocket_Simulator.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Rocket Simulator
// by Sinclair Gurny
// Jan 2018
double scale = 20000; // Resolution scaling
double deltaT = 0.005; // time step per tick
int tick_per_frame = 10; // ticks per frame
Earth earth = new Earth();
Rocket rocket = new Rocket( earth );
PImage img;
void setup() {
size( 1080, 720 );
frameRate( 20 );
background( 0 );
PFont font = createFont( "Times New Roman", 16, true );
textFont( font );
img = loadImage( "Earth.png" );
}
void draw() {
long time = millis();
translate( 540, 360 ); // center on center of screen
background(0); // space is the eternal void
for ( int i = 0; i < tick_per_frame; ++i ) {
rocket.tick();
}
earth.draw();
rocket.draw();
output( rocket );
stats();
//println( " ===> " + ( millis() - time ) );
}
void keyPressed() {
// Toggle Engine
if ( key == ' ' ) {
rocket.engine_on = !rocket.engine_on;
}
// Reset screen
if ( key == 'r' ) {
scale = 20000;
deltaT = 0.005;
tick_per_frame = 10;
}
// Simulation Speed
if ( key == 'q' ) { //-
if ( deltaT > 0 ) {
deltaT -= 0.0025;
}
} else if ( key == 'e' ) { //+
deltaT += 0.0025;
}
// Scale
if ( key == 'z' ) {//in
if ( scale > 10000 ) {
scale -= 2500;
}
} else if ( key == 'x' ) {//out
scale += 2500;
}
// Rocket Rotation
if ( key == 'a' ) {//cw
rocket.rotate( -1 );
} else if ( key == 'd' ) {//ccw
rocket.rotate( 1 );
}
if ( key == 'p' ) {
save( "screenshot"+millis()+".png" );
}
}