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

cube-ascii-react

v0.2.0

Published

A react component that simulates the n-body problem using p5.js

Downloads

1

Readme

cube-ascii-react

Description

This is a package to create a 3D ASCII cube in React.

🚀🚀You can try it online from your browser 🚀🚀

You can find the package in the npm registry:

🚀🚀 The package is available on npm 🚀🚀

Demo video

https://github.com/Im-Rises/cubeAscii/assets/59691442/f5bd5eae-67f1-4b75-88f0-6140808ba2f8

Package installation

To install it type npm install cube-ascii-react in your terminal to install it.

Then you can import it in your project with import ParticleSimulator from 'cube-ascii-react'.

Usage

To use it you can simply add the component in your project like this:

import React, {useEffect, useState} from 'react';
import './App.scss';
import {CubeAscii} from './components/CubeAscii';

const App: React.FC = () => {
    const divRef = React.useRef<HTMLDivElement>(null);
    const preTagRef = React.useRef<HTMLPreElement>(null);
    const [isLoaded, setIsLoaded] = useState(false);
    const [useColor, setUseColor] = useState(true);

    const copyToClipboard = async (text: string) => {
        try {
            await navigator.clipboard.writeText(text);
            console.log('Text copied to clipboard');
        } catch (err: unknown) {
            console.error('Failed to copy text: ', err);
        }
    };

    useEffect(() => {
        if (divRef.current) {
            setIsLoaded(true);
        }
    }, [divRef]);
    return (
        <div className={'App'} ref={divRef}>
            {
                isLoaded
                    ? (<>
                            <CubeAscii parentRef={divRef}/>
                        </>
                    )
                    : (
                        <p>Loading...</p>
                    )
            }
        </div>
    );
};

export default App;

or you can change some settings like this:

import React, {useEffect, useState} from 'react';
import './App.scss';
import {CubeAscii} from './components/CubeAscii';

const App: React.FC = () => {
    const divRef = React.useRef<HTMLDivElement>(null);
    const preTagRef = React.useRef<HTMLPreElement>(null);
    const [isLoaded, setIsLoaded] = useState(false);
    const [useColor, setUseColor] = useState(true);

    const copyToClipboard = async (text: string) => {
        try {
            await navigator.clipboard.writeText(text);
            console.log('Text copied to clipboard');
        } catch (err: unknown) {
            console.error('Failed to copy text: ', err);
        }
    };

    useEffect(() => {
        if (divRef.current) {
            setIsLoaded(true);
        }
    }, [divRef]);
    return (
        <div className={'App'} ref={divRef}>
            {
                isLoaded
                    ? (<>
                            <button onClick={() => {
                                setUseColor(!useColor);
                            }}/>
                            <button className={'Button-Copy-Clipboard'}
                                    onClick={async () => copyToClipboard(preTagRef.current!.innerText)}>Copy to clipboard
                            </button>
                            <CubeAscii parentRef={divRef} useColor={useColor} preTagRef={preTagRef}/>
                        </>
                    )
                    : (
                        <p>Loading...</p>
                    )
            }
        </div>
    );
};

export default App;

The component takes 1 to 9 props:

  • parentRef - a reference to the parent div of the canvas. It is used to get the size of the canvas.
  • screenWidth - the resolution of the cube view in characters.
  • screenHeight - the height of the cube view in characters.
  • cubeWidthHeight - the width and height of the cube in characters.
  • distanceFromCamera - the distance from the camera to the cube.
  • framerate - the framerate of the animation.
  • useColor - a boolean to use colors or not.
  • defaultColor - the default color of the cube when useColor is set to false.
  • preTagRef - a reference to the pre tag that contains the cube. You can use it to copy the cube to the clipboard.

You can find the complete example of the project in the GitHub repository here.

Note
Make sure to follow the example: set the parent div of the canvas before instantiating the cube.

GitHub Actions

Node.js CI ESLint CodeQL Node.js Package

The project is set up to run the following actions:

  • node.js.yml : Runs the tests for the Node.js project.
  • eslint.yml : Runs the ESLint linter on the project.
  • codeql.yml : Runs the CodeQL linter on the project.
  • npm-publish.yml : Publishes the package to npm.

Libraries

React:
https://reactjs.org/docs/getting-started.html

Xo:
https://github.com/xojs/xo
https://github.com/xojs/eslint-config-xo-react
https://github.com/xojs/eslint-config-xo-typescript

ESLint:
https://eslint.org/docs/latest/user-guide/getting-started

GitHub gh-pages:
https://github.com/gitname/react-gh-pages

react-device-detect:
https://www.npmjs.com/package/react-device-detect

Documentation

The Coding Challenge (math and physics):
https://www.youtube.com/watch?v=OAcXnzRNiCY

P5.js:
https://p5js.org/

P5.js React:
https://www.npmjs.com/package/react-p5

Links

Check the source code on github

Check the demo on github

Check the package on npm

Contributors

Quentin MOREL :

GitHub contributors