Created
June 10, 2018 22:40
-
-
Save lonekorean/6c1956568b35d5d6581fc8385b8a6fe2 to your computer and use it in GitHub Desktop.
Function to create bodies
This file contains hidden or 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
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