Add completed the inverse RGB filter
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>randomDot</title>
|
||||
<script src="libraries/p5.min.js" type="text/javascript"></script>
|
||||
|
||||
<script src="libraries/p5.dom.js" type="text/javascript"></script>
|
||||
<script src="libraries/p5.sound.js" type="text/javascript"></script>
|
||||
|
||||
<script src="sketch.js" type="text/javascript"></script>
|
||||
|
||||
<style> body {padding: 0; margin: 0;} canvas {vertical-align: top;} </style>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
36
CM2030 Graphics Programming/Week 15/1. Invert filter/libraries/p5.min.js
vendored
Normal file
36
CM2030 Graphics Programming/Week 15/1. Invert filter/libraries/p5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,41 @@
|
||||
let imgIn;
|
||||
let imgOut;
|
||||
|
||||
function preload()
|
||||
{
|
||||
imgIn = loadImage("assets/seaNettles.jpg");
|
||||
}
|
||||
|
||||
function setup() {
|
||||
createCanvas(imgIn.width * 2, imgIn.height);
|
||||
pixelDensity(1);
|
||||
}
|
||||
|
||||
function draw()
|
||||
{
|
||||
background(255, 0, 255);
|
||||
image(imgIn, 0, 0);
|
||||
image(invertFilter(imgIn), imgIn.width, 0);
|
||||
noLoop();
|
||||
}
|
||||
|
||||
function invertFilter(img) {
|
||||
|
||||
imgOut = createImage(img.width, img.height);
|
||||
imgOut.loadPixels();
|
||||
img.loadPixels();
|
||||
|
||||
for(let y=0; y<img.height; y++)
|
||||
{
|
||||
for(let x=0; x<img.width; x++)
|
||||
{
|
||||
let index = (img.width * y + x) * 4;
|
||||
imgOut.pixels[index + 0] = 255 - img.pixels[index + 0]
|
||||
imgOut.pixels[index + 1] = 255 - img.pixels[index + 1]
|
||||
imgOut.pixels[index + 2] = 255 - img.pixels[index + 2]
|
||||
imgOut.pixels[index + 3] = 255;
|
||||
}
|
||||
}
|
||||
imgOut.updatePixels();
|
||||
return imgOut;
|
||||
}
|
||||
Reference in New Issue
Block a user