GithubHelp home page GithubHelp logo

w0lramd / p5.scribble.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from generative-light/p5.scribble.js

0.0 0.0 0.0 81 KB

Draw 2D primitives in a sketchy look in p5.js

JavaScript 100.00%

p5.scribble.js's Introduction

p5.scribble.js

Draw 2D primitives in a sketchy look in http://p5js.org/.

Example image

With p5.scribble.js you can draw

  • lines
  • curves
  • rects
  • rects with rounded corners
  • ellipses
  • hachures

in a sketchy look

Credits

This is a port of the handy library for processing to p5.js, so much of the source code is taken from the handy library for processing, written by Jo Wood, giCentre, City University London based on an idea by Nikolaus Gradwohl. https://github.com/gicentre/handy

Examples

In the examples directory you can find examples to see p5.scribble.js in action:

  • chart (bar graph) example Example image 2

use headless with phantomJS

If you are interested in using this lib headless, have a look in the example/phantomjs folder
You will find there a skeleton p5 project for using p5 with phantomJS and the bar graph example in it

  • Just fix the path to p5.min.js and p5.scribble.js in render.js
  • Then call "phantomjs render.js" from your command line
  • A screen.png will appear in your folder with the captured image of the sketch

If you create some nice stuff with p5.scribble,js, which could fit in the example directory, let me know or send a PR.

How to use

Include the file

<script language="javascript" type="text/javascript" src="/path/to/p5.scribble.js"></script>

Create an instance

var scribble = new Scribble();              // global mode
var scribble = new Scribble( p5Instance );  // instance mode

You can use p5js and p5.scribble.js in global or instance mode. Just put in the p5 instance to the constructur for instance mode or let it empty for global mode.

Lines

scribble.scribbleLine( x1, y1, x2, y2 );

Draws a line from (x1/y1) to (x2/y2).

Curves

scribble.scribbleCurve( x1, y1, x2, y2, x3, y3, x4, y4 );

Draws a bezier curve from (x1/y1) to (x2/y2). (x3/y3) and (x4/y4) are the coordinates, the curve is pulled to.

Rects

scribble.scribbleRect( x, y, w, h );

Draws a rect centered at (x/y). w and h defines width and height.

scribble.scribbleRoundedRect( x, y, w, h, radius );

Draws a rect like scribbleRect but with rounded corners.

Ellipses

scribble.scribbleEllipse( x, y, w, h );

Draws an allipse centered at (x/y). w and h defines width and height.

Hachures

scribble.scribbleFilling( xCoords, yCoords, gap, angle );

Draws a hachure in the polygon defined by the coordinates from the arrays xCoords and yCoords. The gap defines the space between two hachure lines. The angle defines the orientation of the lines.

General appearance

To change the look you can edit the following attributes

scribble.bowing = yourValue;          // changes the bowing of lines
scribble.roughness = yourValue;       // changes the roughness of lines
scribble.maxOffset = yourValue;       // coordinates will get an offset, here you define the max offset
scribble.numEllipseSteps = yourValue; // defines how much curves will be used to draw an ellipse

This lib works much on random so if you want that your drawings look the same every render step, you should set a seed.

randomSeed( yourSeed );

Color and Weight

Colors and weights are defined like normal in p5.js.

stroke( 255, 0, 0 );

From now on your (sketchy) drawings are red.

strokeWeight( 10 );

From now on your (sketchy) drawings are 10 px heavy.

p5.scribble.js's People

Contributors

jawu avatar ognjenvucko avatar

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.