How to use React with p5.js

前端 未结 2 1239
温柔的废话
温柔的废话 2021-01-02 22:04

I really like p5.js and react.js so i wondered how to combine these two together, and i was unable to do it so I need your help. I cant really provide you with some code sa

2条回答
  •  半阙折子戏
    2021-01-02 22:57

    react-p5

    This Component lets you integrate p5 Sketches into your React App. DEMO, Documentation

    Installation

    npm i react-p5

    Usage

    import React, { Component } from "react";
    import Sketch from "react-p5";
    
    export default class App extends Component {
      x = 50
      y = 50
    
      setup = (p5, parent) => {
        p5.createCanvas(500, 500).parent(parent)
      }
      draw = p5 => {
        p5.background(0)
        p5.ellipse(this.x, this.y, 70, 70)
        this.x++
      }
    
      render() {
        return 
      }
    }
    

提交回复
热议问题