Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

combine p5 with react

export default function sketch(p){
    let canvas;

    p.setup = () => {
      canvas = p.createCanvas(300, 200);
      p.noStroke();
    }

    p.draw = () => {
      p.background('orangered');
      p.ellipse(150, 100, 100, 100);
    }

    p.myCustomRedrawAccordingToNewPropsHandler = (newProps) => {
      if(canvas) //Make sure the canvas has been created
        p.fill(newProps.color);
    }
}
Comment

combine p5 with react

import React, { Component } from 'react';
import P5Wrapper from 'react-p5-wrapper';
import sketch from './sketches/sketch';
import './App.css';

class App extends Component {
  constructor(){
    super();
    this.state = {color:[Math.random()*255, Math.random()*255, Math.random()*255]};
    this.randomColor = this.randomColor.bind(this);
  }

  randomColor(){
    this.setState({color:[Math.random()*255, Math.random()*255, Math.random()*255]}
    )
  }

  render() {
    return (
      <div>
        <button onClick={this.randomColor}>Random Color</button>
        <P5Wrapper sketch={sketch} color={this.state.color}></P5Wrapper>
      </div>
    );
  }
}

export default App;
Comment

PREVIOUS NEXT
Code Example
Javascript :: callback in js 
Javascript :: The toUpperCase JavaScript string method 
Javascript :: next auth 
Javascript :: tilt js vue 
Javascript :: array empty strings 
Javascript :: react native shadow maker 
Javascript :: angular pipe paramerte 
Javascript :: google apps script getsheetbyname 
Javascript :: how to get value of tinymce in javascript 
Javascript :: chaining async await 
Javascript :: react final form 
Javascript :: import ipcrenderer in react 
Javascript :: meteor create package 
Javascript :: sum up all the first and last digit of a number until only two digits are left 
Javascript :: discord js check if message author is admin 
Javascript :: javascript substr 
Javascript :: axios put request 
Javascript :: javascript this Inside Function with Strict Mode 
Javascript :: unexpected token w in json at position 0 
Javascript :: filepond remove file after upload 
Javascript :: usestate hook with callback 
Javascript :: vscode format - .prettierrc jsx singleQuote not work 
Javascript :: Grunt--example gruntfile.js 
Javascript :: atoi javascript 
Javascript :: jquery fedein background color 
Javascript :: sum array elements in javascript 
Javascript :: javascript add maxlength attribute 
Javascript :: how to add key value pair in object 
Javascript :: js replace whole word and not words within words 
Javascript :: Jest DOM Manipulation 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =