Skip to content

Instantly share code, notes, and snippets.

@theAlgorithmist
Created March 30, 2020 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theAlgorithmist/442d45e9101a2ea37a60e865deb2b9c0 to your computer and use it in GitHub Desktop.
Save theAlgorithmist/442d45e9101a2ea37a60e865deb2b9c0 to your computer and use it in GitHub Desktop.
Initialize circle layout inside simulation area
protected __initCircles(): void
{
// Draw the point
this.__drawPoint();
// Draw the circles at pseudo-random locations around the drawing area
const xHigh: number = (this._width - CircleService.MAX_RADIUS) + 0.499;
const yHigh: number = (this._height - CircleService.MAX_RADIUS) + 0.499;
let i: number;
let x: number;
let y: number;
let r: number;
let g: PIXI.Graphics;
let c: TSMT$Circle;
for (i = 0; i < CircleService.NUM_CIRCLES; ++i)
{
x = RandomIntInRange.generateInRange(CircleService.MAX_RADIUS, xHigh);
y = RandomIntInRange.generateInRange(CircleService.MAX_RADIUS, yHigh);
r = RandomIntInRange.generateInRange(CircleService.MIN_RADIUS, CircleService.MAX_RADIUS);
g = new PIXI.Graphics();
c = new TSMT$Circle();
c.x = x;
c.y = y;
c.radius = r;
c.id = i.toString(); // id needs to double as the index into the master array of circle references
// update quadrant(s) for the circle; this requires bounds to be set
c.setBounds(0, 0, this._width, this._height);
// the keys are what matter here ...
if (c.inQuadrant(1)) {
this._quad1[c.id] = true;
}
if (c.inQuadrant(2)) {
this._quad2[c.id] = true;
}
if (c.inQuadrant(3)) {
this._quad3[c.id] = true;
}
if (c.inQuadrant(4)) {
this._quad4[c.id] = true;
}
this._circleRefs.push(c);
this._circleDO.push(g);
this._circles.addChild(g);
g.lineStyle(this.strokeWidth, this.strokeColor);
g.drawCircle(x, y, r);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment