-
Notifications
You must be signed in to change notification settings - Fork 0
/
Crosshair.pde
109 lines (85 loc) · 2.2 KB
/
Crosshair.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
class Crosshair{
int size, x, y;
PGraphics aim;
Crosshair (int size){
this.size = size;
x = y = 0;
createAim();
}
void createAim() {
aim = createGraphics (200, 200);
aim.beginDraw();
aim.background(0);
aim.smooth();
// Visible circle
aim.noStroke();
aim.fill(255);
aim.circle(aim.width/2, aim.height/2, 200);
// Remove lines
aim.stroke(0);
aim.noFill();
aim.strokeWeight(5);
aim.line(40, 100, 160, 100);
aim.line(100, 110, 100, 90);
aim.line(100, 0, 100, 40);
aim.line(100, 200, 100, 160);
// Remove circle
aim.strokeWeight(5);
aim.circle(aim.width/2, aim.height/2, 120);
aim.endDraw();
aim.loadPixels();
color c = color (255, 255, 255, 80); // Semi transparent white
// Whites to semitransparent, black to invisible
for (var i=0; i < aim.pixels.length; i++) {
aim.pixels[i] = (aim.pixels[i] & 0xFF) == 0xFF ? c : 0; // visible / hidden
}
aim.updatePixels();
}
void update(int x, int y){
this.x = x;
this.y = y;
}
void draw(){
image(aim, x - aim.width/2, y - aim.height/2);
}
/*
void createAim2() {
PGraphics mask = createGraphics(200, 200);
mask.beginDraw();
mask.stroke(255);
mask.noFill();
mask.strokeWeight(10);
mask.line(0, 100, 200, 100);
mask.line(100, 110, 100, 90);
mask.strokeWeight(5);
mask.circle(mask.width/2, mask.height/2, 100);
mask.loadPixels();
// Invert
for (var i=0; i < mask.pixels.length; i++) {
mask.pixels[i] = (mask.pixels[i] & 0xFF) == 0xFF ? 0 : 128; // hidden / visible
}
mask.updatePixels();
mask.endDraw();
aim = createGraphics (200, 200);
aim.beginDraw();
aim.noStroke();
aim.fill(255);
aim.circle(aim.width/2, aim.height/2, 200);
aim.endDraw();
doMask(aim, mask);
}
void doMask(PImage target, PImage mask) {
mask.loadPixels();
target.loadPixels();
if (mask.pixels.length != target.pixels.length) {
println("Images are not the same size");
} else {
for (int i=0; i<target.pixels.length; i++) {
if ((target.pixels[i] & 0xff000000) == 0) continue; // Added by me
target.pixels[i] = ((mask.pixels[i] & 0xff) << 24) | (target.pixels[i] & 0xffffff);
}
target.updatePixels();
}
}
*/
}