-
Notifications
You must be signed in to change notification settings - Fork 0
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
19 changed files
with
618 additions
and
156 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
"version": "0.0.1", | ||
"private": true, | ||
"packageManager": "[email protected]", | ||
"description": "Flow wallpaper creator.", | ||
"description": "A library for creating patterns quickly and easily", | ||
"author": { | ||
"name": "Cole", | ||
"email": "[email protected]" | ||
|
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"type": "module", | ||
"version": "0.0.1", | ||
"packageManager": "[email protected]", | ||
"description": "Flow wallpaper creator.", | ||
"description": "A library for creating patterns quickly and easily", | ||
"author": { | ||
"name": "Cole", | ||
"email": "[email protected]", | ||
|
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"type": "module", | ||
"version": "0.0.1", | ||
"packageManager": "[email protected]", | ||
"description": "Flow wallpaper creator.", | ||
"description": "React port for backmoji", | ||
"author": { | ||
"name": "Cole", | ||
"email": "[email protected]", | ||
|
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"type": "module", | ||
"version": "0.0.1", | ||
"packageManager": "[email protected]", | ||
"description": "Flow wallpaper creator.", | ||
"description": "Vue port for backmoji", | ||
"author": { | ||
"name": "Cole", | ||
"email": "[email protected]", | ||
|
Binary file not shown.
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,81 @@ | ||
<div id="demo-animation-pattern" class="relative h-full w-full overflow-hidden rounded-md bg-orange-50"></div> | ||
|
||
<script> | ||
import { backmoji, createImageRenderer } from "backmoji"; | ||
import { animate } from "@/utils/animation"; | ||
import Paw from "/paw.svg?url"; | ||
|
||
const { play, setCallback, getTimestamp, stat } = animate({ | ||
speed: 0.3, | ||
}); | ||
|
||
const canvas = document.createElement("canvas"); | ||
const parent = document.querySelector<HTMLDivElement>("#demo-animation-pattern")!; | ||
|
||
function loadImage(url: string) { | ||
const image = new Image(); | ||
image.src = url; | ||
return new Promise<HTMLImageElement>((resolve) => { | ||
image.onload = () => resolve(image); | ||
}); | ||
} | ||
|
||
async function createRenderer() { | ||
return createImageRenderer(await loadImage(Paw), { | ||
customRender({ ctx, item, renderItemWidth, renderItemHeight, rowGap, columnGap, columnCount, rowCount }) { | ||
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) { | ||
let from: number, to: number; | ||
if (rowIndex % 2 === 0) { | ||
from = -2; | ||
to = columnCount; | ||
} else { | ||
from = 0; | ||
to = columnCount + 2; | ||
} | ||
for (let columnIndex = from; columnIndex < to; columnIndex++) { | ||
let offset = getTimestamp(); | ||
offset = offset % (2 * (renderItemWidth + columnGap)); | ||
const x = columnIndex * (renderItemWidth + columnGap) + (rowIndex % 2 === 0 ? 1 : -1) * offset; | ||
const y = rowIndex * (renderItemHeight + rowGap); | ||
if ((columnIndex - rowIndex) % 2 === 0) { | ||
ctx.drawImage(item, x, y, renderItemWidth, renderItemHeight); | ||
} | ||
} | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
const height = 300; | ||
const { render, setSize } = backmoji(canvas, createRenderer(), { | ||
degree: 30, | ||
}); | ||
|
||
function animationCb() { | ||
const ctx = canvas.getContext("2d")!; | ||
const w = canvas.width; | ||
const h = canvas.height; | ||
ctx.clearRect(0, 0, w, h); | ||
render(); | ||
} | ||
|
||
setCallback(animationCb); | ||
|
||
const observer = new ResizeObserver((entries) => { | ||
for (const entry of entries) { | ||
setSize(entry.contentRect.width, height); | ||
render(); | ||
} | ||
}); | ||
observer.observe(parent); | ||
|
||
parent.appendChild(canvas); | ||
const statDom = stat.dom; | ||
statDom.style.position = "absolute"; | ||
statDom.style.top = "0"; | ||
statDom.style.right = "0"; | ||
statDom.style.left = "unset"; | ||
parent.appendChild(statDom); | ||
|
||
play(); | ||
</script> |
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,55 @@ | ||
<div id="demo-custom-pattern" class="h-full w-full overflow-hidden rounded-md bg-orange-50"></div> | ||
|
||
<script> | ||
import { backmoji, createImageRenderer } from "backmoji"; | ||
import JSLogo from "/javascript.png?url"; | ||
|
||
const canvas = document.createElement("canvas"); | ||
const parent = document.querySelector<HTMLDivElement>("#demo-custom-pattern")!; | ||
|
||
function loadImage(url: string) { | ||
const image = new Image(); | ||
image.src = url; | ||
return new Promise<HTMLImageElement>((resolve) => { | ||
image.onload = () => resolve(image); | ||
}); | ||
} | ||
|
||
async function createRenderer() { | ||
return createImageRenderer(await loadImage(JSLogo), { | ||
customRender({ ctx, item, renderItemWidth, renderItemHeight, rowGap, columnGap, columnCount, rowCount }) { | ||
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) { | ||
let from: number, to: number; | ||
if (rowIndex % 2 === 0) { | ||
from = -2; | ||
to = columnCount; | ||
} else { | ||
from = 0; | ||
to = columnCount + 2; | ||
} | ||
for (let columnIndex = from; columnIndex < to; columnIndex++) { | ||
const x = columnIndex * (renderItemWidth + columnGap); | ||
const y = rowIndex * (renderItemHeight + rowGap); | ||
if ((columnIndex - rowIndex) % 2 === 0) { | ||
ctx.drawImage(item, x, y, renderItemWidth, renderItemHeight); | ||
} | ||
} | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
const height = 300; | ||
const { render, setSize } = backmoji(canvas, createRenderer()); | ||
|
||
const observer = new ResizeObserver((entries) => { | ||
for (const entry of entries) { | ||
setSize(entry.contentRect.width, height); | ||
render(); | ||
} | ||
}); | ||
observer.observe(parent); | ||
|
||
parent.appendChild(canvas); | ||
render(); | ||
</script> |
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,31 @@ | ||
<div id="demo-emoji-pattern" class="h-full w-full overflow-hidden rounded-md bg-orange-50"></div> | ||
|
||
<script> | ||
import { backmoji, createTextRenderer } from "backmoji"; | ||
|
||
const parent = document.querySelector<HTMLDivElement>("#demo-emoji-pattern")!; | ||
const canvas = document.createElement("canvas"); | ||
|
||
const renderer = createTextRenderer("👌", { | ||
font: "30px Aria", | ||
}); | ||
const height = 160; | ||
const { render, setSize } = backmoji(canvas, renderer, { | ||
degree: -45, | ||
rowGap: 50, | ||
columnGap: 40, | ||
}); | ||
|
||
setSize(parent.clientWidth, height); | ||
|
||
const observer = new ResizeObserver((entries) => { | ||
for (const entry of entries) { | ||
setSize(entry.contentRect.width, height); | ||
render(); | ||
} | ||
}); | ||
observer.observe(parent); | ||
|
||
parent.appendChild(canvas); | ||
render(); | ||
</script> |
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,31 @@ | ||
<div id="demo-text-pattern" class="h-full w-full overflow-hidden rounded-md bg-orange-50"></div> | ||
|
||
<script> | ||
import { backmoji, createTextRenderer } from "backmoji"; | ||
|
||
const parent = document.querySelector<HTMLDivElement>("#demo-text-pattern")!; | ||
const canvas = document.createElement("canvas"); | ||
|
||
const renderer = createTextRenderer("Hello World!", { | ||
font: "30px Aria", | ||
}); | ||
const height = 160; | ||
const { render, setSize } = backmoji(canvas, renderer, { | ||
degree: -45, | ||
rowGap: 50, | ||
columnGap: 40, | ||
}); | ||
|
||
setSize(parent.clientWidth, height); | ||
|
||
const observer = new ResizeObserver((entries) => { | ||
for (const entry of entries) { | ||
setSize(entry.contentRect.width, height); | ||
render(); | ||
} | ||
}); | ||
observer.observe(parent); | ||
|
||
parent.appendChild(canvas); | ||
render(); | ||
</script> |
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,29 @@ | ||
<div id="demo-usage"></div> | ||
|
||
<script> | ||
import { backmoji, createImageRenderer } from "backmoji"; | ||
import JSLogo from "/javascript.png?url"; | ||
|
||
const div = document.querySelector<HTMLDivElement>("#demo-usage")!; | ||
const canvas = document.createElement("canvas"); | ||
div.appendChild(canvas); | ||
|
||
async function loadImage(url: string) { | ||
const image = new Image(); | ||
image.src = url; | ||
return new Promise<HTMLImageElement>(resolve => { | ||
image.onload = () => resolve(image); | ||
}) | ||
} | ||
|
||
async function createRenderer() { | ||
return createImageRenderer(await loadImage(JSLogo)); | ||
} | ||
|
||
const { render } = backmoji(canvas, createRenderer(), { | ||
rowGap: 15, | ||
columnGap: 20, | ||
degree: 30, | ||
}); | ||
render(); | ||
</script> |
Oops, something went wrong.