Skip to content

Instantly share code, notes, and snippets.

@lonekorean
Created June 10, 2018 22:40
Show Gist options
  • Save lonekorean/6c1956568b35d5d6581fc8385b8a6fe2 to your computer and use it in GitHub Desktop.
Save lonekorean/6c1956568b35d5d6581fc8385b8a6fe2 to your computer and use it in GitHub Desktop.
Function to create bodies
createBody(viewportWidth, viewportHeight) {
let x = this.randomize([0, viewportWidth]);
let y = this.randomize([0, viewportHeight]);
let radius = this.randomize(this.options.radiusRange);
let color = this.options.colors[this.bodies.length % this.options.colors.length];
return Matter.Bodies.circle(x, y, radius, {
render: {
fillStyle: color,
opacity: this.options.opacity
},
frictionAir: this.options.airFriction,
collisionFilter: {
group: this.options.collisions ? 1 : -1
},
plugin: {
wrap: {
min: { x: 0, y: 0 },
max: { x: viewportWidth, y: viewportHeight }
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment