MCPcopy Create free account
hub / github.com/MankaiHuang/screen-visualization / loop

Function loop

public/iframe/lib/js/mixinsComponents.js:3133–3219  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3131
3132 // Render loop
3133 const loop = () => {
3134 const rad = sin(frame / 100) * PI / 20
3135 const rad2 = sin(frame / 50) * PI / 10
3136 frame++
3137 if (postctx.canvas.width !== postctx.canvas.offsetWidth || postctx.canvas.height !== postctx.canvas.offsetHeight) {
3138 postctx.canvas.width = canvas.width = postctx.canvas.offsetWidth
3139 postctx.canvas.height = canvas.height = postctx.canvas.offsetHeight
3140 }
3141
3142
3143 c.fillStyle = `hsl(200deg, 100%, 2%)`
3144 c.fillRect(0, 0, canvas.width, canvas.height)
3145 c.save()
3146 c.translate(canvas.width / 2, canvas.height / 2)
3147
3148 c.beginPath()
3149 vertices.forEach((vertex, i) => {
3150 const ni = i + oceanWidth
3151 let x = vertex[0] - frame % (gridSize * 2)
3152 let z = vertex[2] - frame * 2 % gridSize + (i % 2 === 0 ? gridSize / 2 : 0)
3153 const wave = (cos(frame / 45 + x / 50) - sin(frame / 20 + z / 50) + sin(frame / 30 + z * x / 10000))
3154 let y = vertex[1] + wave * waveSize
3155 const a = Math.max(0, 1 - (Math.sqrt(x ** 2 + z ** 2)) / depth)
3156 let tx;
3157 let ty;
3158 let tz
3159
3160 y -= oceanHeight
3161
3162 // Transformation variables
3163 tx = x
3164 ty = y
3165 tz = z
3166
3167 // Rotation Y
3168 tx = x * cos(rad) + z * sin(rad)
3169 tz = -x * sin(rad) + z * cos(rad)
3170
3171 x = tx
3172 y = ty
3173 z = tz
3174
3175 // Rotation Z
3176 tx = x * cos(rad) - y * sin(rad)
3177 ty = x * sin(rad) + y * cos(rad)
3178
3179 x = tx;
3180 y = ty;
3181 z = tz;
3182
3183 // Rotation X
3184
3185 ty = y * cos(rad2) - z * sin(rad2)
3186 tz = y * sin(rad2) + z * cos(rad2)
3187
3188 x = tx;
3189 y = ty;
3190 z = tz;

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected