diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d4e35769..e265663e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### v3000.1.12 +- fix `color()` and `rgb()` not working + ### v3000.1.11 - added option `kaboom({ focus: false })` to disable focus on start - fixed `rand()` typing for numbers diff --git a/examples/confetti.js b/examples/confetti.js new file mode 100644 index 000000000..41ba642ab --- /dev/null +++ b/examples/confetti.js @@ -0,0 +1,55 @@ +const DEF_COUNT = 80 +const DEF_GRAVITY = 800 +const DEF_AIR_DRAG = 0.9 +const DEF_VELOCITY = [1000, 4000] +const DEF_ANGULAR_VELOCITY = [-200, 200] +const DEF_FADE = 0.3 +const DEF_SPREAD = 60 +const DEF_SPIN = [2, 8] +const DEF_SATURATION = 0.7 +const DEF_LIGHTNESS = 0.6 + +kaboom() + +function addConfetti(opt = {}) { + const sample = (s) => typeof s === "function" ? s() : s + for (let i = 0; i < (opt.count ?? DEF_COUNT); i++) { + const p = add([ + pos(sample(opt.pos ?? vec2(0, 0))), + choose([ + rect(rand(5, 20), rand(5, 20)), + circle(rand(3, 10)), + ]), + color(sample(opt.color ?? hsl2rgb(rand(0, 1), DEF_SATURATION, DEF_LIGHTNESS))), + opacity(1), + lifespan(4), + scale(1), + anchor("center"), + rotate(rand(0, 360)), + ]) + const spin = rand(DEF_SPIN[0], DEF_SPIN[1]) + const gravity = opt.gravity ?? DEF_GRAVITY + const airDrag = opt.airDrag ?? DEF_AIR_DRAG + const heading = (opt.heading ?? 0) - 90 + const spread = opt.spread ?? DEF_SPREAD + const head = heading + rand(-spread / 2, spread / 2) + const fade = opt.fade ?? DEF_FADE + const vel = sample(opt.velocity ?? rand(DEF_VELOCITY[0], DEF_VELOCITY[1])) + let velX = Math.cos(deg2rad(head)) * vel + let velY = Math.sin(deg2rad(head)) * vel + const velA = sample(opt.angularVelocity ?? rand(DEF_ANGULAR_VELOCITY[0], DEF_ANGULAR_VELOCITY[1])) + p.onUpdate(() => { + velY += gravity * dt() + p.pos.x += velX * dt() + p.pos.y += velY * dt() + p.angle += velA * dt() + p.opacity -= fade * dt() + velX *= airDrag + velY *= airDrag + p.scale.x = wave(-1, 1, time() * spin) + }) + } +} + +onKeyPress("space", () => addConfetti({ pos: mousePos() })) +onMousePress(() => addConfetti({ pos: mousePos() })) diff --git a/package.json b/package.json index 4348e6954..f9b8ddbff 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "kaboom", "description": "kaboom.js is a JavaScript library that helps you make games fast and fun!", - "version": "3000.1.11", + "version": "3000.1.12", "license": "MIT", "homepage": "https://kaboomjs.com/", "repository": "github:replit/kaboom", diff --git a/src/kaboom.ts b/src/kaboom.ts index 5f4b32ea2..b5bd89a78 100644 --- a/src/kaboom.ts +++ b/src/kaboom.ts @@ -1,4 +1,4 @@ -const VERSION = "3000.1.11" +const VERSION = "3000.1.12" import initApp from "./app" diff --git a/src/math.ts b/src/math.ts index 9bb223bdd..25dbdb37d 100644 --- a/src/math.ts +++ b/src/math.ts @@ -236,7 +236,6 @@ export class Color { return new Color(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)) - } static RED = new Color(255, 0, 0) @@ -322,6 +321,8 @@ export class Color { export function rgb(...args): Color { if (args.length === 0) { + return new Color(255, 255, 255) + } else if (args.length === 1) { if (args[0] instanceof Color) { return args[0].clone() } else if (typeof args[0] === "string") {