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

three-cube

v0.3.0

Published

Create an interactive n1xn2xn3 cube with threejs.

Downloads

37

Readme

THREECube

This package lets you create and interact with a n1 x n2 x n3 arrangement of cubes in threejs. The layers in the arrangement can be turned to specific set of moves or alternatively they can be scrambled. User moves are recorded. Solutions are not available yet. As a lazy hack, the inverse of user moves would work.

A demo of this is hosted here: d0st.me/app/cubes

Installation

If you are using node, install with

npm intall three-cube

If not, just import the module src/index.js. (If you are not using a bundler, take note to fix the imports)

Usage

Create a shiny new 4 x 4 x 4 ThreeCube Object:

currentPuzzle = new THREECube({
		x: 4, // number of cubes in x axis
		y: 4, // number of bubes in y axis
		z: 4, // number of cubes in z axis
		cubeSize: 10, // the size of each cube
		scene: scene, // a three.js scene
		camera: camera, // a three.js camera
		canvas: canvas // rendering canvas
})

Other config options like colors, snap time, turn time, etc are available as optional parameters. Check type files for more information.

When rotated around an axis containing equal number of cubes in both directions, the arrangement is rotated in steps of 90 degrees. If that is not the case the arrangement is rotated in steps of 180 degrees.

To scramble the arrangement use:

// Turn the arrangment 17 times in the random axis, selecting a random layer and direction
currentPuzzle.scramble(17) 

To make specific moves:

currentPuzzle.turn(["x0", "y1'", "z2", "z0'"])

When looking at the arrangement from positive z axis, this will perform the following moves

  1. Turn the first layer in x-axis clockwise. This is an "R" move.
  2. Turn the second layer from top anticlockwise.
  3. Turn the third layer in front clockwise.
  4. Turn the first layer in front anti-clockwise. This is a "F'" move.

Bonus

//Resets the arrangement to initial state.
currentPuzzle.reset()
//Write all the moves made
console.log(currentPuzzle.turns) 
//Remove the cubes from scene. Unbind listeners
currentPuzzle.destroy()

//Convert a singmaster notation to Cube notation. Works only for 3x3x3
THREECube.SingmasterToCubeNotation(["R", "U", "B", "L2"])
THREECube.SingmasterToCubeNotation("R U B L2")

Development

Uses parcel to create commonjs and module js files. After working with the source files, create assets for package consumption using:

npm run build 

This will generate the js files inside dist directory with type files (yes from js). Building requires typescript installed globally.