Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

u5.js is a minimalist and lightweight canvas animation library

License

NotificationsYou must be signed in to change notification settings

Ucodia/u5.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm versionbundle size

u5.js

u5.js is a minimalist and lightweight canvas animation library. Its API is essentially a stripped down version of the popularp5.js library which focuses on 2D canvas animation.

Why does this library exists?

I have been using and loving p5.js since 2014, it is all over my websiteucodia.space, including the home page. Though the p5.js library was never built to be tree-shakeable and is now over 800KB, which is very large if all you need is to animate simple primitives.

There is anexisiting issue in the p5.js GitHub repository, though it seems the way the library is built makes it impossible to enable tree-shaking while remaining backward compatible.

As such I have decided to give a try at building a library with the same API which focuses only on 2D canvas animation.

Feature support

Environment

  • frameCount
  • deltaTime
  • frameRate()
  • windowWidth
  • windowHeight
  • windowResized()
  • width
  • height

Color - Setting

  • background()
  • clear()
  • fill()
  • noFill()
  • noStroke()
  • stroke()

Shape - 2D primitives

  • circle()
  • ellipse()
  • line()
  • rect()
  • square()
  • triangle()

Shape - Attributes

  • strokeWeight()

Constants

  • HALF_PI
  • PI
  • QUARTER_PI
  • TAU
  • TWO_PI

Structure

  • setup()
  • draw()
  • remove()
  • noLoop()
  • loop()
  • u5()

Rendering

  • createCanvas()
  • resizeCanvas()

Transform

  • rotate()
  • translate()
  • scale()

Events - Mouse

  • mouseX
  • mouseY
  • pmouseX
  • pmouseY
  • mouseIsPressed
  • mouseMoved()
  • mousePressed()
  • mouseReleased()
  • doubleClicked()

Math

  • map()
  • constrain()

Planned new features

  • Auto-sizing canvas
  • Out of the box support for SVG export (no animation)

Example: setup and draw

Here is an equivalent top5.js setup and draw example.

const example = (sketch) => {  let y = 100;  sketch.setup = function () {    sketch.createCanvas(720, 400);    sketch.stroke("white");    sketch.frameRate(30);  };  sketch.draw = function () {    sketch.background("black");    y = y - 1;    if (y < 0) {    y = sketch.height;    }    sketch.line(0, y, sketch.width, y);  };};new u5(example, document.getElementById("container"));

About

u5.js is a minimalist and lightweight canvas animation library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp