@@ -4,6 +4,8 @@ PImage img;
44boolean imageLoaded = false ;
55String message = " Please Press L to load an image" ;
66
7+ int ditherIdx = 0 ;
8+
79void setup () {
810 size (400 , 400 ); // Initial size, will be adjusted
911 surface. setResizable(true );
@@ -17,65 +19,56 @@ void draw() {
1719
1820 if (imageLoaded && img != null ) {
1921 PImage processed = img;
20- processed = Dithering . apply(processed, Dithering . BAYER_8x8 );
22+
23+ if (ditherIdx == 0 ) {
24+ processed = Dithering . apply(processed, Dithering . Algorithm . BAYER_2x2 );
25+ // label = "BAYER_2x2";
26+ }
27+ if (ditherIdx == 1 ) {
28+ processed = Dithering . apply(processed, Dithering . Algorithm . BAYER_4x4 );
29+ // label = "BAYER_4x4";
30+ }
31+ if (ditherIdx == 2 ) {
32+ processed = Dithering . apply(processed, Dithering . Algorithm . BAYER_8x8 );
33+ // label = "BAYER_8x8";
34+ }
35+
36+ // processed = Dithering.apply(processed, Dithering.BAYER_8x8);
2137 image (processed, 0 , 0 , width , height );
2238
2339 textAlign (CENTER , CENTER );
2440 textSize (16 );
2541 rectMode (CENTER );
2642 noStroke ();
2743 fill (0 );
28- rect (width / 2 , height - 20 , 480 , 30 );
44+ rect (width / 2 , height - 60 , 400 , 70 );
2945 fill (255 );
3046 textSize (12 );
31- text (" Press L to a New Image or Press S to save the current Dithered image. \n Use the left or right arrow keys to swap between 3 different dither effects." , width / 2 , height - 20 );
47+ text (" Press L to a New Image\n Use the left or right arrow keys to swap between 3 different dither effects.\n Press S to save the current Dithered image. \n Press ESC to close the window. " , width / 2 , height - 60 );
3248 } else {
3349 fill (255 );
3450 textSize (16 );
3551 text (message, width / 2 , height / 2 );
3652 }
37-
38-
39- // PImage processed = image;
40- // processed = Dithering.apply(processed, Dithering.BAYER_8x8);
41- // String label = "";
42-
43- // if (keyPressed && key == ' ') {
44- // processed = Grayscale.apply(processed);
45- // }
46-
47- // if (mousePressed == true) {
48- // image(image, 0, 0);
49- // } else {
50-
51- // if (index == -1) {
52- // processed = Dithering.apply(processed);
53- // //label = "BAYER_4x4 on default";
54- // }
55-
56- // if (index == 0) {
57- // processed = Dithering.apply(processed, Dithering.Algorithm.BAYER_2x2);
58- // //label = "BAYER_2x2";
59- // }
60- // if (index == 1) {
61- // processed = Dithering.apply(processed, Dithering.Algorithm.BAYER_4x4);
62- // //label = "BAYER_4x4";
63- // }
64-
65- // if (index == 2) {
66- // processed = Dithering.apply(processed, Dithering.Algorithm.BAYER_8x8);
67- // //label = "BAYER_8x8";
68- // }
69- // }
70-
71- // image(processed, 0, 0);
72-
73- // fill(0);
74- // text(label, width/2 - textWidth(label)/2, 30);
7553}
7654
7755
7856void keyPressed () {
57+ if (key == CODED ) {
58+ if (keyCode == RIGHT ) {
59+ ditherIdx= ditherIdx+ 1 ;
60+ }
61+ if (keyCode == LEFT ) {
62+ ditherIdx= ditherIdx- 1 ;
63+ }
64+ if (ditherIdx < 1 ) {
65+ ditherIdx = 3 ;
66+ }
67+ if (ditherIdx > 2 ) {
68+ ditherIdx = 0 ;
69+ }
70+ }
71+
7972 if (key == ' l' || key == ' L' ) {
8073 selectInput (" Select an image file:" , " fileSelected" );
8174 }
0 commit comments