-
Notifications
You must be signed in to change notification settings - Fork 18
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
7 changed files
with
81 additions
and
2 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
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,33 @@ | ||
import { render, RGBA } from '../renderer' | ||
|
||
const dotSize = 4 | ||
const dotDensity = 1 | ||
const mat = [ | ||
[0.1, 0.9, 0.3, 0.9], | ||
[0.9, 0.3, 0.9, 0.6], | ||
[0.3, 0.9, 0.1, 0.9], | ||
[0.9, 0.6, 0.9, 0.6] | ||
] | ||
const ditherRange = 0 | ||
|
||
export function halftone(source: Buffer, width: number, height: number): Buffer { | ||
return render(source, width, height, (pixelCoords, texture2D) => { | ||
const gridCoords = [Math.floor(pixelCoords[0] / dotSize), Math.floor(pixelCoords[1] / dotSize)] | ||
|
||
const originalColor = texture2D(pixelCoords) | ||
const grayValue = (originalColor[0] + originalColor[1] + originalColor[2]) / (3 * 255) | ||
const ditherValue = (Math.random() - 0.5) * ditherRange | ||
const adjustedGrayValue = Math.min(Math.max(grayValue + ditherValue, 0), 1) | ||
|
||
const relativeCoords = [pixelCoords[0] - gridCoords[0] * dotSize, pixelCoords[1] - gridCoords[1] * dotSize] | ||
|
||
const intensity = mat[relativeCoords[0]][relativeCoords[1]] | ||
|
||
const dotRadius = dotDensity * (1 - adjustedGrayValue) | ||
const isInDot = intensity < dotRadius | ||
|
||
const finalColor: RGBA = isInDot ? [7, 85, 59, 255] : [206, 212, 106, 255] | ||
|
||
return finalColor | ||
}) | ||
} |
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
Binary file added
BIN
+350 KB
...ofile-test-theme-test-ts-theme-render-card-with-green-phosphor-theme-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.27 MB
...st-ts-theme-with-screen-effect-render-card-with-green-phosphor-theme-1-snap.png
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