Git Product home page Git Product logo

react-game-life's Introduction

Simple react hook to create amazing game of life automats.

Install ๐Ÿฑโ€๐Ÿ’ป

npm i react-game-life

Basic usage ๐Ÿ’ก

import React from 'react'
import {useGameLife} from 'react-game-life'

export default function App() {
    
    const [game, canvasRef] = useGameLife();
    
    return (
        <canvas ref={canvasRef}>
        </canvas>
    )
}
Result:

Game life dark demo

How to use
  • Drag to explore the board
  • Double click to spawn/kill cells
  • Mouse wheel to zoom in/out
  • Enter to start/pause evolution
  • +/- keys to speed up/down
You can also pass default config
import React from 'react'
import {useGameLife} from 'react-game-life'

export default function App() {
    
    const [game, canvasRef] = useGameLife({
      game: {delay: 100},
      graphics: {
        colors: {background: "#FFF", cell: "0E0E0E"},
        board: {height: 800, width: 1200}
      }
    });

    return (
        <canvas ref={canvasRef}>
        </canvas>
    )
}
Result:

Game life white demo

To manually interact/customize the game just add ๐Ÿค–:

useEffect(() => {
    game.bornCell({x: 10, t: 10}) // Spawn cell
    game.killCell({x: 10, y: 10}) // Kill cell
    game.startEvolution()         // Start 
    game.stopEvolution()          // Stop
    game.speedUp(1.5)             // Speed up 1.5x
    game.speedDown(0.8)           // Speed down 0.8x
    game.graphics.setConfig({     // Change graphics config
        colors: {background: '#F0F0F0', cell: '#000000'}
    })
    // and more
}, [])

You can use the game object where you want to call it's methods (The useEffect is optional, you can use the game inside a simple function)

Game API ๐Ÿš€

Game life repository

react-game-life's People

Contributors

jafb321 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.