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.touchgui-fork

v0.7.1

Published

An easy-to-use touchscreen and mouse UI library for p5.js.

Downloads

2

Readme

Home | Reference | Development Notes

p5.touchgui-fork

Note: This is a fork of L05/p5.touchgui. I don't know if I'll add any extra features.

It also contains improvements from other forks, most notably aryan02420:patch0

Why p5.touchgui?

Image of three different presets for p5.touchgui: Blue, Rose, and Seafoam

p5.js is a wonderfully accessible way for students and creative minds to both learn computer programming and create interactive art and experiences.

p5.touchgui is intended to extend p5.js and make it easy to add buttons, sliders, and other GUI (graphical user interface) objects to your p5.js sketches, enabling you to focus on quickly iterating ideas with easily created GUI objects that work with both mouse and multi-touch input.

If you'd like to read more about the process, please check out my Google Summer of Code report.

Getting Started

Quick Start

[Back to top]

There are two ways to quickly get started with p5.touchgui.

Option 1 - p5.js editor

Open this p5.js web editor sketch with p5.touchgui.js added.

Option 2 - index.html

In an index.html file, copy and paste the following and open up that file in your web browser.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Getting Started with p5.touchgui</title>
    <!-- p5 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.sound.min.js"></script>
    <!-- p5.touchgui -->
    <script src="https://unpkg.com/[email protected]/lib/p5.touchgui.js"></script>
  </head>

  <body>
    <script>
      // Your code will go here
      let gui;
      let b;

      function setup(){
        createCanvas(400, 400);
                       
        gui = createGui();
        b = createButton("Button", 50, 50);
      }

      function draw(){
        background(200);
        drawGui();

        if(b.isPressed) {
          print(b.label + " is pressed.");
        }
      }
    </script>
  </body>
</html>

That's all!

My First Button

[Back to top]

(Follow along here.)

  1. Declare a variable named gui and use createGui() to create a new GUI context. This is where each of your GUI objects is tracked and updated.
let gui;

function setup() {
  createCanvas(400, 400);
  
  gui = createGui();
}
  1. Declare a variable called b and use createButton() to add a new button.
let gui;
let b;

function setup() {
  createCanvas(400, 400);
  
  gui = createGui();
  b = createButton("myButton", 50, 50);
}
  1. Make sure to call drawGui() in your draw() loop. You can call it anywhere, but make sure to do so after you draw your background().

    If you run your sketch now, you should see your button drawn on the screen at an x position of 50 and a y position of 50.

function draw() {
  background(220);
  drawGui();
}
  1. if() your button is .isPressed, you can choose to perform actions. In this example, we will print() a message using the button's .label.
function draw() {
  background(220);
  drawGui();

  if(b.isPressed) {
    print(b.label + " is pressed.");
  }
}
  1. All together your p5.js sketch should look like:
let gui;
let b;

function setup() {
  createCanvas(400, 400);
  
  gui = createGui();
  b = createButton("Button", 50, 50);
}

function draw() {
  background(220);
  drawGui();

  if(b.isPressed) {
    print(b.label + " is pressed.");
  }
}

Congratulations! You've created your first sketch using p5.touchgui. If you want to see what this looks like, click here.

Object Types

[Back to top]

Blue preset

  • Button A button with a label that highlights when touched or clicked. When released it turns off.
  • Toggle A button with a label that highlights when touched or clicked. When touched or clicked again, it turns off.
  • Checkbox A button with an X that turns on when touched or clicked. When touched or clicked again, it turns off.
  • Slider A horizontally oriented slider that can be touched or clicked and dragged side to side to change its value.
  • SliderV A vertically oriented slider that can be touched or clicked and dragged up and down to change its value.
  • Crossfader A horizontally oriented crossfader that can be touched or clicked and dragged side to side to change its value. Visually similar to a slider except the indicator extends from the center.
  • CrossfaderV A vertically oriented crossfader that can be touched or clicked and dragged up and down to change its value. Visually similar to a slider except the indicator extends from the center.
  • Slider2d A two dimensional slider that returns an X/Y pair of values depending on touch or click location.
  • Joystick A two dimensional slider that returns an X/Y pair of values relative to a resetting zero point at its center.

Examples

[Back to top]

Using the OSC Examples

[Back to top]

In order to run the OSC examples you'll need to do the following:

  1. Download and install node.js

  2. Open a terminal or command prompt (on Windows you might need to open the command prompt as admin).

  3. In the terminal, navigate to your p5.touchgui directory using cd.

  4. In the terminal type to install dependencies needed by p5.touchgui to run the OSC examples: npm install

  5. Type the following in the terminal to install node.js http-server: npm install -g http-server

  6. Then start a local server by typing in the terminal: http-server -c-1

  7. Open a new terminal or command prompt (again, on Windows you might need to open the command prompt as admin).

  8. Use cd to navigate to the examples/osc folder within your p5.touchgui directory.

  9. Once there, type in the terminal: node bridge.js

  10. Then point your browser to http://localhost:8080/index.html and use the menu to select the OSC examples.