DraxCodes revisó este gist . Ir a la revisión
1 file changed, 23 insertions
snakey.js(archivo creado)
@@ -0,0 +1,23 @@ | |||
1 | + | Shader.AA_CIRCLE ??= Shader(`void main(){ | |
2 | + | float l = .5-length(uv-.5); | |
3 | + | float op = clamp(l/fwidth(l)+.5, 0., 1.); | |
4 | + | color = arg0()*op; | |
5 | + | }`, COLOR) | |
6 | + | const circles = new Float32Array(20).fill(NaN) | |
7 | + | render = () => { | |
8 | + | ctx.reset(pixelRatio/ctx.width, 0, 0, pixelRatio/ctx.height, .5, .5) | |
9 | + | let {x, y} = ctx.from(cursor) | |
10 | + | ctx.shader = Shader.AA_CIRCLE | |
11 | + | let r = 50 | |
12 | + | ctx.drawRect(x-r, y-r, r*2, r*2, vec4(.5)) | |
13 | + | for(let i = 0; i < circles.length; i += 2){ | |
14 | + | const r2 = r+(r*=.9) | |
15 | + | let px = circles[i] - x, py = circles[i+1] - y | |
16 | + | const d = r2/hypot(px, py) | |
17 | + | if(!d) px = 0, py = r2 // catch NaN | |
18 | + | else px *= d, py *= d | |
19 | + | circles[i] = x += px | |
20 | + | circles[i+1] = y += py | |
21 | + | ctx.drawRect(x-r, y-r, r*2, r*2, vec4(r*.01)) | |
22 | + | } | |
23 | + | } |
Siguiente
Anterior