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

@curtishughes/rubiks-cube

v2.0.2

Published

<img src="assets/classic.gif" height="150px" />

Downloads

5

Readme

Rubik's Cube

A web based Rubik's Cube implementation. The goal of this package was to provide a minimal interface to the rendered Rubik's cube that would allow consumers to implement custom UI elements and build upon the provided functionality.

Features

  • 3D rendered Rubik's Cube
  • Customizable material and textures
  • Exposed Singmaster notation methods
  • Configurable rotation speed
  • Responsive canvas

Installation

NOTE: Three.js is a required peer dependency of this package. It has purposefully been excluded in order to reduce bundle size and allow the consumer to use their preferred version.

yarn add @curtishughes/rubiks-cube three
npm install @curtishughes/rubiks-cube three

Exports

Default:

  • RubiksCube(canvas: HTMLCanvasElement, materials: THREE.MeshBasicMaterial[], speed?: number, width?: string, height?: string)
    • F (clockwise?: boolean, duration?: number): rotate the side currently facing the solver
    • B (clockwise?: boolean, duration?: number): rotate the side opposite the front
    • U (clockwise?: boolean, duration?: number): rotate the side above or on top of the front side
    • D (clockwise?: boolean, duration?: number): rotate the side opposite the top, underneath the Cube
    • L (clockwise?: boolean, duration?: number): rotate the side directly to the left of the front
    • R (clockwise?: boolean, duration?: number): rotate the side directly to the right of the front
    • f (clockwise?: boolean, duration?: number): rotate the side facing the solver and the corresponding middle layer
    • b (clockwise?: boolean, duration?: number): rotate the side opposite the front and the corresponding middle layer
    • u (clockwise?: boolean, duration?: number): rotate the top side and the corresponding middle layer
    • d (clockwise?: boolean, duration?: number): rotate the bottom layer and the corresponding middle layer
    • l (clockwise?: boolean, duration?: number): rotate the side to the left of the front and the corresponding middle layer
    • r (clockwise?: boolean, duration?: number): rotate the side to the right of the front and the corresponding middle layer
    • x (clockwise?: boolean, duration?: number): rotate the entire Cube on R
    • y (clockwise?: boolean, duration?: number): rotate the entire Cube on U
    • z (clockwise?: boolean, duration?: number): rotate the entire Cube on F

Named:

  • materials
    • classic: THREE.MeshBasicMaterial[]: the classic Rubik's Cube material (shown in above gif)

Usage

Rubik's Cube is not coupled with any specific framework. However, I have included some examples of how it can be used with a few of the popular frontend frameworks:

React

import React, { useRef, useEffect, useState } from 'react';
import RubiksCube, { materials } from '@curtishughes/rubiks-cube';

function App() {
  const canvasRef = useRef<HTMLCanvasElement>(null);
  const [cube, setCube] = useState<RubiksCube>();

  useEffect(() => {
    if (canvasRef.current) {
      setCube(new RubiksCube(canvasRef.current, materials.classic, 100));
    }
  }, []);

  return (
    <>
      <canvas width="200px" height="200px" ref={canvasRef} />
      <button onClick={() => { if (cube) cube.F() }}>F</button>
      <button onClick={() => { if (cube) cube.F(false) }}>F'</button>
      {/** ... **/}
    </>
  );
}

export default App;

Vue

<template>
  <div>
    <canvas ref="cube" />
    <button @click="() => cube.F()">F</button>
    <button @click="() => cube.F(false)">F'</button>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import RubiksCube, { materials } from '@curtishughes/rubiks-cube';

@Component
export default class Editor extends Vue {
  private cube!: RubiksCube;

  mounted() {
    const canvas = this.$refs.cube as HTMLCanvasElement;
    this.cube = new RubiksCube(canvas, materials.classic, 100);
  }
}
</script>

Customize material/textures

import * as THREE from 'three';
/* IMPORTANT: Load RubiksCube from the 'core' sub-module to avoid loading unnecessary material assets */
import RubiksCube from '@curtishughes/rubiks-cube/core';

new RubiksCube(canvas,  [
  new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader().load('path/to/texture1') }),
  new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader().load('path/to/texture2') }),
  new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader().load('path/to/texture3') }),
  new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader().load('path/to/texture4') }),
  new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader().load('path/to/texture5') }),
  new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader().load('path/to/texture6') }),
], 100);

License

MIT License

Copyright (c) [2021] [Curtis Hughes]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.