-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmPressed.pde
More file actions
1188 lines (1152 loc) · 41.3 KB
/
mPressed.pde
File metadata and controls
1188 lines (1152 loc) · 41.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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//*********************************
void mousePressed()
//*********************************
{
x2 = mouseX;
y2 = mouseY;
x1 = pmouseX;
y1 = pmouseY;
if (mouseButton == LEFT)
{
// WEB PRESSED
if ((!keyPressed) && (tool=="Web") && (!eraseW) && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
livelli[activeLyr].pg.noFill();
livelli[activeLyr].pg.stroke(brushCol);
livelli[activeLyr].pg.strokeWeight(brushSize);
if (noGlitch) { prepareGlitch(); } // Start antialias...
attractionW = slWEBA.v;
densityW = slWEBD.v/100.0;
typeW = (int) sbWEBT.v;
jitterW = (int) sbWEBJ.v;
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// WEB ERASE PRESSED
else if ((!keyPressed) && (tool=="Web") && (eraseW) && ((!menu) || (x1 > menuX)))
{
for (int p=cobweb.size()-1; p >= 0 ; p--) // erase point from cobweb
{
PVector v = cobweb.get(p);
if ((v.x > x2-brushSize/2) && (v.x < x2+brushSize/2) && (v.y > y2-brushSize/2) && (v.y < y2+brushSize/2))
{
if ((!aSelection) || (aSelection && v.x>x1sel && v.x<x2sel+1 && v.y>y1sel && v.y<y2sel+1)) // check active selection
{
cobweb.remove(p);
}
}
}
}
// CONFETTI PRESSED
else if ((!keyPressed) && (tool=="Confetti") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
livelli[activeLyr].pg.noStroke();
livelli[activeLyr].pg.fill(brushCol);
if (noGlitch) { prepareGlitch(); } // Start antialias...
// reset Confetti arrayList
confettiThings.clear();
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// DYNA PRESSED
else if ((!keyPressed) && (tool=="Dyna") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
livelli[activeLyr].pg.noStroke();
livelli[activeLyr].pg.fill(brushCol);
if (noGlitch) { prepareGlitch(); } // Start antialias...
// reset Dyna parameters
myDD.px = mouseX;
myDD.py = mouseY;
myDD.ppx = mouseX;
myDD.ppy = mouseY;
myDD.vx = 0;
myDD.vy = 0;
myDD.old_brush = myDD.min_brush;
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// LINER PRESSED
else if ((!keyPressed) && (tool=="Liner") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
lineDown = true;
x1L = x2; y1L = y2;
x2L = x1L; y2L = y1L;
}
// QUAD PRESSED
else if ((!keyPressed) && (tool=="Quad") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
quadDown = true;
x1L = x2; y1L = y2;
x2L = x1L; y2L = y1L;
}
// CIRCLED PRESSED
else if ((!keyPressed) && (tool=="Circle") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
circleDown = true;
x1L = x2; y1L = y2;
x2L = x1L; y2L = y1L;
}
// SELECTION PRESSED
else if ((!keyPressed) && (tool=="Select") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
selectDown = true;
aSelection = false;
x1L = x2; y1L = y2;
x2L = x1L; y2L = y1L;
}
// PENCIL PRESSED
else if ((!keyPressed) && (tool=="Pencil") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
if (noGlitch) { prepareGlitch(); } // Start antialias...
livelli[activeLyr].pg.noStroke();
livelli[activeLyr].pg.fill(brushCol);
if (aSelection) { livelli[activeLyr].pg.clip(x1sel+1, y1sel+1, x2sel-x1sel-1, y2sel-y1sel-1); } // check selection
drawLine(x1,y1,x2,y2, brushSize, livelli[activeLyr].pg); // draw on active layer
if (symX) // draw symmetry from X axis
{
calcSymX(x1,y1,x2,y2);
drawLine(s1x, s1y, s2x, s2y, brushSize, livelli[activeLyr].pg);
}
if (symY) // draw symmetry from Y axis
{
calcSymY(x1,y1,x2,y2);
drawLine(s1x, s1y, s2x, s2y, brushSize, livelli[activeLyr].pg);
}
if(symX && symY) // draw symmetry from center point (opposite)
{
calcSymXY(x1,y1,x2,y2);
drawLine(s1x, s1y, s2x, s2y, brushSize, livelli[activeLyr].pg);
}
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// SHAPE PRESSED
else if ((!keyPressed) && (tool=="Shape") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
if (noGlitch) { prepareGlitch(); } // Start antialias...
livelli[activeLyr].pg.stroke(brushCol);
livelli[activeLyr].pg.noFill();
if (aSelection) { livelli[activeLyr].pg.clip(x1sel+1, y1sel+1, x2sel-x1sel-1, y2sel-y1sel-1); } // check selection
color shColor;
int numItems = (int) slSHitems.v;
livelli[activeLyr].pg.rectMode(CENTER);
livelli[activeLyr].pg.shapeMode(CENTER);
for (int i = 0; i < numItems; i++)
{
int posX = x2 + (int) (round(random(-slSHposD.v, +slSHposD.v)));
int posY = y2 + (int) (round(random(-slSHposD.v, +slSHposD.v)));
int bSizeH = brushSize + (int) (round(random(-slSHsizeD.v, +slSHsizeD.v)));
int bSizeV = brushSize + (int) (round(random(-slSHsizeD.v, +slSHsizeD.v)));
int bAlfa = alfa + (int) (round(random(-slSHalfaD.v, +slSHalfaD.v)));
if (cbSHcolorRND.s)
{
shColor = randomColor();
shColor = color((shColor >> 16) & 0xFF, (shColor >> 8) & 0xFF, shColor & 0xFF, bAlfa);
}
else
{
shColor = color((brushCol >> 16) & 0xFF, (brushCol >> 8) & 0xFF, brushCol & 0xFF, bAlfa);
}
livelli[activeLyr].pg.stroke(shColor);
// draw on active layer
switch((int)sbSHtype.v)
{
case 1: // rectangle
livelli[activeLyr].pg.rect(posX, posY, bSizeH, bSizeV);
if (symX)
{
calcSymX(posX, posY, posX, posY);
livelli[activeLyr].pg.rect(s1x, s1y, bSizeH, bSizeV);
}
if (symY) // draw symmetry from Y axis
{
calcSymY(posX, posY, posX, posY);
livelli[activeLyr].pg.rect(s1x, s1y, bSizeH, bSizeV);
}
if(symX && symY) // draw symmetry from center point (opposite)
{
calcSymXY(posX, posY, posX, posY);
livelli[activeLyr].pg.rect(s1x, s1y, bSizeH, bSizeV);
}
break;
case 2: // square
livelli[activeLyr].pg.rect(posX, posY, bSizeH, bSizeH);
if (symX)
{
calcSymX(posX, posY, posX, posY);
livelli[activeLyr].pg.rect(s1x, s1y, bSizeH, bSizeH);
}
if (symY) // draw symmetry from Y axis
{
calcSymY(posX, posY, posX, posY);
livelli[activeLyr].pg.rect(s1x, s1y, bSizeH, bSizeH);
}
if(symX && symY) // draw symmetry from center point (opposite)
{
calcSymXY(posX, posY, posX, posY);
livelli[activeLyr].pg.rect(s1x, s1y, bSizeH, bSizeH);
}
break;
case 3: // ellipse
livelli[activeLyr].pg.ellipse(posX, posY, bSizeH, bSizeV);
if (symX)
{
calcSymX(posX, posY, posX, posY);
livelli[activeLyr].pg.ellipse(s1x, s1y, bSizeH, bSizeV);
}
if (symY) // draw symmetry from Y axis
{
calcSymY(posX, posY, posX, posY);
livelli[activeLyr].pg.ellipse(s1x, s1y, bSizeH, bSizeV);
}
if(symX && symY) // draw symmetry from center point (opposite)
{
calcSymXY(posX, posY, posX, posY);
livelli[activeLyr].pg.ellipse(s1x, s1y, bSizeH, bSizeV);
}
break;
case 4: // circle
livelli[activeLyr].pg.ellipse(posX, posY, bSizeV, bSizeV);
if (symX)
{
calcSymX(posX, posY, posX, posY);
livelli[activeLyr].pg.ellipse(s1x, s1y, bSizeV, bSizeV);
}
if (symY) // draw symmetry from Y axis
{
calcSymY(posX, posY, posX, posY);
livelli[activeLyr].pg.ellipse(s1x, s1y, bSizeV, bSizeV);
}
if(symX && symY) // draw symmetry from center point (opposite)
{
calcSymXY(posX, posY, posX, posY);
livelli[activeLyr].pg.ellipse(s1x, s1y, bSizeV, bSizeV);
}
break;
case 5: // user svg
int dimX = (int) aShape.width*bSizeH/brushSizeMax;
int dimY = (int) aShape.height*bSizeH/brushSizeMax;
livelli[activeLyr].pg.shape(aShape, posX, posY, dimX, dimY);
break;
} //end switch
}
livelli[activeLyr].pg.rectMode(CORNER);
livelli[activeLyr].pg.shapeMode(CORNER);
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// ERASER PRESSED
else if ((!keyPressed) && (tool=="Eraser") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
if (noGlitch) { prepareGlitch(); } // Start antialias...
livelli[activeLyr].pg.noStroke();
livelli[activeLyr].pg.fill(0,0,0,0);
livelli[activeLyr].pg.blendMode(REPLACE);
if (aSelection) { livelli[activeLyr].pg.clip(x1sel+1, y1sel+1, x2sel-x1sel-1, y2sel-y1sel-1); } // check selection
drawLine(x1,y1,x2,y2, brushSize, livelli[activeLyr].pg); // draw/erase on active layer
if (symX) // draw symmetry from X axis
{
calcSymX(x1,y1,x2,y2);
drawLine(s1x,s1y,s2x,s2y, brushSize, livelli[activeLyr].pg);
}
if (symY) // draw symmetry from Y axis
{
calcSymY(x1,y1,x2,y2);
drawLine(s1x,s1y,s2x,s2y, brushSize, livelli[activeLyr].pg);
}
if(symX && symY) // draw symmetry from center point (opposite)
{
calcSymXY(x1,y1,x2,y2);
drawLine(s1x,s1y,s2x,s2y, brushSize, livelli[activeLyr].pg);
}
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// VERNICE PRESSED
else if ((!keyPressed) && (tool=="Vernice" || tool == "Stencil") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
int x0 = mouseX;
int y0 = mouseY;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
// if (noGlitch) { prepareGlitch(); } // No antialias with this tool :-)
livelli[activeLyr].pg.loadPixels();
drawLinePIXEL(x1,y1,x2,y2, brushSize, livelli[activeLyr].pg);
if (symX) // draw symmetry from X axis
{
calcSymX(x1,y1,x2,y2);
drawLinePIXEL(s1x, s1y, s2x, s2y, brushSize, livelli[activeLyr].pg);
}
if (symY) // draw symmetry from Y axis
{
calcSymY(x1,y1,x2,y2);
drawLinePIXEL(s1x, s1y, s2x, s2y, brushSize, livelli[activeLyr].pg);
}
if(symX && symY) // draw symmetry from center point (opposite)
{
calcSymXY(x1,y1,x2,y2);
drawLinePIXEL(s1x, s1y, s2x, s2y, brushSize, livelli[activeLyr].pg);
}
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
livelli[activeLyr].pg.updatePixels();
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// INK PRESSED
else if ((!keyPressed) && (tool=="Ink") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
int x0 = mouseX;
int y0 = mouseY;
if (grab) { grabLayer(); } // grab layer for Undo
//livelli[activeLyr].pg.noSmooth();
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
livelli[activeLyr].pg.noStroke();
livelli[activeLyr].pg.fill(brushCol);
if (noGlitch) { prepareGlitch(); } // Start antialias...
if (aSelection) { livelli[activeLyr].pg.clip(x1sel+1, y1sel+1, x2sel-x1sel-1, y2sel-y1sel-1); } // check selection
myIB.clear();
myIB.clearPolys();
myIB.addPoint(x0, y0);
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// STAMP PRESSED
else if ((!keyPressed) && (tool=="Stamp") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
xs0 = mouseX;
ys0 = mouseY;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
if (noGlitch) { prepareGlitch(); } // Start antialias...
if (!userStamp) { mySB.createStampBrush(); }
if (aSelection) { livelli[activeLyr].pg.clip(x1sel+1, y1sel+1, x2sel-x1sel-1, y2sel-y1sel-1); } // check selection
livelli[activeLyr].pg.image(stampPG, xs0-brushSize/2,ys0-brushSize/2);
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// MIXER PRESSED
else if ((!keyPressed) && (tool=="Mixer") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
xs0 = mouseX;
ys0 = mouseY;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
// create mixer brush
mixer_alpha = (int)slMIXERA.v;
mixer_decay = (int)slMIXERD.v;
mixer = livelli[activeLyr].pg.get(xs0-brushSize/2,ys0-brushSize/2,brushSize,brushSize);
if (noGlitch) { prepareGlitch(); } // Start antialias...
// create mixer brush
mixer.loadPixels();
int cx = mixer.width/2;
int cy = mixer.height/2;
int loc = 0;
for (int x = 0; x < brushSize; x++)
{
for (int y = 0; y < brushSize; y++)
{
if (dist(x,y,cx,cy) >= brushSize/2)
{
loc = x + y * mixer.width;
mixer.pixels[loc] = 0x0;
}
}
}
mixer.updatePixels();
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// FILLER PRESSED
else if ((!keyPressed) && (tool=="Filler") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
if (!cbFILLERASE.s) // fill area
{
// do not fill if same colors
if (brushCol != livelli[activeLyr].pg.get(mouseX,mouseY))
{
startAction = true;
if (grab) { grabLayer(); } // grab layer for Undo
// Flood fill area of active layer with current color
floodFill(livelli[activeLyr].pg, mouseX, mouseY, brushCol);
mousePressed = false;
}
else { println("no fill: SAME COLORS"); }
}
else // erase area
{
if (((livelli[activeLyr].pg.get(mouseX,mouseY) >> 24) & 0xff ) != 0) // not transparent
{
startAction = true;
if (grab) { grabLayer(); } // grab layer for Undo
// Flood fill area of active layer with current color
floodFill(livelli[activeLyr].pg, mouseX, mouseY, 0x0);
mousePressed = false;
}
else { println("no erase: ALREADY ERASED"); }
}
}
// CLONE PRESSED (LEFT BUTTON)
else if ((!keyPressed) && (tool=="Clone") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
x2 = mouseX;
y2 = mouseY;
if (cloneGap)
{
gapX = x2 - cloneX;
gapY = y2 - cloneY;
cloneGap = true;
}
if (grab) { grabLayer(); } // grab layer for Undo
}
// ALPHA PRESSED
else if ((!keyPressed) && (tool=="Alpha") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
int x0 = mouseX;
int y0 = mouseY;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
// Clear string hashset (Set<String> pts = new HashSet<String>();)
if (!cbALPHAT.s) { ptsAlpha.clear(); }
//int numPtrs = ptsAlpha.size();
int ll = width*height;
int dAlpha = (int) slALPHAT.v;
livelli[activeLyr].pg.loadPixels();
int rr = brushSize/2;
for (int x = x0 - rr; x < x0 + rr; x++)
{
for (int y = y0 - rr; y < y0 + rr; y++)
{
int loc = x+y*width;
String newPt = String.valueOf(loc);
if (ptsAlpha.contains(newPt))
{ } // do nothing (the point is already processed)
else
{
if ((!aSelection) || (aSelection && x>x1sel && x<x2sel && y>y1sel && y<y2sel)) // check active selection
{
if ((loc >= 0) && (loc < ll) && ((x - x0)*(x - x0) + (y - y0)*(y - y0) < rr*rr))
{
// process point
color tc = livelli[activeLyr].pg.pixels[loc];
int ta = (tc >> 24) & 0xff;
if ( ((cbALPHATT.s) && (ta != 0)) || (!cbALPHATT.s) )
{
// add new point to hashset
ptsAlpha.add(newPt);
ta = constrain(ta + dAlpha,0,255);
tc = color((tc >> 16) & 0xFF, (tc >> 8) & 0xFF, tc & 0xFF, ta);
livelli[activeLyr].pg.pixels[loc] = tc;
}
}
}
}
}
}
livelli[activeLyr].pg.updatePixels();
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// RGB PRESSED
else if ((!keyPressed) && (tool=="RGB") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
int x0 = mouseX;
int y0 = mouseY;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
// Clear string hashset (Set<String> pts = new HashSet<String>();)
if (!cbRGBT.s) { ptsRGB.clear(); }
//int numPtrs = ptsRGB.size();
int ll = width*height;
int dR = (int) slRGBr.v;
int dG = (int) slRGBg.v;
int dB = (int) slRGBb.v;
livelli[activeLyr].pg.loadPixels();
int rr = brushSize/2;
for (int x = x0 - rr; x < x0 + rr; x++)
{
for (int y = y0 - rr; y < y0 + rr; y++)
{
int loc = x+y*width;
String newPt = String.valueOf(loc);
if (ptsRGB.contains(newPt))
{ } // do nothing (the point is already processed)
else
{
if ((!aSelection) || (aSelection && x>x1sel && x<x2sel && y>y1sel && y<y2sel)) // check active selection
{
if ((loc >= 0) && (loc < ll) && ((x - x0)*(x - x0) + (y - y0)*(y - y0) < rr*rr))
{
// process point
color tc = livelli[activeLyr].pg.pixels[loc];
int ta = (tc >> 24) & 0xff;
int tr = (tc >> 16) & 0xff;
int tg = (tc >> 8) & 0xff;
int tb = tc & 0xff;
if ( ((cbRGBTT.s) && (ta != 0)) || (!cbRGBTT.s) ) // transparent is locked ?
{
//ta = constrain(ta + dAlpha, 0, 255);
// add new point to hashset
ptsRGB.add(newPt);
tr = constrain(tr + dR, 0, 255);
tg = constrain(tg + dG, 0, 255);
tb = constrain(tb + dB, 0, 255);
tc = color(tr, tg, tb, ta);
livelli[activeLyr].pg.pixels[loc] = tc;
}
}
}
}
}
}
livelli[activeLyr].pg.updatePixels();
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// HSB PRESSED
else if ((!keyPressed) && (tool=="HSB") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
int x0 = mouseX;
int y0 = mouseY;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
// Clear string hashset (Set<String> pts = new HashSet<String>();)
if (!cbHSBT.s) { ptsHSB.clear(); }
//int numPtrs = ptsHSB.size();
int ll = width*height;
int dH = (int) slHSBh.v;
int dS = (int) slHSBs.v;
int dB = (int) slHSBb.v;
livelli[activeLyr].pg.loadPixels();
int rr = brushSize/2;
for (int x = x0 - rr; x < x0 + rr; x++)
{
for (int y = y0 - rr; y < y0 + rr; y++)
{
int loc = x+y*width;
String newPt = String.valueOf(loc);
if (ptsHSB.contains(newPt))
{ } // do nothing (the point is already processed)
else
{
if ((!aSelection) || (aSelection && x>x1sel && x<x2sel && y>y1sel && y<y2sel)) // check active selection
{
if ((loc >= 0) && (loc < ll) && ((x - x0)*(x - x0) + (y - y0)*(y - y0) < rr*rr))
{
// process point
color tc = livelli[activeLyr].pg.pixels[loc];
int ta = (tc >> 24) & 0xff;
if ( ((cbHSBTT.s) && (ta != 0)) || (!cbHSBTT.s) ) // transparent is locked ?
{
// add new point to hashset
ptsHSB.add(newPt);
colorMode(HSB,360.0,100.0,100.0);
float hh = hue(tc);
float ss = saturation(tc);
float bb = brightness(tc);
hh = constrain(hh + dH, 0, 360);
ss = constrain(ss + dS, 0, 100);
bb = constrain(bb + dB, 0, 100);
tc = color(hh,ss,bb,ta);
colorMode(RGB,255.0,255.0,255.0);
livelli[activeLyr].pg.pixels[loc] = tc;
}
}
}
}
}
}
livelli[activeLyr].pg.updatePixels();
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// RND PRESSED
else if ((!keyPressed) && (tool=="RND") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
int x0 = mouseX;
int y0 = mouseY;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
// if (noGlitch) { prepareGlitch(); } // No antialias with this tool :-)
int ll = width*height;
livelli[activeLyr].pg.loadPixels();
int rr = brushSize/2;
// clear hash points
ptsRGB.clear();
// get color
color tc = brushCol;
int ta = (tc >> 24) & 0xff;
int tr = (tc >> 16) & 0xff;
int tg = (tc >> 8) & 0xff;
int tb = tc & 0xff;
// get delta value
int dA = (int) slRNDa.v;
int dR = (int) slRNDr.v;
int dG = (int) slRNDg.v;
int dB = (int) slRNDb.v;
for (int x = x0 - rr; x < x0 + rr; x++)
{
for (int y = y0 - rr; y < y0 + rr; y++)
{
int loc = x+y*width;
String newPt = String.valueOf(loc);
if (ptsRGB.contains(newPt))
{ } // do nothing (the point is already processed)
else
{
if ((!aSelection) || (aSelection && x>x1sel && x<x2sel && y>y1sel && y<y2sel)) // check active selection
{
if ((loc >= 0) && (loc < ll) && ((x - x0)*(x - x0) + (y - y0)*(y - y0) < rr*rr))
{
// add new point to hashset
ptsRGB.add(newPt);
//println("1)",ta,tr,tg,tb);
int newta = constrain(ta + (int) random(-dA,dA), 0, 255);
int newtr = constrain(tr + (int) random(-dR,dR), 0, 255);
int newtg = constrain(tg + (int) random(-dG,dG), 0, 255);
int newtb = constrain(tb + (int) random(-dB,dB), 0, 255);
tc = color(newtr, newtg, newtb, newta);
//println("2)",newta,newtr,newtg,newtb);
livelli[activeLyr].pg.pixels[loc] = tc;
}
}
}
}
}
livelli[activeLyr].pg.updatePixels();
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// BACK PRESSED // Background creator
else if ((!keyPressed) && (tool=="BACK") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
{
startAction = true;
int x0 = mouseX;
int y0 = mouseY;
if (grab) { grabLayer(); } // grab layer for Undo
livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
// if (noGlitch) { prepareGlitch(); } // No antialias with this tool :-)
int ll = width*height;
livelli[activeLyr].pg.loadPixels();
// get color components (Alpha, RGB, HSB)
color tc = brushCol;
float ta = (tc >> 24) & 0xff;
float tr = (tc >> 16) & 0xff;
float tg = (tc >> 8) & 0xff;
float tb = tc & 0xff;
// backup color components
float az = ta;
float rz = tr;
float gz = tg;
float bz = tb;
colorMode(HSB,255.0,255.0,255.0);
float hh = hue(tc);
float ss = saturation(tc);
float bb = brightness(tc);
float hhz = hh;
float ssz = ss;
float bbz = bb;
colorMode(RGB,255.0,255.0,255.0);
// get delta value
float dA = (sbBACKa.v);
float d1 = (sbBACK1.v);
float d2 = (sbBACK2.v);
float d3 = (sbBACK3.v);
//println("Start color (RGB):",ta,tr,tg,tb);
//println("Start color (HSB):",ta,hh,ss,bb);
//println("Start color (HSBn):",ta,360.0*hh/255,ss/2.55,bb/2.55);
if (cbBACKv.s) // vertical fill
{
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
int loc = x+y*width;
{
if ((!aSelection) || (aSelection && x>x1sel && x<x2sel && y>y1sel && y<y2sel)) // check active selection
{
if ((loc >= 0) && (loc < ll))
{
//println("1)",ta,tr,tg,tb);
if (cbBACKadd.s) // cumulative delta
{
if (cbBACKrgb.s) // rgb
{
ta = constrain(ta + (random(-dA,dA)), az-sbBACKaMax.v, az+sbBACKaMax.v);
tr = constrain(tr + (random(-d1,d1)), rz-sbBACK1Max.v, rz+sbBACK1Max.v);
tg = constrain(tg + (random(-d2,d2)), gz-sbBACK2Max.v, gz+sbBACK2Max.v);
tb = constrain(tb + (random(-d3,d3)), bz-sbBACK3Max.v, bz+sbBACK3Max.v);
tc = color(tr, tg, tb, ta);
}
else // hsb
{
ta = constrain(ta + (random(-dA,dA)), az-sbBACKaMax.v, az+sbBACKaMax.v);
hh = constrain(hh + (random(-d1,d1)), hhz-sbBACK1Max.v, hhz+sbBACK1Max.v);
ss = constrain(ss + (random(-d2,d2)), ssz-sbBACK2Max.v, ssz+sbBACK2Max.v);
bb = constrain(bb + (random(-d3,d3)), bbz-sbBACK3Max.v, bbz+sbBACK3Max.v);
colorMode(HSB,255.0,255.0,255.0);
tc = color(hh, ss, bb, ta);
colorMode(RGB,255.0,255.0,255.0);
}
}
else // non cumulative
{
if (cbBACKrgb.s) // rgb
{
float newta = constrain(ta + (random(-dA,dA)), 0, 255);
float newtr = constrain(tr + (random(-d1,d1)), 0, 255);
float newtg = constrain(tg + (random(-d2,d2)), 0, 255);
float newtb = constrain(tb + (random(-d3,d3)), 0, 255);
tc = color(newtr, newtg, newtb, newta);
}
else // hsb
{
float newta = constrain(ta + (random(-dA,dA)), 0, 255);
float newhh = constrain(hh + (random(-d1,d1)), 0, 255);
float newss = constrain(ss + (random(-d2,d2)), 0, 255);
float newbb = constrain(bb + (random(-d3,d3)), 0, 255);
colorMode(HSB,255.0,255.0,255.0);
tc = color(newhh, newss, newbb, ta);
colorMode(RGB,255.0,255.0,255.0);
}
}
//println("2)",newta,newtr,newtg,newtb);
livelli[activeLyr].pg.pixels[loc] = tc;
}
}
}
}
//ta = az;
//tr = rz;
//tg = gz;
//tb = bz;
//hh = hhz;
//ss = ssz;
//bb = bbz;
}
}
else // horizontal fill
{
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int loc = x+y*width;
{
if ((!aSelection) || (aSelection && x>x1sel && x<x2sel && y>y1sel && y<y2sel)) // check active selection
{
if ((loc >= 0) && (loc < ll))
{
//println("1)",ta,tr,tg,tb);
if (cbBACKadd.s) // cumulative delta
{
if (cbBACKrgb.s) // rgb
{
ta = constrain(ta + (random(-dA,dA)), az-sbBACKaMax.v, az+sbBACKaMax.v);
tr = constrain(tr + (random(-d1,d1)), rz-sbBACK1Max.v, gz+sbBACK1Max.v);
tg = constrain(tg + (random(-d2,d2)), gz-sbBACK2Max.v, rz+sbBACK2Max.v);
tb = constrain(tb + (random(-d3,d3)), bz-sbBACK3Max.v, bz+sbBACK3Max.v);
tc = color(tr, tg, tb, ta);
}
else // hsb
{
ta = constrain(ta + (random(-dA,dA)), az-sbBACKaMax.v, az+sbBACKaMax.v);
hh = constrain(hh + (random(-d1,d1)), hhz-sbBACK1Max.v, hhz+sbBACK1Max.v);
ss = constrain(ss + (random(-d2,d2)), ssz-sbBACK2Max.v, ssz+sbBACK2Max.v);
bb = constrain(bb + (random(-d3,d3)), bbz-sbBACK3Max.v, bbz+sbBACK3Max.v);
colorMode(HSB,255.0,255.0,255.0);
tc = color(hh, ss, bb, ta);
colorMode(RGB,255.0,255.0,255.0);
}
}
else // non cumulative
{
if (cbBACKrgb.s) // rgb
{
float newta = constrain(ta + (random(-dA,dA)), 0, 255);
float newtr = constrain(tr + (random(-d1,d1)), 0, 255);
float newtg = constrain(tg + (random(-d2,d2)), 0, 255);
float newtb = constrain(tb + (random(-d3,d3)), 0, 255);
tc = color(newtr, newtg, newtb, newta);
}
else // hsb
{
float newta = constrain(ta + (random(-dA,dA)), 0, 255);
float newhh = constrain(hh + (random(-d1,d1)), 0, 255);
float newss = constrain(ss + (random(-d2,d2)), 0, 255);
float newbb = constrain(bb + (random(-d3,d3)), 0, 255);
colorMode(HSB,255.0,255.0,255.0);
tc = color(newhh, newss, newbb, ta);
colorMode(RGB,255.0,255.0,255.0);
}
}
//println("2)",newta,newtr,newtg,newtb);
livelli[activeLyr].pg.pixels[loc] = tc;
}
}
}
}
}
}
//println("End color (RGB):",ta,tr,tg,tb);
//println("End color (HSB):",ta,hh,ss,bb);
//println("End color (HSBn):",ta,360.0*hh/255,ss/2.55,bb/2.55);
livelli[activeLyr].pg.updatePixels();
livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
}
// TOOL01 PRESSED
//else if ((!keyPressed) && (tool=="Tool01") && (!livelli[activeLyr].ll) && ((!menu) || (x1 > menuX)))
//{
// startAction = true;
// int x0 = mouseX;
// int y0 = mouseY;
// if (grab) { grabLayer(); } // grab layer for Undo
// livelli[activeLyr].pg.beginDraw(); // open active layer PGraphics
// // if (noGlitch) { prepareGlitch(); } // No antialias with this tool :-)
// int ll = width*height;
// livelli[activeLyr].pg.loadPixels();
// //int rr = brushSize/2;
// int rr=height;
// //int rr = brushSize*2;
// // clear hash points
// ptsRGB.clear();
// // get color
// color tc = brushCol;
// int ta = (tc >> 24) & 0xff;
// int tr = (tc >> 16) & 0xff;
// int tg = (tc >> 8) & 0xff;
// int tb = tc & 0xff;
// // get delta value
// int dA = (int) slRNDa.v;
// int dR = (int) slRNDr.v;
// int dG = (int) slRNDg.v;
// int dB = (int) slRNDb.v;
// for (int x = x0 - rr; x < x0 + rr; x++)
// {
// for (int y = y0 - rr; y < y0 + rr; y++)
// {
// int loc = x+y*width;
// String newPt = String.valueOf(loc);
// if (ptsRGB.contains(newPt))
// { } // do nothing (the point is already processed)
// else
// {
// if ((!aSelection) || (aSelection && x>x1sel && x<x2sel && y>y1sel && y<y2sel)) // check active selection
// {
// if ((loc >= 0) && (loc < ll) && ((x - x0)*(x - x0) + (y - y0)*(y - y0) < rr*rr))
// {
// // add new point to hashset
// ptsRGB.add(newPt);
// //println("1)",ta,tr,tg,tb);
// //int newta = constrain(ta + (int) random(-dA,dA), 0, 255);
// //int newtr = constrain(tr + (int) random(-dR,dR), 0, 255);
// //int newtg = constrain(tg + (int) random(-dG,dG), 0, 255);
// //int newtb = constrain(tb + (int) random(-dB,dB), 0, 255);
// //tc = color(newtr, newtg, newtb, newta);
// ta = constrain(ta + (int) random(-dA,dA), 0, 255);
// tr = constrain(tr + (int) random(-dR,dR), 0, 255);
// tg = constrain(tg + (int) random(-dG,dG), 0, 255);
// tb = constrain(tb + (int) random(-dB,dB), 0, 255);
// tc = color(tr, tg, tb, ta);
// //println("2)",newta,newtr,newtg,newtb);
// livelli[activeLyr].pg.pixels[loc] = tc;
// }
// }
// }
// }
// }
// livelli[activeLyr].pg.updatePixels();
// livelli[activeLyr].pg.endDraw(); // close active layer PGraphics
//}
} // LEFT mouse if
else if (mouseButton == RIGHT)
{
// CLONE PRESSED (RIGHT BUTTON)
if ((!keyPressed) && (tool=="Clone") && (!livelli[activeLyr].ll) && !myHSB.isOver() && ((!menu) || (x1 > menuX)))
{
cloneX = mouseX;
cloneY = mouseY;
cloneGap = true;
gapX = mouseX - cloneX;
gapY = mouseY - cloneY;
}
// STAMP PRESSED (RIGHT BUTTON) (userStamp)
else if ((!keyPressed) && (tool=="Stamp") && (!livelli[activeLyr].ll) && !myHSB.isOver() && ((!menu) || (x1 > menuX)))
{
xs0 = mouseX;
ys0 = mouseY;
userStamp = true;
int locLyr, locStamp;
int locLyrMax = width*height;
int locStampMax = brushSize*brushSize;
stampPG = createGraphics(brushSize, brushSize);
stampPG.noSmooth();
stampPG.beginDraw();
stampPG.clear();
stampPG.loadPixels();
livelli[activeLyr].pg.loadPixels();
// clone image under cursor on stampPG
for (int y = ys0-brushSize/2; y < ys0+brushSize/2; y++)
{
for (int x = xs0-brushSize/2; x < xs0+brushSize/2; x++)
{
locLyr = x + y*width;
locStamp = (x - (xs0-brushSize/2)) + (y- (ys0-brushSize/2))*brushSize;
if (locLyr > 0 && locLyr < locLyrMax && locStamp > 0 && locStamp < locStampMax)
{
if (livelli[activeLyr].pg.pixels[locLyr] != 0x0)
{
{ stampPG.pixels[locStamp] = livelli[activeLyr].pg.pixels[locLyr]; }
}
}
}
}
//livelli[activeLyr].pg.updatePixels();
stampPG.updatePixels();
stampPG.endDraw();
}
} // RIGHT mouse if
// PICK COLOR PRESSED
if (keyPressed && mousePressed && picker && !myHSB.isOver()) // pick color from active layer
{
color pickCol;
if (mouseButton == RIGHT)
{
pickCol = livelli[activeLyr].pg.get(mouseX,mouseY);
}
else
{
pickCol = get(mouseX,mouseY);
}
brushCol = color(pickCol,alfa);
rgbhsb.setRGBHSB(brushCol);
myHSB.updateHSB("HSB");
picker = false;
}
// MENU PRESSED
if (menu)
{
// check layer icons pressed
for(int i = 0; i < livelli.length; i++)
{
livelli[i].onClickIcon();
livelli[i].onClickTransp();
}
controlloLivelli.onClick();
// check pressed on RGB-SHB control
rgbhsb.onClick();
// check on palette page pressed
tavolozza.onClick();
// check button tools
btnPENCIL.onClick();
btnLINER.onClick();
btnLOCK.onClick();
btnQUAD.onClick();
btnCIRCLE.onClick();
btnERASER.onClick();
btnSELECT.onClick();
btnSTENCIL.onClick();
btnVERNICE.onClick();
btnINK.onClick();
btnSTAMP.onClick();
btnMIXER.onClick();
btnDYNA.onClick();
btnFILLER.onClick();