npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

realstone

v1.0.0

Published

A JavaScript library for building and simulating interactive contraptions within a physics-based environment.

Downloads

12

Readme

RealStone.js - A library for building and simulating interactive contraptions within a physics-based environment.

Build contrapations with parts.

Think of the Minecraft Redstone system using real-world parts. RealStone.js is a simulation-focused library great for building games or educational tools. RealStone handles all aspects of your simulation while emitting events other outside systems can interact with.

Design Prinicpals

  • Quick and easy design and running of simulated contraptions
  • Opt-in Realism, You decide what level of realism your simulation uses
  • Reasonable defaults and conventions for all physics and world settings
import { RealStone, Button, LEDLight, Wire } from 'realstone';

let lightSwitch = new RealStone();
let button = new Button(0, 0, 0);
let wire = new Wire();
let ledLight = new LEDLight(100, 50, 0);

// Connect button to wire, and wire to LED light
button.connect(wire);
wire.connect(ledLight);

// Add components to RealStone system
lightSwitch.addPart(button);
lightSwitch.addPart(wire);
lightSwitch.addPart(ledLight);

// Simulate pressing the button
button.press();

Part list

| RealStone Part | Minecraft Equivalent | |----------------------|---------------------------| | Wire | Redstone Dust | | Transistor | Redstone Torch | | Power Supply | Redstone Block | | Repeater | Redstone Repeater | | Amplifier | Redstone Comparator | | Button | Button | | Pressure Sensor | Pressure Plate | | Impact Sensor | Target Block | | Motion Detector | Observer | | LED Light | Redstone Lamp |

More Parts are coming. If you'd like to see an additional Part added, please feel free to open a pull request.

Super Easy Rendering

RealStone is available as a Plugin for the Mantra Game Developement Framework and can be rendered in 2d with CSS, Phaser 3 or 3D with Babylon.js

Four ways to to turn on a Light Bulb

Realism vs dynamic gameplay

Striking a balance between realism and dynamic gameplay often leads to situations where an exact simulation would not be appropiate. RealStone simulations are well suited for varying levels of realism depending on your requirements.

Consider a Light Switch contraption. In the following four examples, we demonstrate ascending levels of simulated realism.

Most Basic

In this basic example, we create a light switch without any wires or power source, and all parts are at the default position (0, 0, 0).

import { RealStone, Button, LEDLight } from 'realstone';

let lightSwitch = new RealStone();
let button = new Button(0, 0, 0);
let ledLight = new LEDLight(0, 0, 0);

// Connect button directly to LED light
button.connect(ledLight);

// Add components to RealStone system
lightSwitch.addPart(button);
lightSwitch.addPart(ledLight);

// Simulate pressing the button
button.press();

In this most basic example the entire contraption sits at the (0,0,0) position with no power source. Parts are connected directly to each other without the use of Wires. Triggering the button press event will toggle the light since the two parts are directly connected.

  • no wires used
  • no power source required
  • no spatial awareness ( coordinates ) of parts

With Positioning

In this example we create the same contraption, however we apply spatial positioning so each part is laid out on the grid instead of being stacked on top of each other at starting position.

import { RealStone, Button, LEDLight } from 'realstone';

let lightSwitch = new RealStone();
let button = new Button(0, 0, 0);
let ledLight = new LEDLight(100, 50, 0);

// Connect button directly to LED light
button.connect(ledLight);

// Add components to RealStone system
lightSwitch.addPart(button);
lightSwitch.addPart(ledLight);

// Simulate pressing the button
button.press();

[] - Has spatial position [] - no wires used [] - no power source required

With Wire

Instead of directly connecting the parts together, we can uses Wires to connect parts. A wire has inputs, outputs, carries Signal, and may optionally have eletrical resistance or binary data encoding applied to the Signal as it pases through.

import { RealStone, Button, LEDLight, Wire } from 'realstone';

let lightSwitch = new RealStone();
let button = new Button(0, 0, 0);
let wire = new Wire();
let ledLight = new LEDLight(100, 50, 0);

// Connect button to wire, and wire to LED light
button.connect(wire);
wire.connect(ledLight);

// Add components to RealStone system
lightSwitch.addPart(button);
lightSwitch.addPart(wire);
lightSwitch.addPart(ledLight);

// Simulate pressing the button
button.press();

[]- Has spatial position [] - wires used [] - no power source required

Light with Power

All our previous examples assumed infinite free power was available. By changing the powerRequired setting we can enable power requirements for the contraption. This means we now need to power our contraption with a power source or it will not work.

import { RealStone, Button, LEDLight, Wire, PowerSupply } from 'realstone';

let lightSwitch = new RealStone({ powerRequired: true });
let button = new Button(0, 0, 0);
let wire = new Wire(); // TODO: wire settings
let ledLight = new LEDLight(100, 50, 0); // TOOD: power watter
let powerSupply = new PowerSupply(200, 0, 0); // Adding a power supply // TODO: power settings

// Connect power supply to wire, and wire to other components
powerSupply.connect(wire);
button.connect(wire);
wire.connect(ledLight);

// Add components to RealStone system
lightSwitch.addPart(powerSupply);
lightSwitch.addPart(button);
lightSwitch.addPart(wire);
lightSwitch.addPart(ledLight);

// Simulate pressing the button
button.press();

[] - Has spatial position [] - wires used [] - power source used

Choose your own adventure

As you can see, this opt-in realism design allows for ideal development of contraptions for gaming.

Termonologies

Parts

A Part is a piece of a contrapation such as 'Button', 'LED Light', 'Wire', or 'Power Supply'. Parts are independant units which may be connected to other parts. Parts receive and send Signals. Parts will emit events relevant to their specifc functionality which you can optionally listen for.

Contraptions

A Contraption is a collection of parts which have been connected together in order to process Signal. For example, a "Light Switch" contraption could consist of a Button, Wire, and LED Light.

Signals

Electrical Signal

Electrical signals can also be encoded to data formats like USB through setting values like dPlusVoltage and dMinusVoltage

voltage = 5,    // Volts
current = 1,    // Amps
resistance = 0, // Ohms
capacitance = 0, // Farads
inductance = 0, // Henrys
frequency = 0,  // Hertz (important for AC)
phaseAngle = 0, // Degrees (important for AC)
powerFactor = 1 // Unitless (important for AC)

Light Signal

Light signals are used for optics like LED Light or Laser.

intensity = 1,      // Light intensity (arbitrary units)
wavelength = 550,   // Wavelength in nanometers (visible light spectrum)
direction = 0       // Direction of light in degrees

Test

npm run test

License

Yantra Works 2023 AGPL