-
Notifications
You must be signed in to change notification settings - Fork 1
/
circles_heatmap.pde
86 lines (71 loc) · 1.59 KB
/
circles_heatmap.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
float r1 = 800;
float r2 = 600;
float r3 = 1000;
float r4 = 800;
int x1 = -500;
int y1 = -500;
int x2 = 1000+100;
int y2 = -200;
int x3 = -500;
int y3 = 1000+200;
int x4 = 1000+400;
int y4 = 1000+400;
void setup() {
size(1000, 1000);
noSmooth();
background(10);
drawHeatMap();
stroke(150, 50, 50);
strokeWeight(4);
noFill();
ellipse(x1, y1, r1*2, r1*2);
ellipse(x2, y2, r2*2, r2*2);
ellipse(x3, y3, r3*2, r3*2);
ellipse(x4, y4, r4*2, r4*2);
}
float avg_dist(int x, int y) {
float dist1 = abs ( dist(x, y, x1, y1) - r1);
float dist2 = abs ( dist(x, y, x2, y2) - r2);
float dist3 = abs ( dist(x, y, x3, y3) - r3);
float dist4 = abs ( dist(x, y, x4, y4) - r4);
return (dist1+dist2+dist3+dist4)/4;
}
float pt[][] = new float[1000][1000];
void drawHeatMap() {
float max = 0;
float min = 1000;
int mx=0,my=0;
for (int x =0; x< width; x++) {
for (int y = 0; y< height; y++) {
pt[x][y] = avg_dist(x, y);
if(pt[x][y] > max) max = pt[x][y];
if(pt[x][y] < min) {
min = pt[x][y];
mx = x;
my = y;
}
}
}
println( "min = " + min);
println("max = " +max);
for (int x =0; x< width; x++) {
for (int y = 0; y< height; y++) {
color c = lerpColor(0xffff7f00, 0xff7f00ff, map( pt[x][y], min, max-260, 0,1.0) );
stroke( c );
point(x, y);
}
}
fill(240);
stroke(250);
ellipse(mx,my,10,10);
text(pt[mx] [my], mx,my);
}
void mouseClicked() {
stroke(250);
point(mouseX,mouseY);
fill(250);
text(pt[mouseX] [mouseY], mouseX,mouseY);
println (pt[mouseX] [mouseY]);
}
void draw() {
}