-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
467 lines (398 loc) · 12.3 KB
/
Copy pathindex.js
File metadata and controls
467 lines (398 loc) · 12.3 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
let currentPressure = 0.5;
let thicksize;
let img;
let paintModeActive = false;
let popupsmode;
let w = 50;
let stuff;
let h = 50;
let history = [];
let redoStack = [];
let colorbg = 255;
let mode = "brush";
let brushcolor = "black";
let brushSize;
let canvasLayer;
let prevX, prevY;
let resolutionW;
let resolutionH;
let pX, pY;
let hideornahscore = 0;
let userText = "";
const arraymode = ["rect", "triangle", "circle"];
const randomValue = arraymode[Math.floor(Math.random() * arraymode.length)];
function preload() {
img = loadImage("tumblr_a1036db59fe9a6705a2a95f9dc95eb92_80fbbcf5_640.webp");
}
function screen_size() {
let user = prompt("Choose your pixel dimensions(using numbers next to the shape)\n1. default")
if (user === "1") {
resolutionW = '900';
resolutionH = '505';
} else if (user === "secret") {
resolutionW = '100';
resolutionH = '100';
}
}
function setup() {
screen_size();
let canvas = createCanvas(resolutionW, resolutionH);
canvas.elt.addEventListener('pointermove', (event) => {
if (event.pointerType === 'pen' || event.pointerType === 'touch') {
currentPressure = event.pressure;
} else {
currentPressure = 0.5;
}
})
canvas.parent("canvas-wrapper");
canvasLayer = createGraphics(resolutionW, resolutionH);
canvasLayer.background(colorbg);
background(colorbg); // white background
list1();
list2()
slider();
sliderclear();
canvasLayer.tint(255, 3);
canvasLayer.image(img, 0, 0, resolutionW, resolutionH);
canvasLayer.noTint();
history.push(canvasLayer.get());
}
function draw() {
background(colorbg);
image(canvasLayer, 0, 0);
if (mouseIsPressed) {
if (mode === "brush") {
//HOW DID I CODE THIS LAST NIGHT???
/*canvasLayer.stroke(brushcolor)
canvasLayer.strokeWeight(brushSize)
if (prevX !== undefined && prevY !== undefined ) {
canvasLayer.line(prevX, prevY, mouseX, mouseY)
}
prevX = mouseX
prevY = mouseY*/
let dynamicSize = brushSize * currentPressure
canvasLayer.stroke(brushcolor);
canvasLayer.strokeWeight(dynamicSize);
canvasLayer.line(pmouseX, pmouseY, mouseX, mouseY);
}
if (mode === "normal_pen") {
canvasLayer.stroke(brushcolor);
canvasLayer.strokeWeight(brushSize);
canvasLayer.line(pmouseX, pmouseY, mouseX, mouseY);
}
if (mode === "airbrush") {
let airbrushColor = color(brushcolor);
airbrushColor.setAlpha(100);
canvasLayer.stroke(airbrushColor);
canvasLayer.strokeWeight(brushSize);
canvasLayer.line(pmouseX, pmouseY, mouseX, mouseY);
}
if (mode === "pixel") {
//HOW???
canvasLayer.noStroke();
let x = floor(mouseX / brushSize) * brushSize + brushSize / 2; //Math
let y = floor(mouseY / brushSize) * brushSize + brushSize / 2;
canvasLayer.fill(brushcolor);
if (x !== pX || y !== pY) {
canvasLayer.rect(x, y, brushSize, brushSize);
}
pX = x;
pY = y;
}
} else {
prevX = undefined;
prevY = undefined;
pX = undefined;
pY = undefined;
}
//Basically making a circle following the mouse cursor
if (mode === "brush") {
noFill();
stroke(0);
circle(mouseX, mouseY, brushSize);
}
if (mode === "normal_pen") {
noFill();
stroke(0);
circle(mouseX, mouseY, brushSize);
}
//Same stuff but box
if (mode === "pixel") {
let followX = floor(mouseX / brushSize) * brushSize + brushSize / 2;
let followY = floor(mouseY / brushSize) * brushSize + brushSize / 2;
noFill();
stroke(0);
rect(followX, followY, brushSize, brushSize);
}
if (mode === "paint") {
noFill();
stroke(80);
circle(mouseX, mouseY, 80);
}
if (mode === "rect") {
noFill();
stroke(thicksize)
rect(mouseX, mouseY, brushSize, brushSize);
}
if (mode === "circle") {
noFill();
stroke(thicksize);
circle(mouseX, mouseY, brushSize);
}
if (mode === "triangle") {
noFill();
stroke(thicksize);
triangle(mouseX, mouseY, mouseX + 50, mouseY, mouseX + 25, mouseY - 50);
}
if (mode === "text") {
textSize(brushSize);
text(userText, mouseX, mouseY, brushSize);
}
if (paintModeActive && mouseIsPressed) {
canvasLayer.background(colorbg);
paintModeActive = false;
canvasLayer.tint(255, 3);
canvasLayer.image(img, 0, 0, 900, 505);
canvasLayer.noTint();
}
}
function mousePressed() {
if (mode === "rect") {
canvasLayer.noFill();
canvasLayer.stroke("black");
canvasLayer.strokeWeight(thicksize);
canvasLayer.rect(mouseX, mouseY, brushSize, brushSize);
}
if (mode === "circle") {
canvasLayer.noFill();
canvasLayer.stroke("black");
canvasLayer.strokeWeight(thicksize);
canvasLayer.circle(mouseX, mouseY, brushSize);
}
if (mode === "triangle") {
canvasLayer.noFill();
canvasLayer.stroke("black");
canvasLayer.strokeWeight(thicksize);
canvasLayer.triangle(mouseX, mouseY, mouseX + 50, mouseY, mouseX + 25, mouseY - 50);
}
if (mode === "text") {
canvasLayer.noFill();
canvasLayer.stroke("black");
canvasLayer.strokeWeight(thicksize);
canvasLayer.textSize(brushSize)
canvasLayer.text(userText, mouseX, mouseY, 24)
}
}
//If the mouse are released it will save the drawing to an array
//idk how to explain it more better
function mouseReleased() {
history.push(canvasLayer.get());
redoStack = [];
}
//keys! the only easy thing to code
function keyPressed() {
switch (key) {
case "Z":
case "z":
if (keyIsDown(CONTROL)) {
undo();
}
break;
case "Y":
case "y":
if (keyIsDown(CONTROL)) {
redo();
}
break;
//saved the picture
case "X":
case "x":
if (keyIsDown(CONTROL)) {
popupsave();
}
break;
case "A":
case "a":
shapes()
break;
case "1":
if (keyIsDown(CONTROL)) {
hideornah()
}
break;
case "m":
if (keyIsDown(CONTROL)) {
manualsalert()
}
break;
case "2":
if (keyIsDown(CONTROL)) {
showornah()
}
break;
case "9":
brushSize++
document.getElementById("score").textContent = brushSize
document.getElementById("volume").value = brushSize;
break;
//escaped the paint thingy
case "Escape":
document.getElementById("popup-color").style.display = "none";
document.getElementById("popup").style.display = "none";
break;
default:
break;
}
}
//undo button
//if it's more than two then it will undo it
//it will try to found the most recent image and show it
function undo() {
if (history.length > 1) {
redoStack.push(history.pop());
let img = history[history.length - 1];
canvasLayer.clear();
canvasLayer.image(img, 0, 0);
redraw();
}
}
//redo button!
//if it's more than one then it will redo it
//opposite of undo
function redo() {
if (redoStack.length > 0) {
let img = redoStack.pop();
history.push(img);
canvasLayer.clear();
canvasLayer.image(img, 0, 0);
redraw();
}
}
function hideornah() {
document.getElementById("hideornah").style.display = "none";
}
function showornah() {
document.getElementById("hideornah").style.display = "block";
}
function popupsave() {
document.getElementById("popup-save").style.display = "flex";
mode = "none";
}
function clear_screen() {
canvasLayer = createGraphics(resolutionW, resolutionH);
}
//List of stuff (part 1)
function list1() {
//Pixel art
document.getElementById("pixel").addEventListener("click", () => {
mode = "pixel";
});
/*
document.getElementById("favcolor").addEventListener("input", (e) => {
brushcolor = e.target.value;
});*/
document.getElementById("inputsave").addEventListener("click", () => {
let user = document.getElementById("inputbox").value;
if (user) {
saveCanvas(user, "png");
}
document.getElementById("popup-save").style.display = "none";
});
document.getElementById("brushtype").addEventListener("click", () => {
document.getElementById("popup-brush").style.display = "flex";
})
//Opening the paint pop up
document.getElementById("Paint").addEventListener("click", () => {
document.getElementById("popup").style.display = "flex";
mode = "paint";
});
document.getElementById("text").addEventListener("click", () => {
let user = prompt("Enter a text and place it randomly!")
if (user) {
mode = "text";
userText = user;
thicksize = 1;
document.getElementById("scorethick").textContent = thicksize
}
})
document.getElementById("shapes").addEventListener("click", () => {
mode = "none";
let user = prompt("Choose your shape (using numbers next to the shape)\n1. circle | 2. rectangle | 3. triangle | 4. random");
switch (user) {
case "1":
case "3.14": //easter egg???
mode = "circle"
break;
case "2":
mode = "rect"
break;
case "3":
mode = "triangle"
break;
case "4":
const arraymode = ['rect', 'triangle', 'circle'];
const randomValue = arraymode[Math.floor(Math.random() * arraymode.length)];
mode = randomValue;
break;
default:
break;
}
});
document.getElementById("brushtype").addEventListener("click", () => {
mode = "none";
let user = prompt("Choose your type of brush (using numbers next to the shape)\n1. pen | 2. normal | 3. airbrush | 4. pencil");
switch (user) {
case "1":
mode = "normal_pen"
break;
case "2":
mode = "brush"
break;
case "3":
mode = "airbrush"
break;
case "4":
const arraymode = ['rect', 'triangle', 'circle'];
const randomValue = arraymode[Math.floor(Math.random() * arraymode.length)];
mode = randomValue;
break;
default:
break;
}
});
document.getElementById("brushpickcolor").addEventListener("click", () => {
document.getElementById("popup-color").style.display = "flex";
});
//Eraser
document.getElementById("Eraser").addEventListener("click", () => {
brushSize = 20;
brushcolor = "white";
document.getElementById("score").textContent = brushSize;
});
//Switches back to brush
document.getElementById("Normal").addEventListener("click", () => {
brushcolor = "black";
mode = "brush";
brushSize = 20;
document.getElementById("score").textContent = brushSize;
document.getElementById("volume").value = brushSize;
});
}
//List of stuff (part 2)
function slider() {
let user = document.getElementById("volume").value
brushSize = Number(user)
document.getElementById("score").textContent = brushSize
}
function sliderclear() {
let user1 = document.getElementById("volume1").value
thicksize = Number(user1)
document.getElementById("scorethick").textContent = thicksize
}
function list2() {
}
function manualsalert() {
document.getElementById("popup-manual").style.display = "flex";
}
function hide() {
}