ucodia / u5.js Goto Github PK
View Code? Open in Web Editor NEWu5.js is a minimalist and lightweight canvas animation library
License: MIT License
u5.js is a minimalist and lightweight canvas animation library
License: MIT License
When calling background()
after fill()
the fill style is overridden with the background style.
Example to reproduce
<!DOCTYPE html>
<html>
<body>
<div id="container"></div>
<script type="module">
import u5 from "https://www.unpkg.com/[email protected]/index.js";
const example = (sketch) => {
sketch.setup = function () {
sketch.createCanvas(sketch.windowWidth, sketch.windowHeight);
sketch.fill("blue");
};
sketch.draw = function () {
sketch.background("red");
// sketch.fill("blue");
sketch.rect(100, 100, sketch.width - 200, sketch.height - 200);
};
};
new u5(example, document.getElementById("container"));
</script>
</body>
</html>
Sketches which have a low framerate defined and resize the canvas when the window id resized, show some flickering behaviour.
Here is an example:
<!DOCTYPE html>
<html>
<body>
<div id="container"></div>
<script type="module">
import u5 from "https://www.unpkg.com/[email protected]/index.js";
const example = (sketch) => {
sketch.setup = function () {
sketch.createCanvas(sketch.windowWidth, sketch.windowHeight);
sketch.frameRate(25);
};
sketch.draw = function () {
sketch.background("white");
sketch.fill("black");
sketch.noStroke();
const d = Math.min(sketch.width, sketch.height) / 2;
sketch.ellipse(sketch.width / 2, sketch.height / 2, d, d);
};
sketch.windowResized = () => {
sketch.resizeCanvas(sketch.windowWidth, sketch.windowHeight);
};
};
new u5(example, document.getElementById("container"));
</script>
</body>
</html>
Actual result: Canvas flickers when resized
Expected result: Canvas should not flicker when resized
Currently the ellipse
function is using parameters as radiuses of X/Y instead of width/height as in p5.js.
this.ellipse = function (x, y, rx, ry)
This should be
this.ellipse = function (x, y, w, h)
As a result, ellipses are drawn twice larger with u5.js.
When calling fill() and stroke() in the setup(), the fill and stroke styles are overridden after a canvas resize.
Example to reproduce
<!DOCTYPE html>
<html>
<body>
<div id="container"></div>
<script type="module">
import u5 from "https://www.unpkg.com/[email protected]/index.js";
const example = (sketch) => {
sketch.setup = function () {
sketch.createCanvas(sketch.windowWidth, sketch.windowHeight);
sketch.stroke("red");
sketch.fill("blue");
};
sketch.windowResized = function () {
sketch.resizeCanvas(sketch.windowWidth, sketch.windowHeight);
};
sketch.draw = function () {
sketch.rect(100, 100, sketch.width - 200, sketch.height - 200);
};
};
new u5(example, document.getElementById("container"));
</script>
</body>
</html>
Actual result: After resize, the rectangle is filled black with a black stroke
Expected result: After resize, the rectangle should be filled filled blue with a red stroke
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.