snakey.js
· 783 B · JavaScript
Sin formato
Shader.AA_CIRCLE ??= Shader(`void main(){
float l = .5-length(uv-.5);
float op = clamp(l/fwidth(l)+.5, 0., 1.);
color = arg0()*op;
}`, COLOR)
const circles = new Float32Array(20).fill(NaN)
render = () => {
ctx.reset(pixelRatio/ctx.width, 0, 0, pixelRatio/ctx.height, .5, .5)
let {x, y} = ctx.from(cursor)
ctx.shader = Shader.AA_CIRCLE
let r = 50
ctx.drawRect(x-r, y-r, r*2, r*2, vec4(.5))
for(let i = 0; i < circles.length; i += 2){
const r2 = r+(r*=.9)
let px = circles[i] - x, py = circles[i+1] - y
const d = r2/hypot(px, py)
if(!d) px = 0, py = r2 // catch NaN
else px *= d, py *= d
circles[i] = x += px
circles[i+1] = y += py
ctx.drawRect(x-r, y-r, r*2, r*2, vec4(r*.01))
}
}
| 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 | } |