This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body | mass | distance | barycenter | |
---|---|---|---|---|
Sun | 333054.25 | 0.0 | ||
Mercury | 0.06 | 133.8 | 0.000022 | |
Venus | 0.82 | 250.0 | 0.000612 | |
Earth | 1.00 | 345.7 | 0.001038 | |
Mars | 0.11 | 525.5 | 0.000170 | |
Jupiter | 317.85 | 1797.9 | 1.714159 | |
Saturn | 95.17 | 3312.2 | 0.946171 | |
Uranus | 14.54 | 6638.3 | 0.289716 | |
Neptune | 17.15 | 10389.6 | 0.534930 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parser { | |
constructor(text) { | |
this.nextTokenIndex = 0; | |
this.tokenList = []; | |
const reToken = /[0-9]+(\.[0-9]*)?([eE][\+\-]?[0-9]+)?|[A-Za-z_][A-Za-z_0-9]*|\S/g; | |
for(;;) { | |
const match = reToken.exec(text); | |
if (match === null) { | |
break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Token { | |
constructor(text, index) { | |
this.text = text; | |
this.index = index; | |
// Classify the token. | |
if (/^[A-Za-z_]/.test(text)) { | |
this.kind = 'identifier'; | |
} else if (/^[0-9]/.test(text)) { | |
this.kind = 'number'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ParseExpr() { | |
// expr ::= mulexpr { addop mulexpr } | |
let expr = this.ParseMulExpr(); | |
let optoken; | |
while (optoken = this.NextTokenIs(['+', '-'])) { | |
const right = this.ParseMulExpr(); | |
if (optoken.text === '+') { | |
expr = new Expression_Add(optoken, expr, right); | |
} else { | |
expr = new Expression_Subtract(optoken, expr, right); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Expression { | |
constructor(precedence, optoken, arglist) { | |
this.precedence = precedence; | |
this.optoken = optoken; | |
this.arglist = arglist; | |
} | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Expression_Function extends Expression { | |
constructor(token, arglist) { | |
super(9, token, arglist); | |
} | |
PrettyMath() { | |
switch (this.optoken.text) { | |
case 'sqrt': | |
return '\\sqrt{' + this.PrettyMath_SingleArg() + '}'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PrettyMath_Binary_LeftAssoc(opsymbol) { | |
let left = this.arglist[0].PrettyMath(); | |
let right = this.arglist[1].PrettyMath(); | |
// Use parentheses around the left child expression | |
// if its operator precedence is less than this node's precedence. | |
// If it is equal, assume left-associativity means parentheses are not needed. | |
if (this.arglist[0].precedence < this.precedence) { | |
left = '\\left(' + left + '\\right)'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int Mandelbrot(double cr, double ci, int limit) | |
{ | |
int count = 0; | |
double zr = 0.0; | |
double zi = 0.0; | |
double zr2 = 0.0; | |
double zi2 = 0.0; | |
while ((count < limit) && (zr2 + zi2 < 4.001)) | |
{ | |
double tzi = 2.0*zr*zi + ci; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int GenerateZoomFrames(const char *outdir, int numframes, double xcenter, double ycenter, double zoom) | |
{ | |
try | |
{ | |
// Create a video frame buffer with 720p resolution (1280x720). | |
const int width = 1280; | |
const int height = 720; | |
VideoFrame frame(width, height); | |
const int limit = 16000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VideoFrame | |
{ | |
private: | |
int width; | |
int height; | |
std::vector<unsigned char> buffer; | |
public: | |
VideoFrame(int _width, int _height) | |
: width(_width) |