From c33729e03174b12afe68663cfb286d2c1e4ce2b5 Mon Sep 17 00:00:00 2001 From: Lev Date: Wed, 9 Jun 2021 01:47:54 -0500 Subject: [PATCH] Add a circle and a polygon --- CM2030 Graphics Programming/Topic 4/4.2.3/sketch.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CM2030 Graphics Programming/Topic 4/4.2.3/sketch.js b/CM2030 Graphics Programming/Topic 4/4.2.3/sketch.js index 4c9a296..e296cb2 100644 --- a/CM2030 Graphics Programming/Topic 4/4.2.3/sketch.js +++ b/CM2030 Graphics Programming/Topic 4/4.2.3/sketch.js @@ -5,19 +5,25 @@ let Engine = Matter.Engine, let engine; let box1; let box2; -let ground; +let ground1; +let ground2; +let circle, polygon; function setup() { createCanvas(900, 600); // create engine engine = Engine.create(); 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}; 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}); // add bodies to world - World.add(engine.world, [box1, ground1, ground2]); + World.add(engine.world, [box1, ground1, ground2, circle, polygon]); } function draw() { @@ -32,6 +38,8 @@ function draw() { fill(50, 150, 50); drawVertices(ground2.vertices); + drawVertices(circle.vertices); + drawVertices(polygon.vertices); } function drawVertices(vertices)