-
Notifications
You must be signed in to change notification settings - Fork 0
/
e7.pix
72 lines (67 loc) · 2.91 KB
/
e7.pix
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
#define NUMBER_TO_PRINT esol
#define DISTANCE_BETWEEN_DIGITS 0.05
#define LINE_WIDTH 0.05
#define ON_COLOR vec4(0.0, 1.0, 0.0, 1.0);
#define OFF_COLOR vec4(0.0, 0.0, 0.0, 1.0);
float digits(float x) {
if (x < 2.0) { return 1.0; }
return ceil(log(x) / log(10.0));
}
int imod(int x, int y) {
return x - y*(x/y);
}
int euler7() {
int numprimes = 1;
int ans = 0;
for (int i = 3; i < 150000; i += 2) {
bool isprime = (imod(i, 2) != 0);
for (int j = 3; j*j <= i; j += 2) {
isprime = isprime && (imod(i, j) > 0);
}
numprimes = numprimes + int(isprime);
ans += (int(numprimes == 10001) * i);
numprimes += int(numprimes == 10001);
}
return ans;
}
uniform vec3 iResolution;
void main(void)
{
int esol = euler7();
vec2 uv = gl_FragCoord.xy / iResolution.xy;
//Below line switches between glsl and webgl coordinaes
//uv.y = 1.0 - uv.y;
float N = digits(float(NUMBER_TO_PRINT));
float width = (1.0 - (N-1.0)*DISTANCE_BETWEEN_DIGITS) / N;
float digit = floor(uv.x / (width + DISTANCE_BETWEEN_DIGITS));
//coordinates within box
float digitStartx = (width+DISTANCE_BETWEEN_DIGITS)*digit;
float digitEndx = digitStartx + width;
vec2 sub_uv = vec2((uv.x - digitStartx) * 1.0/(digitEndx - digitStartx), (uv.y - .2) * (1.0/.6));
//Computing a power of 10 was made harder because webgl
//Could do something less silly in actual glsl
int p = 1;
for (int i = 0; i < 10; ++i) {
p *= (1 + int(i < int(N) - int(digit)) * 9);
}
int currentDigit = imod(NUMBER_TO_PRINT, p) / (p/10);
//Determining the position
bool tiptop = sub_uv.y < LINE_WIDTH && sub_uv.y > 0.0;
bool top = sub_uv.y < 0.5 - LINE_WIDTH/2.0&& sub_uv.y > 0.0;
bool left = sub_uv.x > 0.0 && sub_uv.x < LINE_WIDTH;
bool middle_x = sub_uv.x > LINE_WIDTH && sub_uv.x < 1.0 - LINE_WIDTH;
bool middle_y = sub_uv.y > 0.5 - LINE_WIDTH/2.0&& sub_uv.y < 0.5 + LINE_WIDTH/2.0;
bool right = sub_uv.x > (1.0 - LINE_WIDTH) && sub_uv.x < 1.0;
bool bottom = sub_uv.y > 0.5 + LINE_WIDTH/2.0&& sub_uv.y < 1.0;
bool botbot = sub_uv.y > 1.0 - LINE_WIDTH && sub_uv.y < 1.0;
//shorthand
int c = currentDigit;
bool bit =(top && left && (c != 1 && c != 2 && c != 3 && c != 7)) ||
(top && right && (c != 5 && c != 6)) ||
(tiptop && middle_x && (c != 1 && c != 4)) ||
(middle_x && middle_y && (c > 1 && c != 7)) ||
(bottom && left && (c/2*2 == c) && c != 4) ||
(bottom && right && (c != 2)) ||
(botbot && middle_x && (c != 1 && c != 4 && c != 7));
gl_FragColor = float(bit && true) * ON_COLOR + float(!(bit && true)) * OFF_COLOR;
}