GithubHelp home page GithubHelp logo

zachkrall / p5snap Goto Github PK

View Code? Open in Web Editor NEW
22.0 1.0 2.0 2.08 MB

a command-line interface for creating snapshots of a p5 sketch

Home Page: https://zachkrall.github.io/p5snap

License: MIT License

JavaScript 100.00%
p5js cli

p5snap's Introduction



about

Codacy Badge

p5snap is a command-line interface that creates and saves snapshots of a p5 sketch

installation

with npm:

npm -g install p5snap

usage

to start p5snap, provide a relative file path and the number of images that should be saved

p5snap <FILE-PATH> -n <NUMBER-OF-IMAGES>

for example:

p5snap ./mySketch.js -n 20

will create:
• mySketch_0.png
• mySketch_1.png
• mySketch_2.png
• ...
• mySketch_19.png

as a module

you can bring p5snap into your existing node.js build tools by importing the snap module.

snap() only executes once, you can implement your own setInterval() to run snap() multiple times

for example:

const path = require('path')
const snap = require('p5snap/lib/snap.js')

snap({
  sketch_path: path.resolve(__dirname, './mySketch.js'),
  output_path: path.resolve(__dirname, 'output'),
  width: 1920,
  height: 1080,
  instance: false,
  filename: 'mySketch',
  delay: 300 // milliseconds to delay capturing
})

instance mode

if your sketch is written as a p5 instance, you can use the --instance flag to execute p5snap in instance mode

module.exports and require statements are removed from instance mode. sketch should also include a "new p5()" call.

view example code for instance mode sketches.

limitations

single canvas

p5snap currently only saves a single <canvas/> context. If your p5 drawing uses or draws DOM elements, it will not be included in the image.

interactive sketches

p5snap runs in a hidden virtual browser environment. this means that interactive elements like webcam footage, cursor events, or key presses won't be triggered.

external resources

right now, the virtual browser environment does not have access to loading any external resources. a work around is providing them in your javascript as a data uri.

eventually, I'd like to include the JSOM fromFile api to allow passing in an index.html file instead of a js file.

contributing

Contributions, issues and feature requests are welcome.
Feel free to check issues page if you want to contribute.

Check the tag for suggestions on features to work on.

license

Copyright © 2020 Zach Krall.
This project is MIT licensed.

p5snap's People

Contributors

actions-user avatar codacy-badger avatar dependabot[bot] avatar zachkrall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

p5snap's Issues

add --out-dir option

currently, p5snap saves files in the same directory it's executed in

add an --out-dir flag to save to a custom location

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.