summaryrefslogtreecommitdiff
path: root/Year_2/IandM/negative
diff options
context:
space:
mode:
Diffstat (limited to 'Year_2/IandM/negative')
-rw-r--r--Year_2/IandM/negative/data/lena.pngbin0 -> 473831 bytes
-rw-r--r--Year_2/IandM/negative/negative.pde25
2 files changed, 25 insertions, 0 deletions
diff --git a/Year_2/IandM/negative/data/lena.png b/Year_2/IandM/negative/data/lena.png
new file mode 100644
index 0000000..59ef68a
--- /dev/null
+++ b/Year_2/IandM/negative/data/lena.png
Binary files differ
diff --git a/Year_2/IandM/negative/negative.pde b/Year_2/IandM/negative/negative.pde
new file mode 100644
index 0000000..c7c4475
--- /dev/null
+++ b/Year_2/IandM/negative/negative.pde
@@ -0,0 +1,25 @@
+void setup() {
+ size(512, 256);
+ PImage img = loadImage("lena.png");
+ img.resize(256, 256);
+
+ image(img, 0, 0);
+ image(negative(img), 256, 0);
+}
+
+PImage negative(PImage I) {
+ PImage out = I.copy();
+ out.loadPixels();
+ float r, g, b;
+
+ for (int i = 0; i < out.pixels.length; ++i) {
+ r= 255-red(out.pixels[i]);
+ g= 255-green(out.pixels[i]);
+ b= 255-blue(out.pixels[i]);
+
+ out.pixels[i] = color(r, g, b);
+ }
+
+ out.updatePixels();
+ return out;
+}