Socket
Socket
Sign inDemoInstall

jk-react-p5

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jk-react-p5

This Component lets you integrate p5 Sketches into your React App (fixed types)


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

react-p5

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

GitHub

Installation

  • npm

    npm i --save react-p5
    
  • yarn

    yarn add react-p5
    

Usage

JavaScript
import React from "react";
import Sketch from "react-p5";

export default (props) => {
	let x = 50;
	const y = 50;

	const setup = (p5, canvasParentRef) => {
		// use parent to render the canvas in this ref
		// (without that p5 will render the canvas outside of your component)
		p5.createCanvas(500, 500).parent(canvasParentRef);
	};

	const draw = (p5) => {
		p5.background(0);
		p5.ellipse(x, y, 70, 70);
		// NOTE: Do not use setState in the draw function or in functions that are executed
		// in the draw function...
		// please use normal variables or class properties for these purposes
		x++;
	};

	return <Sketch setup={setup} draw={draw} />;
};
Typescript
import React from "react";
import Sketch from "react-p5";
import p5Types from "p5"; //Import this for typechecking and intellisense

interface ComponentProps {
	//Your component props
}

const YourComponent: React.FC<ComponentProps> = (props: ComponentProps) => {
	let x = 50;
	const y = 50;

	//See annotations in JS for more information
	const setup = (p5: p5Types, canvasParentRef: Element) => {
		p5.createCanvas(500, 500).parent(canvasParentRef);
	};

	const draw = (p5: p5Types) => {
		p5.background(0);
		p5.ellipse(x, y, 70, 70);
		x++;
	};

	return <Sketch setup={setup} draw={draw} />;
};

Props

PropRequiredTypeDescription
className:x:StringClassName for canvas parent ref
style:x:ObjectStyles for canvas parent ref
setup:heavy_check_mark:FunctionThe setup() function is called once when the program starts.
draw:x:FunctionCalled directly after setup(), the draw() function continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called.
windowResized:x:FunctionThe windowResized() function is called once every time the browser window is resized.
preload:x:FunctionCalled directly before setup(), the preload() function is used to handle asynchronous loading of external files in a blocking way.
mouseClicked:x:FunctionThe mouseClicked() function is called once after a mouse button has been pressed and then released.
mouseMoved:x:FunctionThe mouseMoved() function is called every time the mouse moves and a mouse button is not pressed.
doubleClicked:x:FunctionThe doubleClicked() function is executed every time a event listener has detected a dblclick event which is a part of the DOM L3 specification.
mousePressed:x:FunctionThe mousePressed() function is called once after every time a mouse button is pressed.
mouseWheel:x:FunctionThe function mouseWheel() is executed every time a vertical mouse wheel event is detected either triggered by an actual mouse wheel or by a touchpad.
mouseDragged:x:FunctionThe mouseDragged() function is called once every time the mouse moves and a mouse button is pressed. If no mouseDragged() function is defined, the touchMoved() function will be called instead if it is defined.
mouseReleased:x:FunctionThe mouseReleased() function is called every time a mouse button is released.
keyPressed:x:FunctionThe keyPressed() function is called once every time a key is pressed. The keyCode for the key that was pressed is stored in the keyCode variable.
keyReleased:x:FunctionThe keyReleased() function is called once every time a key is released. See key and keyCode for more information.
keyTyped:x:FunctionThe keyTyped() function is called once every time a key is pressed, but action keys such as Backspace, Delete, Ctrl, Shift, and Alt are ignored.
touchStarted:x:FunctionThe touchStarted() function is called once after every time a touch is registered.
touchMoved:x:FunctionThe touchMoved() function is called every time a touch move is registered.
touchEnded:x:FunctionThe touchEnded() function is called every time a touch ends. If no touchEnded() function is defined, the mouseReleased() function will be called instead if it is defined.
deviceMoved:x:FunctionThe deviceMoved() function is called when the device is moved by more than the threshold value along X, Y or Z axis. The default threshold is set to 0.5. The threshold value can be changed using setMoveThreshold()
deviceTurned:x:FunctionThe deviceTurned() function is called when the device rotates by more than 90 degrees continuously.
deviceShaken:x:FunctionThe deviceShaken() function is called when the device total acceleration changes of accelerationX and accelerationY values is more than the threshold value. The default threshold is set to 30.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D
Or you can sponsor via Open Collective

Open Collective

Author

@Gherciu/react-p5 :copyright: GHERCIU, Released under the MIT License.
Authored and maintained by GHERCIU with help from contributors (list).

If you like this repository star:star: and watch:eyes: on GitHub

Keywords

FAQs

Package last updated on 18 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc