-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPSMoulder.pde
60 lines (55 loc) · 2.32 KB
/
RPSMoulder.pde
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
class RPSMoulder extends Moulder{
int RPS;
float weightTo,weightFro;
RPSMoulder(int rps,float _weightTo,float _weightFro){
super();
if (rps < 0 || rps > 2){throw new IllegalArgumentException("0,1,2 are the valid rps values.");}
RPS = rps;
weightTo = _weightTo;
weightFro = _weightFro;
}
void sense(){
//calculate pixel indices for sensors
int leftS = pixelIndex(PVector.add(pos,PVector.mult(PVector.fromAngle(heading + sensorAngle),sensorDistance)));
int midS = pixelIndex(PVector.add(pos,PVector.mult(PVector.fromAngle(heading),sensorDistance)));
int rightS = pixelIndex(PVector.add(pos,PVector.mult(PVector.fromAngle(heading - sensorAngle),sensorDistance)));
switch(RPS){
case 0://red
senseL = round(red(pixels[leftS]) + weightTo*green(pixels[leftS]) - weightFro*blue(pixels[leftS]));
senseM = round(red(pixels[midS]) + weightTo*green(pixels[midS]) - weightFro*blue(pixels[midS]));
senseR = round(red(pixels[rightS]) + weightTo*green(pixels[rightS]) - weightFro*blue(pixels[rightS]));
break;
case 1://green
senseL = round(green(pixels[leftS]) + weightTo*blue(pixels[leftS]) - weightFro*red(pixels[leftS]));
senseM = round(green(pixels[midS]) + weightTo*blue(pixels[midS]) - weightFro*red(pixels[midS]));
senseR = round(green(pixels[rightS]) + weightTo*blue(pixels[rightS]) - weightFro*red(pixels[rightS]));
break;
case 2://blue
senseL = round(blue(pixels[leftS]) + weightTo*red(pixels[leftS]) - weightFro*green(pixels[leftS]));
senseM = round(blue(pixels[midS]) + weightTo*red(pixels[midS]) - weightFro*green(pixels[midS]));
senseR = round(blue(pixels[rightS]) + weightTo*red(pixels[rightS]) - weightFro*green(pixels[rightS]));
break;
}
}
void deposit(){
int index = pixelIndex(pos);
int r = round(red(pixels[index]));
int g = round(green(pixels[index]));
int b = round(blue(pixels[index]));
switch(RPS){
case 0://red
r += depositRate;
break;
case 1://green
g += depositRate;
break;
case 2://blue
b += depositRate;
break;
}
if(r>255){r = 255;}
if(g>255){g = 255;}
if(b>255){b = 255;}
pixels[index] = color(r,g,b);
}
}