-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
209 lines (166 loc) · 6.94 KB
/
script.js
File metadata and controls
209 lines (166 loc) · 6.94 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
function lerp(a, b, t) {
return a + (b - a) * t;
}
const canvas = document.getElementById("backgroundCanvas");
const gl = canvas.getContext("webgl");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let totalScrolledDistance = 0;
let scrollSpeed = 0;
let lastScrollY = window.scrollY;
let smooth
document.addEventListener("scroll", () => {
let currentScrollY = window.scrollY;
scrollSpeed = lerp(scrollSpeed, (currentScrollY - lastScrollY), 0.2);
lastScrollY = currentScrollY;
const arrow = document.getElementById("arrow");
if (window.scrollY > 0) {
arrow.style.opacity = "0";
} else {
arrow.style.opacity = "1";
}
});
setInterval(() => {
if (scrollSpeed > 0) {
totalScrolledDistance += scrollSpeed;
}
scrollSpeed *= 0.98;
}, 10);
const vertexShaderSource = `
#version 100
attribute vec2 a_position;
varying vec2 v_texcoord;
void main() {
v_texcoord = a_position * 0.5 + 0.5;
gl_Position = vec4(a_position, 0.0, 1.0);
}
`;
const fragmentShaderSource = `
#version 100
precision highp float;
#define MY_HIGHP_OR_MEDIUMP highp
#define number float
#define SPIN_EASE 0.5
varying vec2 v_texcoord;
uniform vec2 iResolution;
uniform MY_HIGHP_OR_MEDIUMP number time;
uniform MY_HIGHP_OR_MEDIUMP number spin_time;
vec4 effect( vec4 colour, vec2 screen_coords )
{
vec2 love_ScreenSize = iResolution.xy;
MY_HIGHP_OR_MEDIUMP vec4 colour_1 = vec4(0.03, 0.19, 0.36, 1.0); // outside
MY_HIGHP_OR_MEDIUMP vec4 colour_2 = vec4(1.0, 0.95, 0.68, 1.0); // inside
MY_HIGHP_OR_MEDIUMP vec4 colour_3 = vec4(0.92, 0.58, 0.07, 1.0); // middle
MY_HIGHP_OR_MEDIUMP number contrast = 1.0;
MY_HIGHP_OR_MEDIUMP number spin_amount = 1.0;
//Convert to UV coords (0-1) and floor for pixel effect
MY_HIGHP_OR_MEDIUMP number pixel_size = 1.0;
MY_HIGHP_OR_MEDIUMP vec2 uv = (floor(screen_coords.xy*(1./pixel_size))*pixel_size - 0.5*love_ScreenSize.xy)/length(love_ScreenSize.xy) - vec2(0.12, 0.);
MY_HIGHP_OR_MEDIUMP number uv_len = length(uv);
//Adding in a center swirl, changes with time. Only applies meaningfully if the 'spin amount' is a non-zero number
MY_HIGHP_OR_MEDIUMP number speed = (spin_time*SPIN_EASE*0.2) + 302.2;
MY_HIGHP_OR_MEDIUMP number new_pixel_angle = (atan(uv.y, uv.x)) + speed - SPIN_EASE*20.*(1.*spin_amount*uv_len + (1. - 1.*spin_amount));
MY_HIGHP_OR_MEDIUMP vec2 mid = (love_ScreenSize.xy/length(love_ScreenSize.xy))/2.;
uv = (vec2((uv_len * cos(new_pixel_angle) + mid.x), (uv_len * sin(new_pixel_angle) + mid.y)) - mid);
//Now add the paint effect to the swirled UV
uv *= 30.;
speed = time*(2.);
MY_HIGHP_OR_MEDIUMP vec2 uv2 = vec2(uv.x+uv.y);
for(int i=0; i < 5; i++) {
uv2 += sin(max(uv.x, uv.y)) + uv;
uv += 0.5*vec2(cos(5.1123314 + 0.353*uv2.y + speed*0.131121),sin(uv2.x - 0.113*speed));
uv -= 1.0*cos(uv.x + uv.y) - 1.0*sin(uv.x*0.711 - uv.y);
}
//Make the paint amount range from 0 - 2
MY_HIGHP_OR_MEDIUMP number contrast_mod = (0.25*contrast + 0.5*spin_amount + 1.2);
MY_HIGHP_OR_MEDIUMP number paint_res =min(2., max(0.,length(uv)*(0.035)*contrast_mod));
MY_HIGHP_OR_MEDIUMP number c1p = max(0.,1. - contrast_mod*abs(1.-paint_res));
MY_HIGHP_OR_MEDIUMP number c2p = max(0.,1. - contrast_mod*abs(paint_res));
MY_HIGHP_OR_MEDIUMP number c3p = 1. - min(1., c1p + c2p);
MY_HIGHP_OR_MEDIUMP vec4 ret_col = (0.3/contrast)*colour_1 + (1. - 0.3/contrast)*(colour_1*c1p + colour_2*c2p + vec4(c3p*colour_3.rgb, c3p*colour_1.a));
return ret_col;
}
void main() {
vec2 uv = v_texcoord;
uv.y = 1.0 - uv.y;
uv.x += 2.0/15.0;
vec2 fragCoord = uv * iResolution;
gl_FragColor = effect(vec4(1.0, 1.0, 0.0, 1.0), fragCoord);
}
`;
function compileShader(source, type) {
const shader = gl.createShader(type);
gl.shaderSource(shader, source);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
console.error('Shader compilation failed:', gl.getShaderInfoLog(shader));
gl.deleteShader(shader);
return null;
}
return shader;
}
const vertexShader = compileShader(vertexShaderSource, gl.VERTEX_SHADER);
const fragmentShader = compileShader(fragmentShaderSource, gl.FRAGMENT_SHADER);
const shaderProgram = gl.createProgram();
gl.attachShader(shaderProgram, vertexShader);
gl.attachShader(shaderProgram, fragmentShader);
gl.linkProgram(shaderProgram);
gl.useProgram(shaderProgram);
const vertices = new Float32Array([
-1.0, 1.0,
-1.0, -1.0,
1.0, 1.0,
1.0, -1.0,
]);
const vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
const positionAttributeLocation = gl.getAttribLocation(shaderProgram, "a_position");
gl.vertexAttribPointer(positionAttributeLocation, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(positionAttributeLocation);
const resolutionUniformLocation = gl.getUniformLocation(shaderProgram, "iResolution");
const timeUniformLocation = gl.getUniformLocation(shaderProgram, "time");
const spinTimeUniformLocation = gl.getUniformLocation(shaderProgram, "spin_time");
function animate() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
const time = performance.now() / 1000;
gl.uniform2f(resolutionUniformLocation, canvas.width, canvas.height);
gl.uniform1f(timeUniformLocation, time);
gl.uniform1f(spinTimeUniformLocation, time + (totalScrolledDistance * 0.0025));
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
requestAnimationFrame(animate);
}
animate();
async function fetchLatestVersion() {
const url = `https://api.github.com/repos/Firch/Bunco/releases/latest`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
const releaseDate = new Date(data.published_at);
const formattedDate = releaseDate.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric"
});
document.getElementById("download-version").innerText = `Latest version: ${data.tag_name} (${formattedDate})`;
}
window.onload = fetchLatestVersion;
document.getElementById('arrow').addEventListener('click', function() {
window.scrollTo({
top: document.body.scrollHeight,
behavior: 'smooth'
});
});
document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll("img.screenshot").forEach(img => {
img.addEventListener("click", function () {
window.location.href = img.src;
});
});
});