TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

A stochastic method to generate the Sierpinski triangle

110 点作者 wenderen超过 3 年前

28 条评论

klntsky超过 3 年前
I played with a similar approach a while ago. By changing the algorithm a bit it&#x27;s possible to create various other beautiful images:<p><a href="https:&#x2F;&#x2F;drive.google.com&#x2F;drive&#x2F;folders&#x2F;1TSgLRdO0tKIFUb6Oj8yNJgUeh2D_WA9-?usp=sharing" rel="nofollow">https:&#x2F;&#x2F;drive.google.com&#x2F;drive&#x2F;folders&#x2F;1TSgLRdO0tKIFUb6Oj8yN...</a><p>Here&#x27;s a link to my post (unfortunately, in Russian) describing the process: <a href="https:&#x2F;&#x2F;t.me&#x2F;little_pieces&#x2F;822?single" rel="nofollow">https:&#x2F;&#x2F;t.me&#x2F;little_pieces&#x2F;822?single</a><p>A quick translation:<p>1. We have a 2D space and a regular shape with N angles, where N is a parameter.<p>2. Choose a function f : R -&gt; R (e.g. f(x) = x &#x2F; 2 for Sierpinsky).<p>3. Choose a random &quot;current&quot; point<p>4. Choose a random angular point of the N-shape<p>5. Calculate the distance D between two points. Move the current point to the selected angle point by distance calculated as f(D).<p>6. Repeat steps 4-5, saving position of the current point on each step, until there is enough data to draw a density map<p>Another person from gen-club[0] (Russian telegram chat dedicated to generative art) made a 3D-version of it[1][2]:<p>[0] <a href="https:&#x2F;&#x2F;t.me&#x2F;gen_c" rel="nofollow">https:&#x2F;&#x2F;t.me&#x2F;gen_c</a><p>[1] <a href="https:&#x2F;&#x2F;t.me&#x2F;mathimages&#x2F;156" rel="nofollow">https:&#x2F;&#x2F;t.me&#x2F;mathimages&#x2F;156</a><p>[2] <a href="https:&#x2F;&#x2F;codepen.io&#x2F;strangerintheq&#x2F;full&#x2F;ZEKXamr" rel="nofollow">https:&#x2F;&#x2F;codepen.io&#x2F;strangerintheq&#x2F;full&#x2F;ZEKXamr</a> (zoom out at startup)
评论 #29703497 未加载
arutar超过 3 年前
Here&#x27;s a quick proof as to how it works. Suppose the triangle has endpoints (0,0), (1,0), and (1&#x2F;2, sqrt(3)&#x2F;2). Given a point (x,y), the three transformations then become<p>f1(x,y) = (x&#x2F;2, y&#x2F;2)<p>f2(x,y) = (x&#x2F;2+1&#x2F;2, y&#x2F;2)<p>f3(x,y) = (x&#x2F;2 + 1&#x2F;4, y&#x2F;2 + sqrt(3)&#x2F;4)<p>which are precisely the maps in the Iterated Function System [1] which generate the Sierpinsky triangle!<p>It&#x27;s a very nice observation that the three maps have a concise representation in terms of taking the midpoint with the given point and the vertices of the triangle.<p>[1] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Iterated_function_system" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Iterated_function_system</a>
评论 #29701980 未加载
评论 #29704046 未加载
评论 #29701948 未加载
user-the-name超过 3 年前
&quot;Pick a random vertex of the triangle and find its midpoint with p&quot; is actually &quot;Take the whole triangle, and scale it down to half size, and place it so that it shares a random vertex&quot;. This is the basic structure of the Sierpinski triangle, so repeating this process creates the fractal shape of the Sierpinski.
评论 #29701662 未加载
a_e_k超过 3 年前
I think this is basically the &quot;chaos game.&quot;<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Chaos_game" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Chaos_game</a>
评论 #29702774 未加载
frob超过 3 年前
I believe this is also the algorithm included in the TI-83 (plus) manual: <a href="https:&#x2F;&#x2F;www.manualowl.com&#x2F;m&#x2F;Texas%20Instruments&#x2F;TI-83-Plus&#x2F;Manual&#x2F;240607?page=573" rel="nofollow">https:&#x2F;&#x2F;www.manualowl.com&#x2F;m&#x2F;Texas%20Instruments&#x2F;TI-83-Plus&#x2F;M...</a><p>I remember sitting on the floor of our living room programming this in character by character on that TI keyboard. It&#x27;s the first BASIC program I ever wrote. Everything before that was js and html.
评论 #29704016 未加载
_archon_超过 3 年前
I thought I&#x27;d note that one of my favorite pages on the web pertains to exploring Sierpinski triangles [0]<p>&quot;The sierpinski triangle page to end most sierpinski triangle pages ™&quot;<p>[0]:<a href="http:&#x2F;&#x2F;www.oftenpaper.net&#x2F;sierpinski.htm" rel="nofollow">http:&#x2F;&#x2F;www.oftenpaper.net&#x2F;sierpinski.htm</a>
daneel_w超过 3 年前
The method presented by the author is the only method I&#x27;ve ever known. It was both simple enough for me to understand as a kid, and fast enough that I could plot the results within a minute using HiSoft BASIC on my Amiga 500.<p>Just to add the curiosum, the method as it was explained to me as a kid: &quot;Plot a pixel on any corner of the triangle. Pick a new corner on random and plot a pixel halfway between there and where your last pixel was, then just repeat.&quot;
评论 #29702484 未加载
评论 #29704120 未加载
pfedak超过 3 年前
As others have pointed out, a generalization of this method (iterated function systems) can generate a large class of fractals. There&#x27;s a some fun software for generating these ( see <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fractal_flame" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fractal_flame</a>) which also adds coloring based on the sequence of function applications, resulting in a pattern that respects the fractal structure.<p>Going a step further, changing the &quot;functions&quot; over time can create smoothly animated fractals. Electric Sheep (<a href="https:&#x2F;&#x2F;electricsheep.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;electricsheep.org&#x2F;</a>) is a screensaver version of this which doubles as a distributed computing network to generate them. It also mixes in non-linear transformations which makes for some impressive, mesmerizing patterns.
baliex超过 3 年前
You’ll find some more insight from Numberphile here, <a href="https:&#x2F;&#x2F;youtu.be&#x2F;kbKtFN71Lfs" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;kbKtFN71Lfs</a>
评论 #29701497 未加载
arunchaganty超过 3 年前
The chaos game is one of my favorite things! I first came across it nearly 15 years ago from James Gleick&#x27;s excellent book Chaos and in fact I learned how to program so that I could actually implement the chaos game.<p>After spending many years idly reflecting on why the chaos game converged to the Sierpinski triangle, I&#x27;d like to share an illustrated proof of mine that might be enjoyed by this audience: <a href="https:&#x2F;&#x2F;arun.chagantys.org&#x2F;technical&#x2F;2020&#x2F;04&#x2F;28&#x2F;chaos-game.html" rel="nofollow">https:&#x2F;&#x2F;arun.chagantys.org&#x2F;technical&#x2F;2020&#x2F;04&#x2F;28&#x2F;chaos-game.h...</a>
IngoBlechschmid超过 3 年前
Here is a version which can be played by up to three persons sharing a keyboard:<p><a href="https:&#x2F;&#x2F;www.speicherleck.de&#x2F;iblech&#x2F;stuff&#x2F;chaosspiel-2015&#x2F;chaosspiel.html" rel="nofollow">https:&#x2F;&#x2F;www.speicherleck.de&#x2F;iblech&#x2F;stuff&#x2F;chaosspiel-2015&#x2F;cha...</a><p>Developed as part of a mathematics day for children, the worksheet is available here: <a href="https:&#x2F;&#x2F;www.speicherleck.de&#x2F;iblech&#x2F;stuff&#x2F;chaosspiel-2015&#x2F;arbeitsblaetter.pdf" rel="nofollow">https:&#x2F;&#x2F;www.speicherleck.de&#x2F;iblech&#x2F;stuff&#x2F;chaosspiel-2015&#x2F;arb...</a>
paol超过 3 年前
This is how I learned to draw the Sierpinsky triangle, I don&#x27;t even know the analytical method. I got this method from fractint[0] I think, it had great docs explaining some of the fractal types. This was sometime in the mid 90&#x27;s.<p>[0] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fractint" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fractint</a><p>EDIT: Also, as a bonus this method is very easy to do with a pen and paper. I remember trying that, but it takes a lot of points before the structure starts to become visible.
评论 #29702016 未加载
londons_explore超过 3 年前
This is what got me into programming... I had fiddled with Print &quot;My Name Is Bob&quot; in an infinite loop, and decided that there was nothing interesting programming could do...<p>Then a relative wrote this algorithm in about 10 lines of qbasic. I was amazed that such simple code could do something so complex and unexpected. As a 5 yr old child, I spent hours trying to figure out how on earth this algorithm worked - even though it&#x27;s blatantly obvious to adult me.
Jyaif超过 3 年前
Kudos to whoever included it in the TI82&#x27;s manual, it successfully tickled my curiosity when I was a kid in the 90s and played a part in me becoming a programmer.<p><a href="https:&#x2F;&#x2F;www.manualslib.com&#x2F;manual&#x2F;325928&#x2F;Ti-Ti-82.html?page=202#manual" rel="nofollow">https:&#x2F;&#x2F;www.manualslib.com&#x2F;manual&#x2F;325928&#x2F;Ti-Ti-82.html?page=...</a>
aimor超过 3 年前
It&#x27;s funny, so each point is only guaranteed to be in that iteration of the triangle. So if you want a sierpinski triangle accurate to n levels deep you want to throw away the first n-1 points. If you want to plot a specific sierpinski triangle you have to re-run the algorithm from the beginning to get more points.
ralferoo超过 3 年前
This isn&#x27;t new. I first learned about Sierpinski triangles with this algortihm in the early 90s. Later, I learned how it can be generalised to IFS and opened my eyes to much more interesting examples. I think there&#x27;s even an entire chapter on this specific algorithm in Barnsley&#x27;s Fractals Everywhere book.
sizediterable超过 3 年前
I remember there being a section demonstrating this in the manual for my TI-83 calculator [0]<p>It prompted me to learn a bit more about IFS and discover one of my favorite fractals ever. The word &quot;chaos&quot; where each stroke is made up of the word &quot;chaos&quot; [1]. I spent a bunch of time coding up the fractals on that site [2] on my calculator<p>[0] <a href="http:&#x2F;&#x2F;manualsdump.com&#x2F;en&#x2F;manuals&#x2F;texas_instruments-ti-83&#x2F;132084&#x2F;573" rel="nofollow">http:&#x2F;&#x2F;manualsdump.com&#x2F;en&#x2F;manuals&#x2F;texas_instruments-ti-83&#x2F;13...</a><p>[1] <a href="http:&#x2F;&#x2F;paulbourke.net&#x2F;fractals&#x2F;ifs&#x2F;chaos_1.gif" rel="nofollow">http:&#x2F;&#x2F;paulbourke.net&#x2F;fractals&#x2F;ifs&#x2F;chaos_1.gif</a><p>[2] <a href="http:&#x2F;&#x2F;paulbourke.net&#x2F;fractals&#x2F;ifs&#x2F;" rel="nofollow">http:&#x2F;&#x2F;paulbourke.net&#x2F;fractals&#x2F;ifs&#x2F;</a>
Nydhal超过 3 年前
You can make it using Cellular Automata too.<p>Python Code:<a href="https:&#x2F;&#x2F;nbviewer.org&#x2F;github&#x2F;Nydhal&#x2F;Python-Notebooks&#x2F;blob&#x2F;master&#x2F;Selmi_Impossible_Fractal.ipynb" rel="nofollow">https:&#x2F;&#x2F;nbviewer.org&#x2F;github&#x2F;Nydhal&#x2F;Python-Notebooks&#x2F;blob&#x2F;mas...</a>
jankovicsandras超过 3 年前
Cool. Shameless plug:<p>Sierpinski carpet L-system<p>677 bytes will render a Sierpinski carpet using an L-system to create a Z-order curve :<p><a href="https:&#x2F;&#x2F;github.com&#x2F;jankovicsandras&#x2F;misc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jankovicsandras&#x2F;misc</a>
RonInDune超过 3 年前
The Sierpinski triangle was the first &quot;complex&quot; system I had managed to draw, using the Logo programming language in the 90s. I recently tried to do a vtk 3D extension (Sierpinski cube)[1] using the same process as in the OP, but it was surprisingly computationally expensive!<p>[1] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Menger_sponge" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Menger_sponge</a>
ArtWomb超过 3 年前
Love comp prob &amp; geom ;) Coolest part is the algo to generate uniform random points bounded within any triangle. I feel like its useful in loads of applications: FEM, monte carlo rendering, etc.<p><a href="https:&#x2F;&#x2F;blogs.sas.com&#x2F;content&#x2F;iml&#x2F;2020&#x2F;10&#x2F;19&#x2F;random-points-in-triangle.html" rel="nofollow">https:&#x2F;&#x2F;blogs.sas.com&#x2F;content&#x2F;iml&#x2F;2020&#x2F;10&#x2F;19&#x2F;random-points-i...</a>
jventura超过 3 年前
I did the same thing, but in Python, some years ago [1]. Never understood how it works, but it&#x27;s easy to implement..<p>[1] <a href="https:&#x2F;&#x2F;joaoventura.net&#x2F;blog&#x2F;2016&#x2F;sierpinski-triangle&#x2F;" rel="nofollow">https:&#x2F;&#x2F;joaoventura.net&#x2F;blog&#x2F;2016&#x2F;sierpinski-triangle&#x2F;</a>
rileyphone超过 3 年前
Also rule 90 tends to generate them from the nil seed - try clicking on the banner I made and set window size to something even and the seed to zero.<p><a href="https:&#x2F;&#x2F;rileystew.art&#x2F;posts&#x2F;banner" rel="nofollow">https:&#x2F;&#x2F;rileystew.art&#x2F;posts&#x2F;banner</a>
评论 #29701692 未加载
richm44超过 3 年前
Here&#x27;s a version of the same as a BBC Microbot tweet <a href="https:&#x2F;&#x2F;twitter.com&#x2F;bbcmicrobot&#x2F;status&#x2F;1333542986588753921" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;bbcmicrobot&#x2F;status&#x2F;1333542986588753921</a>
londons_explore超过 3 年前
Why it works:<p>Imagine what would be required to put a dot in an area that ought to be blank... The previous point would have had to have been outside the triangle, or in another blank area at the previous step.<p>Hence, it is impossible to draw in the blank areas.
评论 #29701939 未加载
RantyDave超过 3 年前
Could you write a function so that for point (x,y) it returns true if the point is &quot;in&quot; the spierpinski triangle? Yes, I am wondering if it could be expressed as a fragment shader :)
评论 #29702244 未加载
punnerud超过 3 年前
Video with here: <a href="https:&#x2F;&#x2F;imgur.com&#x2F;1Svgp0G" rel="nofollow">https:&#x2F;&#x2F;imgur.com&#x2F;1Svgp0G</a><p>(From the repo)
ssm008超过 3 年前
How lovely! I thoroughly enjoyed this