Skip to content

Commit 90d18f3

Browse files
committed
call canvasFillStyle each frame, move away from gradient concept
1 parent e1df03b commit 90d18f3

File tree

6 files changed

+11
-20
lines changed

6 files changed

+11
-20
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ by including `{canvas: yourCanvas}` in the configuration.
3939
```javascript
4040
bubbly({
4141
canvas: document.querySelector("#background"), // default is created and attached automatically
42-
gradientStart: "#4c004c", // default is blue-ish
43-
gradientStop: "#1a001a",// default is blue-ish
4442
compose: "lighter", // default is "lighter"
4543
animate: false, // default is true
4644
bubbles: Math.random() * 100, // default is Math.floor((canvas.width + canvas.height) * 0.02);

dist/bubbly-bg.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/bubbly-bg.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/generator.css

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ body {
2626
white-space: pre;
2727
overflow-wrap: normal;
2828
overflow-x: scroll;
29-
min-height: 132px;
29+
min-height: 138px;
3030
padding-bottom: 8px;
3131
}
3232

@@ -57,7 +57,8 @@ input::placeholder {
5757

5858
hr {
5959
height: 1px;
60-
background: rgba(255, 255, 255, 0.5);
60+
background: rgba(255, 255, 255, 0.3);
61+
margin: 12px 0;
6162
}
6263

6364
.side-by-side {

docs/generator.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<b-input v-model="shadowBlur" placeholder="Integer or expression returning integer"></b-input>
3434
</b-field>
3535
</div>
36-
<b-field label="Gradient function" label-position="inside">
37-
<b-input v-model="gradientFunc" type="textarea" placeholder="Function for drawing gradient"></b-input>
36+
<b-field label="Canvas fill function" label-position="inside">
37+
<b-input v-model="canvasFillFunc" type="textarea" placeholder="Function for canvas fill"></b-input>
3838
</b-field>
3939
<b-field label="Radius function" label-position="inside">
4040
<b-input v-model="radiusFunc" placeholder="Function for calculating radius"></b-input>
@@ -70,7 +70,7 @@
7070
fillFunc: "`hsla(0, 0%, 100%, ${Math.random() * 0.1})`",
7171
angleFunc: "Math.random() * Math.PI * 2",
7272
velocityFunc: "0.1 + Math.random() * 0.5",
73-
gradientFunc: `
73+
canvasFillFunc: `
7474
(ctx) => {
7575
const gradient = ctx.createLinearGradient(0, 0, ctx.canvas.width, ctx.canvas.height);
7676
gradient.addColorStop(0, "#2AE");
@@ -118,7 +118,7 @@
118118
compose: this.selectedCompositeType,
119119
shadowBlur: eval(this.shadowBlur),
120120
shadowColor: this.shadowColor,
121-
gradientFunc: eval(this.gradientFunc),
121+
canvasFillFunc: eval(this.canvasFillFunc),
122122
radiusFunc: eval("() => " + this.radiusFunc),
123123
fillFunc: eval("() => " + this.fillFunc),
124124
angleFunc: eval("() => " + this.angleFunc),

src/bubbly-bg.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ window.bubbly = function (c = {}) {
2929
}
3030
}
3131
c.ctx.globalCompositeOperation = c.compose;
32-
c.ctx.fillStyle = c.gradient;
3332
requestAnimationFrame(draw);
3433

3534
function draw() {
35+
c.ctx.fillStyle = c.canvasFillFunc(c.ctx);
3636
if (c.cv.parentNode === null) {
3737
bubbles = [];
3838
return cancelAnimationFrame(draw);
@@ -88,18 +88,10 @@ function generateConfig(c) {
8888
fillFunc: () => `hsla(0, 0%, 100%, ${Math.random() * 0.1})`,
8989
angleFunc: () => Math.random() * Math.PI * 2,
9090
velocityFunc: () => 0.1 + Math.random() * 0.5,
91-
gradientFunc: gradientFunc,
91+
canvasFillFunc: () => "#2AE",
9292
animate: c.animate !== false,
9393
ctx: cv.getContext("2d"),
9494
}, c);
95-
mergedConfig.gradient = mergedConfig.gradientFunc(mergedConfig.ctx);
9695
mergedConfig.padding = mergedConfig.shadowBlur * 2 + 2;
9796
return mergedConfig;
9897
}
99-
100-
const gradientFunc = (ctx) => {
101-
const gradient = ctx.createLinearGradient(0, 0, ctx.canvas.width, ctx.canvas.height);
102-
gradient.addColorStop(0, "#2AE");
103-
gradient.addColorStop(1, "#17B");
104-
return gradient;
105-
}

0 commit comments

Comments
 (0)