-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
39 lines (26 loc) · 906 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { AsciiEffect } from './AsciiEffect';
import * as painter from './painter';
import './style.css';
const rangeInput: HTMLInputElement = document.querySelector('.range input');
const rangeLabel: HTMLLabelElement = document.querySelector('.range-label');
const fetchImageBitmap = async () => {
const imageData = await fetch(
'https://newsletter.gradle.com/images/gradle-400x400.png'
);
const blob = await imageData.blob();
return await createImageBitmap(blob);
};
let effect;
const runEffect = () => {
const value = Number(rangeInput.value);
rangeLabel.innerHTML = value === 1 ? 'Original Image' : `${value} PX`;
effect.apply(value);
};
const init = async () => {
const bitmap = await fetchImageBitmap();
const imageData = painter.imageData(bitmap);
effect = new AsciiEffect(imageData);
effect.apply();
};
rangeInput.addEventListener('input', runEffect);
init();