var DOT_SIZE = 20; var X_START_POS = 100; var Y_START_POS = 80; // ‥‥‥‥‥‥‥‥‥‥‥‥‥□□□ // ‥‥‥‥‥‥〓〓〓〓〓‥‥□□□ // ‥‥‥‥‥〓〓〓〓〓〓〓〓〓□□ // ‥‥‥‥‥■■■□□■□‥■■■ // ‥‥‥‥■□■□□□■□□■■■ // ‥‥‥‥■□■■□□□■□□□■ // ‥‥‥‥■■□□□□■■■■■‥ // ‥‥‥‥‥‥□□□□□□□■‥‥ // ‥‥■■■■■〓■■■〓■‥‥‥ // ‥■■■■■■■〓■■■〓‥‥■ // □□■■■■■■〓〓〓〓〓‥‥■ // □□□‥〓〓■〓〓□〓〓□〓■■ // ‥□‥■〓〓〓〓〓〓〓〓〓〓■■ // ‥‥■■■〓〓〓〓〓〓〓〓〓■■ // ‥■■■〓〓〓〓〓〓〓‥‥‥‥‥ // ‥■‥‥〓〓〓〓‥‥‥‥‥‥‥‥ var dataSet = [ "BK","BK","BK","BK","BK","BK","BK","BK","BK","BK","BK","BK","BK","BG","BG","BG", "BK","BK","BK","BK","BK","BK","RD","RD","RD","RD","RD","BK","BK","BG","BG","BG", "BK","BK","BK","BK","BK","RD","RD","RD","RD","RD","RD","RD","RD","RD","BG","BG", "BK","BK","BK","BK","BK","BR","BR","BR","BG","BG","BR","BG","BK","RD","RD","RD", "BK","BK","BK","BK","BR","BG","BR","BG","BG","BG","BR","BG","BG","RD","RD","RD", "BK","BK","BK","BK","BR","BG","BR","BR","BG","BG","BG","BR","BG","BG","BG","RD", "BK","BK","BK","BK","BR","BR","BG","BG","BG","BG","BR","BR","BR","BR","RD","BK", "BK","BK","BK","BK","BK","BK","BG","BG","BG","BG","BG","BG","BG","RD","BK","BK", "BK","BK","RD","RD","RD","RD","RD","BL","RD","RD","RD","BL","RD","BK","BK","BK", "BK","RD","RD","RD","RD","RD","RD","RD","BL","RD","RD","RD","BL","BK","BK","BR", "BG","BG","RD","RD","RD","RD","RD","RD","BL","BL","BL","BL","BL","BK","BK","BR", "BG","BG","BG","BK","BL","BL","RD","BL","BL","YL","BL","BL","YL","BL","BR","BR", "BK","BG","BK","BR","BL","BL","BL","BL","BL","BL","BL","BL","BL","BL","BR","BR", "BK","BK","BR","BR","BR","BL","BL","BL","BL","BL","BL","BL","BL","BL","BR","BR", "BK","BR","BR","BR","BL","BL","BL","BL","BL","BL","BL","BK","BK","BK","BK","BK", "BK","BR","BK","BK","BL","BL","BL","BL","BK","BK","BK","BK","BK","BK","BK","BK" ]; function getRgbColor(colorType) { var colorHash = { //"BK":"#000000", // black "BK":"#dcaa6b", // black "WH":"#FFFFFF", // white "BG":"#FFCCCC", // beige "BR":"#800000", // brown "RD":"#FF0000", // red "YL":"#FFFF00", // yellow "GN":"#00FF00", // green "WT":"#00FFFF", // water "BL":"#0000FF", // blue "PR":"#800080" // purple }; return colorHash[colorType]; } // Matter module aliases var Engine = Matter.Engine, World = Matter.World, Body = Matter.Body, Bodies = Matter.Bodies, Constraint = Matter.Constraint, Composites = Matter.Composites, MouseConstraint = Matter.MouseConstraint; // create a Matter.js engine var engine = Engine.create(document.body, { render: { options: { showAngleIndicator: false, wireframes: false } } }); // add a mouse controlled constraint var mouseConstraint = MouseConstraint.create(engine); World.add(engine.world, mouseConstraint); // a few settings var rows = 10; var yy = 600 - 50 - 40 * rows; var i = 0; var stack = Composites.stack(X_START_POS, Y_START_POS, 16, 16, 0, 0, function(x, y, column, row) { var color = dataSet[i++]; var style = getRgbColor(color); return Bodies.rectangle(x, y, DOT_SIZE, DOT_SIZE, { render: {fillStyle:style }}); }); // create the ground the stack will sit on var ground = Bodies.rectangle(200, 400, 500, 10, { isStatic: true }); // create the wrecking ball var ball = Bodies.circle(-60, 60, 20, { density: 1, frictionAir: 0.001}); // create the rope the ball will swing on var ballRope = Constraint.create({ pointA: { x: 40, y: 60 }, bodyB: ball }); // add all of the bodies to the world World.add(engine.world, [stack, ball, ballRope, ground]); // run the engine Engine.run(engine);