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

p5-brush-react

v1.0.2

Published

A React component that encapsulates p5.brush.js, allows you to use p5.js and p5.brush in React app

Downloads

17

Readme

p5-brush-react

p5.brush 进行封装的 react 组件。 如果你只是想使用基础的 p5.js 的能力, 可以使用 P5-wrapper

安装

使用 p5-brush-react 要求同时安装 p5.js

yarn install p5-brush-react p5

示例

仓库中的实例代码 examples

也可以克隆仓库到本地,运行示例

git clone https://github.com/chenjian-bzh/p5-brush-react.git
cd p5-brush-react
yarn install
yarn preview

使用

import React from "react";
import { createRoot } from "react-dom/client";
import P5BrushInstance from "p5-brush-react";

const App = () => {
  return (
    <div>
      <P5BrushInstance
        sketch={(ins) => {
          const palette = [
            "#2c695a",
            "#4ad6af",
            "#7facc6",
            "#4e93cc",
            "#f6684f",
            "#ffd300",
          ];

          ins.setup = () => {
            ins.background("black");
            ins.createCanvas(1500, 1500, "webgl");
            ins.angleMode("degrees");
            ins.brush.scaleBrushes(1.5);
            ins.brush.field("seabed");
          };

          ins.draw = () => {
            const { width, height } = ins;
            const random = ins.random.bind(ins);

            ins.frameRate(30);
            ins.translate(-width / 2, -height / 2);

            // brush.box() returns an array with available brushes
            const available_brushes = ins.brush.box();

            ins.brush.set(random(available_brushes), random(palette), 1);

            // Draw a random flowLine (x, y, length, direction)
            ins.brush.flowLine(
              random(width),
              random(height),
              random(300, 800),
              random(0, 360)
            );

            // Set the stroke to a random brush, color, and weight = 1
            ins.brush.set(random(available_brushes), random(palette), 1);

            // Draw a random flowLine (x, y, length, direction)
            ins.brush.flowLine(
              random(width),
              random(height),
              random(300, 800),
              random(0, 360)
            );
          };
        }}
      />
    </div>
  );
};

createRoot(document.getElementById("root")).render(<App />);