Sierpinski

Developer
Size
3,208 Kb
Views
10,120

How do I make an sierpinski?

I referred to the following site. 「Coding Math: Episode 35 - Intro to Fractals」https://youtu.be/bIfNwgUVjV8. What is a sierpinski? How do you make a sierpinski? This script and codes were developed by Takashi on 20 October 2022, Thursday.

Sierpinski Previews

Sierpinski - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>sierpinski</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.6/p5.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Sierpinski - Script Codes CSS Codes

html,body { margin: 0; padding: 0; overflow: hidden; }

Sierpinski - Script Codes JS Codes

"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Sierpinski = function () { function Sierpinski(_5, p0, p1, p2, limit) { _classCallCheck(this, Sierpinski); this._5 = _5; this.startPoints = { p0: p0, p1: p1, p2: p2 }; this.limit = limit; } Sierpinski.prototype.recursive = function recursive(p0, p1, p2, limit) { var pA = undefined, pB = undefined, pC = undefined; if (limit > 0) { pA = this._5.createVector(0, 0); pB = this._5.createVector(0, 0); pC = this._5.createVector(0, 0); pA.x = (p0.x + p1.x) / 2; pA.y = (p0.y + p1.y) / 2; pB.x = (p1.x + p2.x) / 2; pB.y = (p1.y + p2.y) / 2; pC.x = (p2.x + p0.x) / 2; pC.y = (p2.y + p0.y) / 2; this.recursive(p0, pA, pC, limit - 1); this.recursive(pA, p1, pB, limit - 1); this.recursive(pC, pB, p2, limit - 1); } else { this.drawTriangle(p0, p1, p2); } }; Sierpinski.prototype.drawTriangle = function drawTriangle(p0, p1, p2) { this._5.fill(0); this._5.beginShape(); this._5.vertex(p0.x, p0.y); this._5.vertex(p1.x, p1.y); this._5.vertex(p2.x, p2.y); this._5.endShape(this._5.CLOSE); }; Sierpinski.prototype.go = function go() { this.recursive(this.startPoints.p0, this.startPoints.p1, this.startPoints.p2, this.limit); }; return Sierpinski;
}();
window.onload = function () { var sketch = function sketch(_5) { var r = window.innerHeight / 2; var startPoints = { p0: _5.createVector(0, -r), p1: _5.createVector(_5.cos(_5.radians(30)) * r, _5.sin(_5.radians(30)) * r), p2: _5.createVector(_5.cos(_5.radians(150)) * r, _5.sin(_5.radians(150)) * r) }; var spsk = new Sierpinski(_5, startPoints.p0, startPoints.p1, startPoints.p2, 6); _5.setup = function () { // _5.frameRate(30); // _5.textSize(20); _5.createCanvas(window.innerWidth, window.innerHeight); _5.background(255); _5.noLoop(); }; _5.draw = function () { _5.background(255); _5.push(); _5.translate(window.innerWidth / 2, window.innerHeight / 2 + 40); spsk.go(); _5.pop(); //_5.text(_5.floor(_5.getFrameRate()), 20, 20); }; }; var _p5 = new p5(sketch);
};
Sierpinski - Script Codes
Sierpinski - Script Codes
Home Page Home
Developer Takashi
Username tksiiii
Uploaded October 20, 2022
Rating 3
Size 3,208 Kb
Views 10,120
Do you need developer help for Sierpinski?

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!

Takashi (tksiiii) Script Codes
Create amazing sales emails 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!