F10:warp
How do I make an f10:warp?
Codevember Day 16. Warped circles.. What is a f10:warp? How do you make a f10:warp? This script and codes were developed by Satchmorun on 28 August 2022, Sunday.
F10:warp - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>f10:warp</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="canvas"></canvas> <script src="js/index.js"></script>
</body>
</html>
F10:warp - Script Codes CSS Codes
body { margin: 0; padding: 0; overflow: hidden;
}
F10:warp - Script Codes JS Codes
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
'floor|random|round|abs|sqrt|PI|atan2|sin|cos|pow|max|min|hypot' .split('|') .forEach(function(p) { window[p] = Math[p]; });
var TAU = PI*2;
function r(n) { return random()*n; }
function rrng(lo, hi) { return lo + r(hi-lo); }
function rint(lo, hi) { return lo + floor(r(hi - lo + 1)); }
function choose(args) { return args[rint(0, args.length-1)]; }
/*---------------------------------------------------------------------------*/
var W, H, frame, time, DPR;
function dpr(n) { return DPR*n; }
function resize() { var w = innerWidth; var h = innerHeight; DPR = 2; canvas.style.width = w+'px'; canvas.style.height = h+'px'; W = canvas.width = w * DPR; H = canvas.height = h * DPR;
}
function loop(t) { frame = requestAnimationFrame(loop); draw(); time++;
}
function pause() { cancelAnimationFrame(frame); frame = frame ? null : requestAnimationFrame(loop);
}
function reset() { cancelAnimationFrame(frame); resize(); ctx.clearRect(0, 0, W, H); init(); time = 0; frame = requestAnimationFrame(loop);
}
/*---------------------------------------------------------------------------*/
function Vector(x, y) { this.x = x; this.y = y;
}
Vector.add = function(a, b) { return new Vector(a.x + b.x, a.y + b.y); };
Vector.sub = function(a, b) { return new Vector(a.x - b.x, a.y - b.y); };
Vector.mul = function(a, n) { return new Vector(a.x * n, a.y * n); };
Vector.div = function(a, n) { return new Vector(a.x / n, a.y / n); };
Vector.prototype.clone = function() { return new Vector(this.x, this.y);
};
Vector.prototype.add = function(other) { this.x += other.x; this.y += other.y; return this;
};
Vector.prototype.sub = function(other) { this.x -= other.x; this.y -= other.y; return this;
};
Vector.prototype.mul = function(n) { this.x *= n; this.y *= n; return this;
};
Vector.prototype.div = function(n) { this.x /= n; this.y /= n; return this;
};
Vector.prototype.mag = function() { var x = this.x, y = this.y; return sqrt(x*x + y*y);
};
Vector.prototype.normalize = function() { return this.div(this.mag());
};
Vector.prototype.constrain = function(n) { var m = this.mag(); return m > n ? this.mul(n/m) : this;
};
Vector.prototype.zero = function() { this.x = 0; this.y = 0;
};
Vector.prototype.rotate = function(angle) { var c = cos(angle); var s = sin(angle); var x = this.x; var y = this.y; this.x = x*c - y*s; this.y = x*s + y*c; return this;
};
function vec(x, y) { return new Vector(x, y);
}
/*---------------------------------------------------------------------------*/
function Particle(loc) { this.loc = loc; this.lifespan = rint(60, 300); this.ticks = this.lifespan; this.acc = vec(0, 0);
}
Particle.prototype.follow = function(field) { this.checkBounds(); this.acc.add(field.forceAt(this.loc));
};
Particle.prototype.trace = function(draw) { ctx.moveTo(this.loc.x, this.loc.y); this.move(); ctx.lineTo(this.loc.x, this.loc.y);
};
Particle.prototype.move = function(field) { this.loc.add(this.acc); this.acc.zero(); this.ticks++;
};
Particle.prototype.checkBounds = function() { if (this.loc.x < L || this.loc.y < T || this.loc.x > R || this.loc.y > B) { this.loc.x = rrng(L, R); this.loc.y = rrng(T, B); this.ticks = 0; }
};
/*---------------------------------------------------------------------------*/
function Gravitron(loc, mass, attract) { this.loc = loc; this.mass = mass; this.attract = !!attract;
}
/*---------------------------------------------------------------------------*/
function Field(x, y, w, h, res) { this.x = x; this.y = y; this.w = w; this.h = h; this.res = res; this.imax = ~~(w/res); this.jmax = ~~(h/res); this.forces = []; var nn = dpr(100); for (var i = 0; i <= this.imax; i++) { this.forces[i] = []; var xx = x + i*res + res/2; for (var j = 0; j <= this.jmax; j++) { var yy = y + j*res + res/2; var cxx = x + floor((xx-x)/nn)*nn + nn/2; var cyy = y + floor((yy-y)/nn)*nn + nn/2; var v = vec(cxx-xx, cyy-yy).rotate(TAU/4).normalize().mul(dpr(1)); this.forces[i][j] = v; } }
}
Field.prototype.draw = function() { var res = this.res; for (var i = 0; i <= this.imax; i++) { var xx = this.x + i*res + res/2; for (var j = 0; j <= this.jmax; j++) { var yy = this.y + j*res + res/2; var v = Vector.mul(this.forces[i][j], dpr(10)); ctx.fillStyle = 'black'; ctx.fillRect(xx-3, yy-3, 6, 6); ctx.beginPath(); ctx.moveTo(xx, yy); ctx.lineTo(xx + v.x, yy + v.y); ctx.stroke(); } }
};
Field.prototype.forceAt = function(v) { var i = ~~((v.x - this.x) / this.res); var j = ~~((v.y - this.y) / this.res); return this.forces[i][j];
};
Field.prototype.zero = function() { for (var i = 0; i <= this.imax; i++) { for (var j = 0; j <= this.jmax; j++) { this.forces[i][j] = vec(0, 0); } }
};
Field.prototype.addGravitron = function(g) { for (var i = 0; i <= this.imax; i++) { for (var j = 0; j <= this.jmax; j++) { var x = this.x + this.res*i + this.res/2; var y = this.y + this.res*j + this.res/2; var d = sqrt((x-g.loc.x)*(x-g.loc.x) + (y-g.loc.y)*(y-g.loc.y)); if (d < dpr(1)) continue; //if (d > g.mass) continue; var f = g.attract ? vec(g.loc.x-x, g.loc.y-y) : vec(x-g.loc.x, y-g.loc.y); f.normalize().mul(g.mass/d); this.forces[i][j].add(f); } }
};
Field.prototype.addGravitrons = function(gravitrons) { for (var i = 0; i < gravitrons.length; i++) { this.addGravitron(gravitrons[i]); }
};
Field.prototype.rotation = 0;
Field.prototype.cos = cos(0);
Field.prototype.sin = sin(0);
Field.prototype.scale = 0.2;
Field.prototype.rotateTo = function(angle) { this.rotation = angle; this.cos = cos(angle); this.sin = sin(angle);
};
Field.prototype.scaleBy = function(scale) { this.scale = lerp(0.2, 4, scale);
};
function lerp(a, b, n) { return a + (b-a)*n;
}
Field.prototype.rotate = function(angle) { for (var i = 0; i <= this.imax; i++) { for (var j = 0; j <= this.jmax; j++) { this.forces[i][j].rotate(angle); } }
};
Field.prototype.flip = function() { for (var i = 0; i <= this.imax; i++) { for (var j = 0; j <= this.jmax; j++) { this.forces[i][j].mul(-1); } }
};
/*---------------------------------------------------------------------------*/
var P, particles;
var L, R;
var field;
var G, gravitrons;
var cx, cy;
var ww, hh;
function init() { var n = floor((min(W/2, H/2) / dpr(50)) - 2) * dpr(50); cx = W/2; cy = H/2; L = cx-n; R = cx+n; T = cy-n; B = cy+n; ww = R-L; hh = B-T; var i, j, k; P = min(pow(n/dpr(50), 2)*300, 20000); particles = new Array(p); var t, p; for (i = 0; i < P; i++) { p = new Particle( vec(rrng(L, R), rrng(T, B)) ); particles[i] = p; } P = particles.length; gravitrons = [ ]; var threshold = rrng(0.25, 0.75); var grid = dpr(2); var mass = rrng(dpr(2), dpr(8)); for (i = 0; i < ww/4; i++) { var x = rrng(L, R); var y = rrng(T, B); gravitrons.push(new Gravitron(vec(x, y), mass, r(1) < threshold)); } G = gravitrons.length; field = new Field(L, T, R-L, B-T, grid); field.addGravitrons(gravitrons); drawFrame(grid, mass, threshold); ctx.strokeStyle = black; ctx.fillStyle = white;
}
function drawFrame(grid, mass, threshold) { ctx.save(); var outer = dpr(50); var inner = dpr(45); ctx.fillStyle = 'white'; ctx.fillRect(0, 0, W, H); ctx.fillStyle = 'black'; ctx.fillRect(L - outer, T - outer, 2*outer + R - L, 2*outer + B - T); ctx.fillStyle = 'white'; ctx.fillRect(L - inner, T - inner, 2*inner + R - L, 2*inner + B - T); ctx.fillStyle = 'black'; ctx.font = 'bold '+ dpr(25) +'px Courier'; ctx.fillText('f10', L - outer, T - outer - dpr(6)); ctx.textAlign = 'right'; ctx.fillText(threshold.toPrecision(3)+','+(mass/DPR).toPrecision(4), R + outer, T - outer - dpr(6)); ctx.restore();
}
function drawProgress(t) { var outer = dpr(50); ctx.save(); ctx.fillStyle = 'black'; ctx.fillRect(L-outer, B+outer+dpr(5), t*(R-L + 2*outer), dpr(5)); ctx.restore();
}
var black = 'rgba(0, 0, 0, 0.1)';
var white = 'rgba(255, 255, 255, 0.1)';
var rot = 0;
function draw() { var i, p; var duration = floor(ww/3); if (time && time % duration === 0) { reset(); } drawProgress(time/duration); ctx.beginPath(); for (i = 0; i < P; i++) { p = particles[i]; p.follow(field); p.trace(); } ctx.stroke();
}
/*---------------------------------------------------------------------------*/
window.onclick = pause;
window.ondblclick = reset;
reset();
Developer | Satchmorun |
Username | satchmorun |
Uploaded | August 28, 2022 |
Rating | 3.5 |
Size | 4,032 Kb |
Views | 18,216 |
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 |
Mess | 3,472 Kb |
Grid 3 | 3,411 Kb |
A Sliding Record Of Our Time Together | 2,558 Kb |
A Gooey Cursor | 2,553 Kb |
A Study in Red | 2,765 Kb |
Network 3 | 3,896 Kb |
Colorful Wanderers | 3,142 Kb |
Signals. | 2,515 Kb |
Network 2 | 3,115 Kb |
Lines 5 | 2,658 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 |
Twinner Spinner II | Katydecorah | 2,974 Kb |
Elephants Full screen site | Orrinward | 3,981 Kb |
Price table | Serluk | 5,928 Kb |
Mario | Takaneichinose | 3,902 Kb |
Responsive Pricing Table | Jeremycaris | 2,690 Kb |
Material design buttons | Fischaela | 4,381 Kb |
Smoke Shader - Frame Buffer | Omarshe7ta | 2,672 Kb |
CSS Parent Selector | Tomhodgins | 2,143 Kb |
Flexbox playground | Enxaneta | 5,418 Kb |
CSS Colors | Alexpate | 2,232 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!