Add a circle and a polygon

This commit is contained in:
Lev
2021-06-09 01:47:54 -05:00
parent ad28871d8e
commit c33729e031

View File

@ -5,19 +5,25 @@ let Engine = Matter.Engine,
let engine; let engine;
let box1; let box1;
let box2; let box2;
let ground; let ground1;
let ground2;
let circle, polygon;
function setup() { function setup() {
createCanvas(900, 600); createCanvas(900, 600);
// create engine // create engine
engine = Engine.create(); engine = Engine.create();
box1 = Bodies.rectangle(200, 200, 80, 80, {restitution: .8, friction: 0.5}); box1 = Bodies.rectangle(200, 200, 80, 80, {restitution: .8, friction: 0.5});
circle = Bodies.circle(80, 0, 20, {restitution: .8, friction: 0.5});
polygon = Bodies.polygon(100, 0, 5, 30, {restitution: .8, friction: 0.5, frictionAir: 0.1});
Matter.Body.setMass(polygon, 0.2);
Matter.Body.setMass(circle, 20);
let options = {isStatic: true, angle: Math.PI * 0.06}; let options = {isStatic: true, angle: Math.PI * 0.06};
ground1 = Bodies.rectangle(100, 350, 500, 10, {isStatic: true, angle: Math.PI * 0.06}); ground1 = Bodies.rectangle(100, 350, 500, 10, {isStatic: true, angle: Math.PI * 0.06});
ground2 = Bodies.rectangle(500, 500, 500, 10, {isStatic: true, angle: Math.PI * -0.06}); ground2 = Bodies.rectangle(500, 500, 500, 10, {isStatic: true, angle: Math.PI * -0.06});
// add bodies to world // add bodies to world
World.add(engine.world, [box1, ground1, ground2]); World.add(engine.world, [box1, ground1, ground2, circle, polygon]);
} }
function draw() { function draw() {
@ -32,6 +38,8 @@ function draw() {
fill(50, 150, 50); fill(50, 150, 50);
drawVertices(ground2.vertices); drawVertices(ground2.vertices);
drawVertices(circle.vertices);
drawVertices(polygon.vertices);
} }
function drawVertices(vertices) function drawVertices(vertices)