-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_filters.js
68 lines (62 loc) · 1.88 KB
/
image_filters.js
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
<script src="https://www.dukelearntoprogram.com/course1/common/js/image/SimpleImage.js" >
//I used Duke's Learn To Program utility class Simple Image to implement these
//this function makes an image red by increasing the R value in the RGB of a pixel
function makeredlarge(imagename) {
var image = new SimpleImage(imagename);
for(var i of image.values()){
i.setRed(255)
}
return image
}
//removes all red pixels(sets them to their least value to re-create a greenish-blue hue
function removeallred(imagename){
var image = new SimpleImage(imagename);
for(var i of image.values()){
i.setRed(0);
}
return image
}
//this function decreases the redness by setting R values greater than 70 to 70
function lessred(imagename) {
var image = new SimpleImage(imagename)
for(var i of image.values()){
var red = i.getRed()
if (red>70){
i.setRed(70)
}
}
return image
}
//this function creates a black line at the bottom of an image
function blackbottom(imagename) {
var image = new SimpleImage(imagename)
var height = image.getHeight()
var lastten = height -10
for(var i of image.values()){
if (i.getY()>= lastten){
i.setRed(0)
i.setGreen(0)
i.setBlue(0)
}
}
return image
}
//this function creates three blocks of red,green and blue equally across the width of the image
function threeverticalstripes(imagename) {
var image = new SimpleImage(imagename)
var width = image.getWidth()
var onethird = width / 3
var twothird = onethird * 2
for(var i of image.values()){
if(i.getX() <= onethird){
i.setRed(255)
}
if (i.getX() >onethird && i.getX() <=twothird) {
i.setGreen(255)
}
if (i.getX() >twothird) {
i.setBlue(255)
}
}
return image
}