GithubHelp home page GithubHelp logo

p5.js-export's Introduction

p5.js-export

Export high resolution snapshots from p5.js sketches

Update 2022-06-25:

  • When a .png is exported, the resolution (eg. 300 DPI) is also encoded in the PNG image.

Note: it's very much a work in progress. Currently it only works with A* ISO sizes in portrait orientation.

How to use

Import the library in your html <head> tag :

<script src="https://unpkg.com/p5.js-export/p5.js-export.js"></script>

Then insert saveForPrint() in your code :

saveForPrint("sketch.jpg", "A3", 300);

Save the file on key press :

function keyPressed() {
  if (keyCode === 83) { // if "s" is pressed
    saveForPrint("sketch.jpg", "A3", 300);
  }
}

Save multiple frames

4th parameter is used to save multiple frames. Useful if you have an alpha on the background ("blending" multiple draw() calls)

saveForPrint("sketch.jpg", "A3", 300, 10); // save 10 frames

Known limitations

  • The frames saved are not the previous ones, but the future ones. In that sense, it's not possible to export sketches based on user actions. One possible solution would be to have a notion of recording (start a recording, then move mouse, then save).
  • Background has to be set in draw() function or it will be ignored. One possible solution would be to pass your background as an option in the saveForPrint() function.

Why ?

I was looking for a simple way to print sketches at high resoution but couldn't find one. The goal was to have a unique method as to mimic p5.js save() method.

How it works

When calling saveForPrint(), the canvas is scaled to the desired resolution ("A4", "A3", "A2", "A1", "A0"), draw() is called (once or multiple times) then the p5 save() method is called and we reduce the canvas to its original size.

p5.js-export's People

Contributors

drskullster avatar vincentsijben avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

vincentsijben

p5.js-export's Issues

Using in instance mode

Are you able to provide an example of how this plugin could be used with p5 when in instance mode?

It looks really fantastic, and thank you for your work!

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.