-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmartPaint.js
More file actions
67 lines (56 loc) · 1.95 KB
/
smartPaint.js
File metadata and controls
67 lines (56 loc) · 1.95 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
let selectedTool = ""
let color = ""
let id = ""
let userText = ""
let selectedImg = null;
function objectsPaintInit() {
toolButton("text", () => { selectedTool = "text" }, "Smart paint")
toolButton("rectangle", () => { selectedTool = "rectangle" }, "Smart paint")
toolButton("image", async () => {
selectedImg = downscaleImage(await selectImage(), 16, 16);
selectedTool = "image"
}, "Smart paint")
toolInput((e) => { id = e.target.value; }, "Smart paint")
toolInput((e) => { userText = e.target.value; }, "Smart paint")
}
function updateAttributes() {
color = document.getElementById('colorPicker').value.slice(1, 7);
}
function pixelClicked(x, y) {
updateAttributes()
if (selectedTool == "line")
rectangle(id, x, y, x, y, color)
if (selectedTool == "text")
text(id, userText, x, y, color)
if (selectedTool == "image")
image(id, selectedImg, x, y)
render();
}
function pixelUnclicked(x, y) {
}
function pixelEnteredClicked(x, y) {
if (selectedTool == "line")
rectangle(id, null, null, x, y, null)
if (selectedTool == "text")
text(id, userText, x, y, color)
if (selectedTool == "image")
image(id, null, x, y)
render();
}
async function render() {
let pixels = []
Object.values(shapesObjects).map(e => {
const p = e.func(e.args)
pixels = [...pixels.filter(oldPixel => !p.some(newPixel => newPixel.x == oldPixel.x && newPixel.y == oldPixel.y)), ...p]
})
Object.values(textObjects).map(e => {
const p = e.func(e.args)
pixels = [...pixels.filter(oldPixel => !p.some(newPixel => newPixel.x == oldPixel.x && newPixel.y == oldPixel.y)), ...p]
})
Object.values(imageObjects).map(e => {
const p = e.func(e.args)
pixels = [...pixels.filter(oldPixel => !p.some(newPixel => newPixel.x == oldPixel.x && newPixel.y == oldPixel.y)), ...p]
})
await updatePixels(pixels, true)
}
objectsPaintInit();