summaryrefslogtreecommitdiff
path: root/Year_2/IandM/bitplane/bitplane.pde
diff options
context:
space:
mode:
Diffstat (limited to 'Year_2/IandM/bitplane/bitplane.pde')
-rw-r--r--Year_2/IandM/bitplane/bitplane.pde39
1 files changed, 39 insertions, 0 deletions
diff --git a/Year_2/IandM/bitplane/bitplane.pde b/Year_2/IandM/bitplane/bitplane.pde
new file mode 100644
index 0000000..33cda9c
--- /dev/null
+++ b/Year_2/IandM/bitplane/bitplane.pde
@@ -0,0 +1,39 @@
+int nb = 0;
+
+void setup() {
+ size(512, 256);
+}
+
+void draw() {
+ PImage img = loadImage("lena.png");
+ img.resize(256, 256);
+ img.filter(GRAY);
+
+ image(img, 0, 0);
+ image(bitplane(img, nb), 256, 0);
+}
+
+void keyPressed() {
+ if(key == '+' && nb < 7) {
+ nb++;
+ } else if(key == '-' && nb > 1) {
+ nb--;
+ }
+}
+
+PImage bitplane(PImage I, int nb) {
+ PImage out = I.copy();
+ out.loadPixels();
+
+ int x, r;
+
+ for (int i = 0; i < out.pixels.length; ++i) {
+ x = int(red(out.pixels[i]));
+ r = (x >> nb) & 1;
+ out.pixels[i] = color(255*r);
+ }
+
+ out.updatePixels();
+
+ return out;
+}