Skip to content

Commit

Permalink
feat: added clear flag, enabled by default, if disabled, the canvas w…
Browse files Browse the repository at this point in the history
…on't be cleared
  • Loading branch information
matteobruni committed Dec 4, 2023
1 parent 17750ea commit 299784c
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 7 deletions.
2 changes: 1 addition & 1 deletion engine/src/Core/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class Canvas {
} else if (trailFill.image) {
this._paintImage(trailFill.image, trailFill.opacity);
}
} else {
} else if (options.clear) {
this.draw((ctx) => {
clear(ctx, this.size);
});
Expand Down
10 changes: 10 additions & 0 deletions engine/src/Options/Classes/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class Options implements IOptions, IOptionLoader<IOptions> {
autoPlay;
readonly background;
readonly backgroundMask;
clear: boolean;
defaultThemes: DefaultThemes;
delay: RangeValue;
detectRetina;
Expand Down Expand Up @@ -60,6 +61,7 @@ export class Options implements IOptions, IOptionLoader<IOptions> {
this.autoPlay = true;
this.background = new Background();
this.backgroundMask = new BackgroundMask();
this.clear = true;
this.defaultThemes = {};
this.delay = 0;
this.fullScreen = new FullScreen();
Expand Down Expand Up @@ -95,6 +97,14 @@ export class Options implements IOptions, IOptionLoader<IOptions> {
this.autoPlay = data.autoPlay;
}

if (data.clear !== undefined) {
this.clear = data.clear;
}

if (data.name !== undefined) {
this.name = data.name;
}

if (data.delay !== undefined) {
this.delay = setRangeValue(data.delay);
}
Expand Down
5 changes: 5 additions & 0 deletions engine/src/Options/Interfaces/IOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export interface IOptions {
*/
backgroundMask: IBackgroundMask;

/**
* Clears the canvas on every frame if enabled
*/
clear: boolean;

/**
* The initial delay before starting the animation
*/
Expand Down
6 changes: 4 additions & 2 deletions utils/configs/src/n/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import nasa from "./nasa.js";
import noconfig from "./noconfig.js";
import noClear from "./noClear.js";
import noConfig from "./noConfig.js";
import noisePlanes from "./noisePlanes.js";
import nyancat from "./nyancat.js";
import nyancat2 from "./nyancat2.js";

export default {
nasa,
noconfig,
noClear,
noConfig,
noisePlanes,
nyancat,
nyancat2,
Expand Down
101 changes: 101 additions & 0 deletions utils/configs/src/n/noClear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import type { ISourceOptions } from "@tsparticles/engine";

const options: ISourceOptions = {
name: "No Clear",
clear: false,
interactivity: {
events: {
onHover: {
enable: true,
mode: "trail",
},
},
modes: {
trail: {
delay: 0.01,
quantity: 1,
pauseOnStop: true,
},
},
},
particles: {
color: {
value: [
"#80F31F",
"#ED8B08",
"#ED1868",
"#800CE0",
"#1274F7",
"#12E797",
"#7FF31F",
"#ED8B08",
"#ED1868",
"#800CE0",
"#1274F7",
"#12E797",
"#7FF31F",
"#ED8B08",
"#ED1868",
"#800CE0",
"#1274F7",
"#12E797",
"#7FF31F",
"#ED8B08",
"#ED1868",
"#800CE0",
"#1274F7",
"#12E797",
"#7FF31F",
"#ED8B08",
"#ED1868",
"#800CE0",
"#1274F7",
"#12E797",
"#7FF31F",
"#ED8B08",
"#ED1868",
"#800CE0",
"#1274F7",
"#12E797",
"#7FF31F",
"#ED8B08",
"#ED1868",
"#800CE0",
"#1274F7",
"#12E797",
"#7FF31F",
"#ED8B08",
"#ED1868",
"#800CE0",
"#1274F7",
"#12E797",
"#7FF31F",
"#ED8B08",
],
},
life: {
count: 1,
duration: {
sync: true,
value: 1,
},
},
number: {
value: 500,
},
size: {
value: 50,
},
shape: {
type: "star",
},
rotate: {
value: {
min: 0,
max: 360,
},
},
},
};

export default options;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import type { ISourceOptions } from "@tsparticles/engine";

const options: ISourceOptions = {
name: "No Config",
fullScreen: {
enable: true,
zIndex: 0,
},
};

export default options;

0 comments on commit 299784c

Please sign in to comment.