# HP Prime for All

English  Русский
 Name Von Koch Fractals Description Generates Von Koch snowflake fractals. Author Damien Unknown

EXPORT VON_KOCH_SNOWFLAKES() `BEGIN ````LOCAL T2, T1, AA, LL, a, l, L0; LOCAL Xi, Yi, X1, Y1, X0, Y0; LOCAL XA, YA, XD, YD, A0, II; LOCAL x, y, NP; // Init parameters HAngle := 0; // RAD M := 3; N := 4; K := 5; // change K from 0 to 6 (or 7 if you are very very... patient) NP := 208; // Point coordinates of the starting curve x := {0, NP, NP/2, 0}; y := {√3/2*NP, √3/2*NP, 0, √3/2*NP}; // Model segments Length l := {1/3, 1/3, 1/3, 1/3}; // Segments angle with the horizontal a := {0, π/3, −π/3, 0}; // Black screen RECT_P(#383838h); // Main loop FOR II := 1 TO M DO // Calculate starting and ending point of segment number II XD := x(II); YD := y(II); XA := x(II+1); YA := y(II+1); X0 := XD; Y0 := YD; IF XA <> XD THEN A0 := ATAN((YA−YD) / (XA−XD)) ; ELSE A0 := π/2*SIGN(YA−YD); END; IF (XA−XD) < 0 THEN A0 := A0+π; END; L0 := √((XA−XD)² + (YA−YD)²); // Move the pen to its starting place Xi := IP(X0); Yi := IP(Y0); //secondary loop: each time it pass through, an elementary segment is plotted. FOR I := 0 TO N^K−1 DO // so there is N^K segments to draw (M time) LL := L0; AA := A0 ; T1 := I; IF K <> 0 THEN FOR J := K−1 DOWNTO 0 STEP 1 DO R := N^J; T2 := IP(T1/R); AA := AA+a(T2+1); // angle for segment number I LL := LL*l(T2+1); // length for segment number I T1 := T1−T2*R; END; // NEXT J END; // Time to draw X0 := X0+LL*COS(AA); Y0 := Y0+LL*SIN(AA); X1 := IP(X0); Y1 := IP(Y0); LINE_P(Xi, Yi, X1, Y1, RGB(240, 230, 0)); // orange Xi := X1; Yi := Y1; END; // NEXT I END; // NEXT II WAIT(-1); END; ```
``` Comments var disqus_shortname = 'hpprime'; var disqus_identifies = 'apps-graphics-koch'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); Please enable JavaScript to view the comments powered by Disqus. (adsbygoogle = window.adsbygoogle || []).push({}); (adsbygoogle = window.adsbygoogle || []).push({}); ```
``` ↑Back to top © 2017 Oleksandr Sidko — mail to site author var I18N = { 'Copied to clipboard': 'Copied to clipboard' }; !function(e,a,t,n,c,o,s){e.GoogleAnalyticsObject=c,e[c]=e[c]||function(){(e[c].q=e[c].q||[]).push(arguments)},e[c].l=1*new Date,o=a.createElement(t),s=a.getElementsByTagName(t)[0],o.async=1,o.src=n,s.parentNode.insertBefore(o,s)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-59274985-1","auto"),ga("send","pageview"); ```