+ 2
challenge for html or any graphical language : draw a szierpinski-star
Hi, https://scratch.mit.edu/projects/17914973/ is an easy fractal: find 5 points for a regular hexagon. begin at any point A choose a random point B, which is not neighbour to A. Stop on half the way to B and plot a mark Now start from the mark to any point not neighbour to B and mark on half the way... and so on. I would like to have it as animation on a website. or at least in any other language but scratch.
9 Réponses
+ 7
@Oma Falk wrote: << is an easy fractal >>
Only if principle was good described... but your explanation doesn't ^^
Anyway, have you at least implement your own, before telling that's << easy >>? Probably not, as you don't correctly explained the algorithm @@
However, there isn't a lot of explanation directly related on the Sierpinski fractal star on the web (appart the 'scratch' code link you've provided, but that's not at all a clear language for real programmers ;P), but almost about Sierpinski triangle... so implementing this algorithm is not obvious at all, even it's easy to do once you've got it clearly:
https://code.sololearn.com/WkfyQ4Box1fK/#js
+ 3
Since you've "scratched" that star, you can write correctly yourself the rules ^^
And anyway, I think that my previous answer deserve the 'best answer' mark ;P
+ 3
You doesn't explained anything, you've just posted a translation of the Turtle-like scratch code in Python using Turtle module: that's more readable than scratch code, but doesn't provide a proper description of the algoritm ^^
> Generalized Sierpinski Algorithm
Given a set of points P (five in our case):
Do:
+ Get p in P randomly as starting dot,
+ Get n randomly in subset S of P that are possible next points that can be choosen after p (given by the rule you explain in question description, BUT ITSELF INCLUDED -- ie 3 points in subset, not 2 as your question description let think),
+ Get the middle of [p,n] (or any dot in the segment) and trace it,
Until the count of wanted iterations is done...
Anyway, using turtle-like programming for that kind of geometrical draw is widely more easy than implementing it with other languages, where you have to implement the geometrical stuff needed (even if here, requirements are quite basic: drawing the middle of two points)... all the more to implement it << as animation on a website >> wich require to handle iterations with a setTimeout/setInterval() way ;P (by this way, my code display speed frequency is determinated by the time necessary to refresh the screen between each iteration/dot drawing: it could be accelerated -- and even be quite instantaneous if only displayed after all points generated, without timing methods -- by only refereshing display after a given count of generated dots ^^)
+ 2
This is an example for turtle graphics in Python
from turtle import *
import random
points = [(),(),(),(),()]
newpoints = {0:[2,3,0],1:[3,4,1],2:[4,0,2],3:[0,1,3],4:[1,2,4]}
penup()
SEITE = 200
for i in range(5):
points[i] = (xcor(),ycor())
left(72)
forward(SEITE)
oldPoint = 0
oldX,oldY = points[0]
for i in range(1000):
PointTo = random.choice(newpoints[oldPoint])
oldPoint = PointTo
toX , toY = points[PointTo]
newX, newY = (oldX + toX ) / 2,(oldY + toY)/2
oldX,oldY = newX,newY
goto(newX,newY)
dot(4,"red")
+ 2
if an algorithm is easy it is not said, that the program is easy. This are two very different things.
The set of points is not given. u have to calculate them to build a regular polygon.
Every Point has two neighbours. So three points are remaining. anyhow good idea to explicitly write this implication.
How much time did it take for you to write the javascript with which experience?
btw: ok your programm as answer is a top answer.
+ 1
@calvin
not exactly what I mean. there should be around 1000 marks(dots) which are plotted on half rhe way to the next vertex of the pentagon.
Anyhow.. svg ... yeah not so bad
+ 1
when I first saw a sierpinski triangle, i was excited.
i could not believe, that a few rules build that triangle.
So I began to play with the rules and "scratched" that star and some variations.
Since you obviously understood...
could you write down the rules?
+ 1
done :-)