Sierpinski
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 - 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);
};
Developer | Takashi |
Username | tksiiii |
Uploaded | October 20, 2022 |
Rating | 3 |
Size | 3,208 Kb |
Views | 10,120 |
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 |
Wave2D | 4,772 Kb |
Floating circle particle | 2,698 Kb |
Magic circle1 | 3,558 Kb |
Mosaic Pixel Effect | 358,869 Kb |
Glittering particle | 2,058 Kb |
Colorful 2D particle attractor | 2,841 Kb |
Rose curve animation | 2,083 Kb |
Polar Rose Generator | 5,055 Kb |
SplitShiftEffect | 6,607 Kb |
Lines circle | 1,959 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 |
Animated bar chart | CreativePunch | 3,124 Kb |
Portfolio Page | KaylaMT | 1,983 Kb |
Responsive Advert | James_zedd | 2,354 Kb |
Collapsing Widget | Er40 | 4,279 Kb |
Mobile first social buttons with no iframe | Alistairtweedie | 3,158 Kb |
Mapbox Directions with geolocation tracking | Pollardld | 5,827 Kb |
Chuck Norris Background | Manz | 1,967 Kb |
Buttons with style | Chbymnky | 2,082 Kb |
AngularJS Skills | Supro | 3,312 Kb |
Use the Twitchtv JSON API | Roksanaop | 3,561 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!