-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
457 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { createCanvas, loadImage } from 'canvas'; | ||
import { join } from 'path'; | ||
import { Utils } from '../lib'; | ||
|
||
export class Crush { | ||
private path = join(__dirname, '..', '..', 'assets', 'images', 'crush.png'); | ||
|
||
private utils = new Utils(); | ||
|
||
/** | ||
* Constructs an instance of the Crush class | ||
* @param {string | Buffer} image Image of the crush | ||
*/ | ||
|
||
constructor(private image: string | Buffer) {} | ||
|
||
/** | ||
* Builds the image | ||
* @returns {Buffer} | ||
*/ | ||
|
||
public build = async (): Promise<Buffer> => { | ||
if (typeof this.image !== 'string' && !Buffer.isBuffer(this.image)) | ||
throw new TypeError( | ||
`Image should be of type string or Buffer. Recieved ${typeof this | ||
.image}` | ||
); | ||
if (typeof this.image === 'string') | ||
this.image = await this.utils.getBuffer(this.image); | ||
const base = await loadImage(this.path); | ||
const data = await loadImage(this.image); | ||
const canvas = createCanvas(base.width, base.height); | ||
const ctx = canvas.getContext('2d'); | ||
ctx.fillStyle = 'white'; | ||
ctx.fillRect(0, 0, base.width, base.height); | ||
ctx.rotate(3.79 * (Math.PI / 180)); | ||
const { x, y, width, height } = this.utils.centerImagePart( | ||
data, | ||
400, | ||
400, | ||
79, | ||
472 | ||
); | ||
ctx.drawImage(data, x, y, width, height); | ||
ctx.rotate(-3.79 * (Math.PI / 180)); | ||
ctx.drawImage(base, 0, 0); | ||
return canvas.toBuffer(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { createCanvas, loadImage, registerFont } from 'canvas'; | ||
import { join } from 'path'; | ||
import { Utils } from '../lib'; | ||
|
||
export class Friendship { | ||
private paths = { | ||
image: join(__dirname, '..', '..', 'assets', 'images', 'friendship.png'), | ||
font: join(__dirname, '..', '..', 'assets', 'fonts', 'Pinky_Cupid.ttf'), | ||
}; | ||
|
||
private utils: Utils = new Utils(); | ||
/** | ||
* Constructs an instance of the Frienship class | ||
* @param {IFriendShip[]} options Array of name and image of the people | ||
* @param {number} percentage The level of their friencship | ||
* @param {string} text The text to be written at the above for their friendship | ||
*/ | ||
|
||
constructor( | ||
private options: IFriendShip[], | ||
private percentage: number, | ||
private text?: string | ||
) {} | ||
|
||
/** | ||
* Builds the image | ||
* @returns {Bufffer} | ||
*/ | ||
|
||
public build = async (): Promise<Buffer> => { | ||
registerFont(this.paths.font, { family: 'Pinky Cupid' }); | ||
if (this.options.length <= 1) | ||
this.options.push({ | ||
name: this.options[0].name, | ||
image: this.options[0].image, | ||
}); | ||
if ( | ||
(typeof this.options[0].image !== 'string' && | ||
!Buffer.isBuffer(this.options[0].image)) || | ||
(typeof this.options[1].image !== 'string' && | ||
!Buffer.isBuffer(this.options[1].image)) | ||
) | ||
throw new TypeError('The image should be of type string or Buffer'); | ||
if (typeof this.options[0].image === 'string') | ||
this.options[0].image = await this.utils.getBuffer(this.options[0].image); | ||
if (typeof this.options[1].image === 'string') | ||
this.options[1].image = await this.utils.getBuffer(this.options[1].image); | ||
const image1 = await loadImage(this.options[0].image); | ||
const image2 = await loadImage(this.options[1].image); | ||
const base = await loadImage(this.paths.image); | ||
const canvas = createCanvas(base.width, base.height); | ||
const percentColors = [ | ||
{ pct: 0.0, color: { r: 0, g: 0, b: 255 } }, | ||
{ pct: 0.5, color: { r: 0, g: 255 / 2, b: 255 / 2 } }, | ||
{ pct: 1.0, color: { r: 0, g: 255, b: 0 } }, | ||
]; | ||
let text!: string; | ||
if (this.percentage === 0 || (this.percentage > 0 && this.percentage < 10)) | ||
text = 'Awful'; | ||
else if (this.percentage >= 10 && this.percentage < 25) text = 'Very Bad'; | ||
else if (this.percentage >= 25 && this.percentage < 50) text = 'Poor'; | ||
else if (this.percentage >= 50 && this.percentage < 75) text = 'Average'; | ||
else if (this.percentage >= 75 && this.percentage < 80) text = 'Good'; | ||
else if (this.percentage >= 80 && this.percentage < 90) text = 'Great'; | ||
else if (this.percentage >= 90 && this.percentage < 95) | ||
text = 'Best Friends'; | ||
else if (this.percentage >= 95) text = 'Soulmates'; | ||
const ctx = canvas.getContext('2d'); | ||
ctx.drawImage(image1, 70, 56, 400, 400); | ||
ctx.drawImage(image2, 730, 56, 400, 400); | ||
ctx.drawImage(base, 0, 0); | ||
ctx.textAlign = 'center'; | ||
ctx.textBaseline = 'top'; | ||
ctx.fillStyle = 'green'; | ||
ctx.font = '40px Pinky Cupid'; | ||
ctx.fillText('~Friendship Meter~', 600, 15); | ||
ctx.fillStyle = 'white'; | ||
ctx.fillText(this.options[0].name, 270, 448); | ||
ctx.fillText(this.options[1].name, 930, 448); | ||
ctx.font = '60px Pinky Cupid'; | ||
ctx.fillStyle = this.utils.percentColor( | ||
this.percentage / 100, | ||
percentColors | ||
); | ||
ctx.fillText(`~${this.percentage}%~`, 600, 230); | ||
ctx.fillText(this.text ?? text, 600, 296); | ||
ctx.font = '90px Pinky Cupid'; | ||
ctx.fillText(this.percentage > 49 ? '👍' : '👎', 600, 100); | ||
return canvas.toBuffer(); | ||
}; | ||
} | ||
|
||
export interface IFriendShip { | ||
name: string; | ||
image: string | Buffer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { join } from 'path'; | ||
import GIFEncoder from 'gifencoder'; | ||
import { createCanvas, loadImage } from 'canvas'; | ||
import { Utils } from '../lib'; | ||
import { type } from 'os'; | ||
|
||
export class Triggered { | ||
private path = join( | ||
__dirname, | ||
'..', | ||
'..', | ||
'assets', | ||
'images', | ||
'triggered.png' | ||
); | ||
|
||
private utils = new Utils(); | ||
|
||
/** | ||
* Constructs an instance of the triggered class | ||
* @param {string | Buffer} image Image to be triggered | ||
*/ | ||
|
||
constructor(private image: string | Buffer) {} | ||
|
||
/** | ||
* Builds the triggered gif | ||
* @returns {Buffer} | ||
*/ | ||
|
||
public build = async (): Promise<Buffer> => { | ||
if (typeof this.image !== 'string' && !Buffer.isBuffer(this.image)) | ||
throw new TypeError( | ||
`Image should be of type string or Buffer. Recieved ${typeof this | ||
.image}` | ||
); | ||
if (typeof this.image === 'string') | ||
this.image = await this.utils.getBuffer(this.image); | ||
const data = await loadImage(this.image); | ||
const coord1 = [-25, -33, -42, -14]; | ||
const coord2 = [-25, -13, -34, -10]; | ||
const base = await loadImage(this.path); | ||
const encoder = new GIFEncoder(base.width, base.width); | ||
const canvas = createCanvas(base.width, base.width); | ||
const ctx = canvas.getContext('2d'); | ||
ctx.fillStyle = 'white'; | ||
ctx.fillRect(0, 0, base.width, base.width); | ||
const stream = encoder.createReadStream(); | ||
encoder.start(); | ||
encoder.setRepeat(0); | ||
encoder.setDelay(50); | ||
encoder.setQuality(200); | ||
for (let i = 0; i < 4; i++) { | ||
this.utils.drawImageWithTint( | ||
ctx, | ||
data, | ||
'red', | ||
coord1[i], | ||
coord2[i], | ||
300, | ||
300 | ||
); | ||
ctx.drawImage(base, 0, 218, 256, 38); | ||
encoder.addFrame(ctx); | ||
} | ||
encoder.finish(); | ||
return Buffer.concat( | ||
(await this.utils.streamToArray(stream)) as readonly Uint8Array[] | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export * from './GuessThePokemon'; | ||
export * from './Ship'; | ||
export * from './Simp'; | ||
export * from './Triggered'; | ||
export * from './Crush'; | ||
export * from './Friendship'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { Ship, IShipOptions, Simp, GuessThePokemon as Pokemon } from './Base'; | ||
export * from './Base'; |
Oops, something went wrong.