Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
trajectory = [],
i, id, k;
// initialize trajectory conatiner
for (id = 0; id < scenario.params.num_obj; id++) { //id = 0 corresponds to world!
trajectory[id] = [];
}
// run the engine
for (i = 0; i < numsteps; i++) {
for (id = 0; id < scenario.params.num_obj; id++) { //id = 0 corresponds to world!
// Now it is a design choice of whether to use keys or to use numbers
trajectory[id][i] = {};
for (k of ['position', 'velocity', 'mass']){
if (typeof scenario.engine.world.bodies[id][k] === 'object') {
trajectory[id][i][k] = Matter.Common.clone(scenario.engine.world.bodies[id][k], true); // can only clone objects, not primitives
} else {
trajectory[id][i][k] = scenario.engine.world.bodies[id][k]; // can only clone objects, not primitives
}
}
}
Engine.update(scenario.engine);
}
jsonfile.writeFileSync(sim_file, trajectory, {spaces: 2});
};
"use strict";
/**
* A tool for for running and testing example scenes.
* @module Demo
*/
const Matter = require('matter-js');
const Common = Matter.Common;
const Demo = module.exports = {};
const Gui = require('matter-tools').Gui;
const Inspector = require('matter-tools').Inspector;
const ToolsCommon = require('./Common');
Demo._isIOS = window.navigator && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
Demo._matterLink = 'http://brm.io/matter-js/';
/**
* Creates a new demo instance.
* See example for options and usage.
* @function Demo.create
* @param {} options
*/
Demo.create = function(options) {
/**
* A tool for inspecting worlds.
* @module Inspector
*/
const Inspector = module.exports = {};
const $ = require('jquery');
require('../../node_modules/jstree/dist/jstree.min');
const ToolsCommon = require('./Common');
const Serializer = require('matter-tools').Serializer;
const km = require('keymaster');
const Matter = require('matter-js');
const Body = Matter.Body;
const Bounds = Matter.Bounds;
const Composite = Matter.Composite;
const Common = Matter.Common;
const Events = Matter.Events;
const Mouse = Matter.Mouse;
const Query = Matter.Query;
const Vertices = Matter.Vertices;
const Vector = Matter.Vector;
const MouseConstraint = Matter.MouseConstraint;
var $body;
/**
* Creates an inspector
* @function Gui.create
* @param {engine} engine
* @param {render} [render]
* @param {object} options
* @return {inspector} The created inspector instance.
import React, { Component } from "react";
import { StatusBar, Dimensions } from "react-native";
import { GameEngine } from "react-native-game-engine";
import { Physics, CreateBox, MoveBox, CleanBoxes, Shake } from "./systems";
import { Box } from "./renderers";
import Matter from "matter-js";
import { Accelerometer } from 'react-native-sensors';
Matter.Common.isElement = () => false; //-- Overriding this function because the original references HTMLElement
export default class AccelerometerExample extends Component {
constructor() {
super();
this.accelerometer = new Accelerometer({ updateInterval: 16 });
}
componentDidMount() {
this.accelerometer.pairwise().subscribe(([r1, r2]) => {
this.refs.engine.publishEvent({ type: "accelerometer", x: r2.x - r1.x, y: r2.y - r1.y });
})
}
componentWillUnmount() {
this.accelerometer.stop();
}
copy = function(thing) {
if (typeof thing == 'object') {
return Matter.Common.clone(thing, true)
} else {
return thing;
}
};
import React, { Component } from "react";
import { StatusBar, Dimensions } from "react-native";
import { GameEngine } from "react-native-game-engine";
import { Physics, CreateBox, MoveBox, CleanBoxes } from "./systems";
import { Box } from "./renderers";
import Matter from "matter-js";
Matter.Common.isElement = () => false; //-- Overriding this function because the original references HTMLElement
export default class RigidBodies extends Component {
constructor() {
super();
}
render() {
const { width, height } = Dimensions.get("window");
const boxSize = Math.trunc(Math.max(width, height) * 0.075);
const engine = Matter.Engine.create({ enableSleeping: false });
const world = engine.world;
const body = Matter.Bodies.rectangle(width / 2, -1000, boxSize, boxSize, { frictionAir: 0.021 });
const floor = Matter.Bodies.rectangle(width / 2, height - boxSize / 2, width, boxSize, { isStatic: true });
const constraint = Matter.Constraint.create({
label: "Drag Constraint",
import React, { Component } from "react";
import { StatusBar, Dimensions } from "react-native";
import { ComponentEntitySystem } from "../../react-native-game-engine";
import { Physics, CreateBox, MoveBox, CleanBoxes } from "./systems";
import { Box } from "./renderers";
import Matter from "matter-js";
Matter.Common.isElement = () => false; //-- Overriding this function because the original references HTMLElement
export default class RigidBodies extends Component {
constructor() {
super();
}
render() {
const { width, height } = Dimensions.get("window");
const boxSize = Math.trunc(Math.max(width, height) * 0.075);
const engine = Matter.Engine.create({ enableSleeping: false });
const world = engine.world;
const body = Matter.Bodies.rectangle(width / 2, -1000, boxSize, boxSize, { frictionAir: 0.021 });
const floor = Matter.Bodies.rectangle(width / 2, height - boxSize / 2, width, boxSize, { isStatic: true });
const constraint = Matter.Constraint.create({
label: "Drag Constraint",