Deflectors vs asteroids
How do I make an deflectors vs asteroids?
What is a deflectors vs asteroids? How do you make a deflectors vs asteroids? This script and codes were developed by Findoff on 17 December 2022, Saturday.
Deflectors vs asteroids - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>deflectors vs asteroids</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <script src='https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5.1/dat.gui.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/stats.js/r16/Stats.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/seedrandom/2.4.2/seedrandom.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Deflectors vs asteroids - Script Codes JS Codes
/* my editor width */
/* if( you.read(code.bellow) && you.strenght != strong ) you.eye.setStatus(bleeding); ==== let's begin. ==== */
console.clear();
function reflect(a, v, f){ let isr = 1/(a[0]*a[0] + a[1]*a[1]) let x = (v[0] * a[0] + v[1] * a[1]) * f; let y = (v[1] * a[0] - v[0] * a[1]) * -1; return [ (x * a[0] - y * a[1]) * isr, (y * a[0] + x * a[1]) * isr, ];
}
function getCircleLineIntersect(c,cr, a,b){ let x = b[0]-a[0]; let y = b[1]-a[1]; let l = Math.sqrt(x*x+y*y); let nx = x/l; let ny = y/l; let cx0 = c[0] - a[0]; let cy0 = c[1] - a[1]; if(cx0*cx0+cy0*cy0 < cr*cr) return [a[0], a[1]]; let cx = cx0 * nx + cy0 * ny; let cy = cy0 * nx - cx0 * ny; if(Math.abs(cy) > cr) return null; let tx = cx - Math.sqrt( 1 - cy/cr*cy/cr ) * cr; if( Math.abs(tx) > l ) return null; return [ a[0] + tx * nx, a[1] + nx + tx * ny, ];
}
document.addEventListener('DOMContentLoaded', ()=>{ let canvas, ctx, w, h, vmin, vr, opts={}, gui, stats; let meteors, shields; function init(){ let t = Date.now(); opt('speed', 5, 1, 30).step(2); opt('size', 50, 10, 100).step(5); opt('maxMeteors', 10, 0, 50).step(1); opt('bounce', 4, 0.5, 10).step(0.5); opt('damageDivider', 1, 0.25, 20).step(0.25); opt('clear', 1, 0,1).step(0.01); opt('restart', start); opt('halt!', ()=> loop=()=>{} ); console.log('init time', Date.now()-t); start(); } function start(){ meteors = []; shields = []; shields.push({ pos: [0,h/2], size: vr, maxSize: vr, regen: 2, }); shields.push({ pos: [0,h/2], size: 0, maxSize: vr*0.9, regen: 2, }); shields.push({ pos: [0,h/2], size: 0, maxSize: vr*0.8, regen: 2, }); } function genMeteor(){ let meteor = { a: 0, aVel: (Math.random()-0.5)*2 * Math.PI/64, pos: [ (Math.random()-0.5) * w, 0, ], vel: [ 0, opts.speed*0.25 + opts.speed*0.75*Math.random(), ], color: `hsl(${200+Math.random()*60}, 30%, 30%)`, }; meteor.vel[0] = meteor.vel[1] * 0.25 * (Math.random()-0.5) meteor.size = opts.size*0.25 + opts.size*0.75*Math.random(); //meteor.size = 80 / Math.hypot(meteor.vel[0], meteor.vel[1]); meteor.pos[1] = -h/2 - meteor.size/2; meteors.push(meteor); } function shieldFunc(shield){ shield.size = Math.min(shield.maxSize, shield.size+shield.regen); if( shield.size < 0 ) return; ctx.beginPath(); ctx.strokeStyle = '#fff'; ctx.arc(shield.pos[0], shield.pos[1], shield.size/2, 0,Math.PI*2, 0); ctx.stroke(); for(let i=0; i<meteors.length; ++i){ let meteor = meteors[i]; let x = meteor.vel[0]; let y = meteor.vel[1]; let r = Math.hypot(x,y); x /= r; y /= r; x *= r + meteor.size/2; y *= r + meteor.size/2; let a = [ meteor.pos[0] + meteor.vel[0] / 2 - x, meteor.pos[1] + meteor.vel[1] / 2 - y, ]; let b = [ a[0] + x*2, a[1] + y*2, ]; let intersect = getCircleLineIntersect(shield.pos, shield.size/2, a, b); if( !intersect ){ let x = shield.pos[0] - meteor.pos[0]; let y = shield.pos[1] - meteor.pos[1]; let r = Math.hypot(x,y); if(r < (shield.size + meteor.size) / 2){ intersect = [ shield.pos[0] - x / r * shield.size / 2, shield.pos[1] - y / r * shield.size / 2, ]; } } if( intersect ){ ctx.fillStyle = '#f00'; ctx.beginPath(); ctx.arc(intersect[0], intersect[1], meteor.size/2*1.5, 0,Math.PI*2,0); ctx.fill(); shield.size -= meteor.size * Math.hypot(meteor.vel[0], meteor.vel[1]) / opts.damageDivider; //meteors.splice(i--, 1); let x = shield.pos[0] - meteor.pos[0]; let y = shield.pos[1] - meteor.pos[1]; let r2 = Math.hypot(x,y); meteor.vel = reflect([y/r2,-x/r2], meteor.vel, 1); meteor.pos[0] = intersect[0] + meteor.vel[0] / r * (meteor.size+1); meteor.pos[1] = intersect[1] + meteor.vel[1] / r * (meteor.size+1); if( shield.size < 0 ) return; break; } } } function loop(){ stats.begin(); ctx.fillStyle = `rgba(0,0,0, ${Math.pow(opts.clear,2)})`; ctx.fillRect(0,0, w,h); ctx.save(); ctx.translate(w/2>>0, h/2>>0); while(meteors.length < opts.maxMeteors) genMeteor(); for(let i=0; i<meteors.length; ++i){ let meteor = meteors[i]; if( meteor.pos[1]-meteor.size/2 > h/2 || meteor.pos[1]+meteor.size/2 < -h/2 || meteor.pos[0]-meteor.size/2 > w/2 || meteor.pos[0]+meteor.size/2 < -w/2 ){ meteors.splice(i--, 1); continue; } ctx.fillStyle = meteor.color; ctx.beginPath(); ctx.arc( meteor.pos[0], meteor.pos[1], meteor.size/2, meteor.a, Math.PI*1.5+meteor.a, 0 ); ctx.fill(); ctx.strokeStyle = '#000'; ctx.closePath(); ctx.stroke(); meteor.a += meteor.aVel; meteor.pos[0] += meteor.vel[0]; meteor.pos[1] += meteor.vel[1]; } for(let shield of shields) shieldFunc(shield); ctx.restore(); requestAnimationFrame(loop); stats.end(); } stats = new Stats(); stats.showPanel( 0 ); stats.domElement.style.position = 'absolute'; document.body.appendChild( stats.domElement ); //let panel = stats.addPanel( new Stats.Panel( 'caption', '#ff8', '#221' ) ); // panel.update(value, maxValue); /* i love DOM */ canvas = document.createElement('canvas'); document.body.appendChild(canvas); document.body.style.padding = '0px'; document.body.style.margin = '0px'; document.body.style.overflow = 'hidden'; /* i love full screen */ function resize(){ w = canvas.width = window.innerWidth; h = canvas.height = window.innerHeight; vmin = Math.min(w,h); vr = vmin / 2; } resize(); window.addEventListener('resize', resize, false); ctx = canvas.getContext('2d'); ctx.translate(0.5, 0.5); /* i love bad short opts ^__^ like q or qwe */ gui = new dat.GUI(); function opt(name, value, min, max){ opts[name] = value; return gui.add(opts, name, min, max); } // i make it for you... init(); loop();
}, false);
Developer | Findoff |
Username | findoff |
Uploaded | December 17, 2022 |
Rating | 3.5 |
Size | 3,565 Kb |
Views | 6,072 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Through penises... | 2,057 Kb |
A Pen by findoff | 2,637 Kb |
Screeps body calculator | 6,315 Kb |
Elementary cellular automaton | 2,685 Kb |
Linear-feedback shift register | 3,009 Kb |
Insect builder v0 | 3,425 Kb |
Ant | 2,365 Kb |
Small orbitals | 2,218 Kb |
Lightning | 2,284 Kb |
Let it snow | 2,600 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Flower expansion | Sreucherand | 3,425 Kb |
Caputre Cam with JS | KimmoCommit | 2,795 Kb |
Spilled Paint | Darrylhuffman | 3,894 Kb |
Highbrow Basic HTML Lesson 7 | Kimlarocca | 1,662 Kb |
Simple Login Form | JoshBlackwood | 4,418 Kb |
Easing | GreenSock | 2,043 Kb |
Scroll Arrow | Robooneus | 4,437 Kb |
Animated skewed panes | NyX | 4,462 Kb |
About Mazano | Kiti | 2,585 Kb |
Sitemap generator for Sharepoint | Gyusza | 2,518 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!