Superformula

Developer
Size
3,671 Kb
Views
40,480

How do I make an superformula?

See https://en.wikipedia.org/wiki/Superformula. What is a superformula? How do you make a superformula? This script and codes were developed by Aitor on 16 September 2022, Friday.

Superformula Previews

Superformula - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Superformula</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<canvas width="640" height="480"></canvas> <script src="js/index.js"></script>
</body>
</html>

Superformula - Script Codes CSS Codes

html,
body { background: #000; color: #fff; margin: 0; padding: 0; font-family: Lato, sans-serif;
}

Superformula - Script Codes JS Codes

"use strict";
// @see: https://en.wikipedia.org/wiki/Superformula
var canvas = document.querySelector("canvas"), context = canvas.getContext("2d");
var SCALE = 150;
var VALUES = [];
for (var index = 0; index < 30; index++) { VALUES.push(Math.random() * 20000 + 100);
}
function superformula(phi, a, b, m, n1, n2, n3) { return Math.pow(Math.pow(Math.abs(Math.cos(m * phi / 4) / a), n2) + Math.pow(Math.abs(Math.sin(m * phi / 4) / b), n3), -1 / n1);
}
function renderFormula(now, t1, t2, t3, i) { var s1 = now / t1; var s2 = now / t2; var s3 = now / t3; var a = Math.abs(Math.sin(s1)); var b = Math.abs(Math.sin(s1)); var m = Math.abs(Math.sin(s2) * 50); var n1 = Math.abs(Math.sin(s3) * 50); var n2 = Math.abs(Math.sin(s2) * 50); var n3 = Math.abs(Math.sin(s1) * 50); context.beginPath(); for (var index = 0; index < 360; index++) { var radius = superformula(index / 360 * Math.PI * 2, a, b, m, n1, n2, n3); var x = Math.cos(index / 360 * Math.PI * 2) * radius * SCALE; var y = Math.sin(index / 360 * Math.PI * 2) * radius * SCALE; if (index === 0) { context.moveTo(x, y); } else { context.lineTo(x, y); } } context.closePath(); context.globalCompositeOperation = "lighten"; context.shadowColor = "#0cf"; context.shadowBlur = 32; context.lineWidth = i; context.strokeStyle = "#fff"; context.stroke();
}
function update() {}
function render(now) { var s1 = now / 1000; var s2 = now / 250; var s3 = now / 500; var a = Math.abs(Math.sin(s1)); var b = Math.abs(Math.sin(s1)); var m = Math.abs(Math.sin(s2) * 50); var n1 = Math.abs(Math.sin(s3) * 50); var n2 = Math.abs(Math.sin(s2) * 50); var n3 = Math.abs(Math.sin(s1) * 50); context.clearRect(0, 0, canvas.width, canvas.height); context.save(); context.translate(canvas.width * 0.5, canvas.height * 0.5); for (var index = 0; index < VALUES.length; index += 3) { renderFormula(now, VALUES[index], VALUES[index + 1], VALUES[index + 2], index + 1); } context.restore();
}
function frame(now) { update(); render(now); window.requestAnimationFrame(frame);
}
function resize() { canvas.width = window.innerWidth; canvas.height = window.innerHeight;
}
window.requestAnimationFrame(frame);
window.addEventListener("resize", resize);
window.dispatchEvent(new Event("resize"));
Superformula - Script Codes
Superformula - Script Codes
Home Page Home
Developer Aitor
Username AzazelN28
Uploaded September 16, 2022
Rating 4
Size 3,671 Kb
Views 40,480
Do you need developer help for Superformula?

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!

Aitor (AzazelN28) Script Codes
Create amazing love letters with AI!

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!