English: von Koch snowflake curve after 6 steps (4,097 points); initially created with Scilab, transformed into SVG by pstoedit, layout by Inkscape. New version was created by a text editor.
Français : Courbe du flocon de neige de von Koch après 6 étapes (4,097 points) ; initialement créé avec Scilab, transformé en SVG avec pstoedit, mis en forme avec Inkscape. La nouvelle version a été faite avec un éditeur de texte.
This media was created with Scilab, a free open-source software.
Here is a listing of the Scilab source used to create this file.
English: English version by default.
Français : Version française, si les préférences de votre compte sont réglées (voir Special:Preferences).
Iterative source code
// ******************************// * *// * "Snowflake" von Koch curve *// * *// ******************************clear;clf;// **************// * constants *// **************n=6;// number of steps // limited to 9 (262 145 points), otherwise the stacksize must be changed// 6 steps (4 097 points) are enough for a good renderingN=4^n+1;// amount of pointssin_soixante=sqrt(3)/2;// sin(60°)l=1;// length of the initial line (arbitrary unit)// ******************// * initialisation *// ******************ycourbe=[zeros(1,N)];ycourbe1=ycourbe;// *************// * functions *// *************function[xx, yy] = etape(x, y)// from a line [(x(1),y(1)) ; (x(2),y(2))]// make the line [(xx(1),yy(1)) ; (xx(2),yy(2)) ; (xx(3),yy(3))]// x and y are 2-cells tables, the ends of the basis line// xx and yy are 3-cells tables// the edges of the equilateral trianglexu=(x(2)-x(1))/3;yu=(y(2)-y(1))/3;// third of the basis line vectorxv=0.5*xu-sin_soixante*yu;yv=sin_soixante*xu+0.5*yu;// vector turned by +60°xx(1)=x(1)+xu;yy(1)=y(1)+yu;xx(3)=x(2)-xu;yy(3)=y(2)-yu;xx(2)=xx(1)+xv;yy(2)=yy(1)+yv;endfunctionfunction[xkoch, ykoch] = vonkoch(x, y, n)// builds the curve// initialisationxkoch=x;ykoch=y;xkoch1=x;ykoch1=y;fori=1:njmax=4^(i-1);// number of lines at the beginning of the step iforj=1:jmax/2+1// we work with two points which indices are j and j+1 (line #j)// thanks t the symmetry, we work with a half curvedecalage=(j-1)*4;// the new points shift the next points by this offsetx_init=xkoch(j:j+1);y_init=ykoch(j:j+1);// line #j[x_trans,y_trans]=etape(x_init,y_init);// transformed linexkoch1(decalage+1)=x_init(1);xkoch1(decalage+5)=x_init(2);ykoch1(decalage+1)=y_init(1);ykoch1(decalage+5)=y_init(2);fork=1:3xkoch1(k+decalage+1)=x_trans(k);ykoch1(k+decalage+1)=y_trans(k);// values put in the global vectorendendxkoch=xkoch1;ykoch=ykoch1;endfori=1:4^nykoch(N-i+1)=ykoch(i);xkoch(N-i+1)=l-xkoch(i);// 2nd half-curveendendfunction// ****************// * main program *// ****************xcourbe(2)=l;[xcourbe,ycourbe]=vonkoch(xcourbe,ycourbe,n);// drawing the curvexpoly(xcourbe,ycourbe)isoview(0,l,0,l*sin_soixante/3)
The following code can be added to directly generate the file (the SVG export was not implemented at the time the file was created).
// saving the filename="von_koch_"+string(n)+"_steps.svg";xs2svg(0,name)
Recursive source code
The code is more compact but the execution is slower, and does not generate the table of values.
//============================================================================// name: von_koch.sce// author: Christophe Dang Ngoc Chan// date of creation: 2012-10-23// dates of modification: // 2013-07-08: quotes ' -> "// 2013-07-2: vectorisation of the calculations//----------------------------------------------------------------------------// version of Scilab: 5.3.1// required Atoms modules: aucun//----------------------------------------------------------------------------// Objective: draws the von Koch's "snowflake"// Inputs: none (parameters are hard coded)// Outputs: graphical window with a curve; SVG file//============================================================================clear;clf;// *************// * constants *// **************n=6;// number of steps // limited to 9 (262 145 points), otherwise the stacksize must be changed// 6 steps (4 097 points) are enough for a good renderingsin_soixante=sqrt(3)/2;// sin(60°)l=1;// length of the initial line (arbitrary unit)// ******************// * initialisation *// ******************// *************// * functions *// *************function[]=vonkoch(A, B, i)u=(B-A)/3;// third of the AB vectorv=[0.5*u(1)-sin_soixante*u(2);sin_soixante*u(1)+0.5*u(2)];// vector turned by +60°C=A+u;D=C+v;E=B-u;// points of the lineifi==1then// drawing the smallest segmentsx=[A(1);C(1);D(1);E(1);B(1)];y=[A(2);C(2);D(2);E(2);B(2)];xpoly(x,y,"lines")elsej=i-1;vonkoch(A,C,j);vonkoch(C,D,j);vonkoch(D,E,j);vonkoch(E,B,j);// recursive callendendfunction// ****************// * main program *// ****************beginning=[0;0];ending=[l;0];vonkoch(beginning,ending,n)isoview(0,l,0,sin_soixante*l)// Saving the filename="von_koch_"+string(n)+"_steps.svg";xs2svg(0,name)
Lizentzia
Nik, lan honen egileak, argitaratzen dut ondorengo lizentzia hauen pean:
Baimena duzu dokumentu hau kopiatu, banatu edo/eta aldatzeko GNU Free Documentation License baldintzapean, Free Software Foundationek argitaratutako 1.2 edo ondorengo bertsioan; sekzio aldaezinik gabe, azaleko testurik gabe, eta atzeko azaleko testurik gabe. Lizentziaren kopia dago GNU Free Documentation License izenburudun atalean.http://www.gnu.org/copyleft/fdl.htmlGFDLGNU Free Documentation Licensetruetrue
partekatzeko – lana kopiatzeko, banatzeko eta bidaltzeko
birnahasteko – lana moldatzeko
Ondorengo baldintzen pean:
eskuduntza – Egiletza behar bezala aitortu behar duzu, lizentzia ikusteko esteka gehitu, eta ea aldaketak egin diren aipatu. Era egokian egin behar duzu hori guztia, baina inola ere ez egileak zure lana edo zure erabilera babesten duela irudikatuz.
berdin partekatu – Lan honetan oinarrituta edo aldatuta berria eraikitzen baduzu, emaitza lana hau bezalako lizentzia batekin argitaratu behar duzu.
This licensing tag was added to this file as part of the GFDL licensing update.http://creativecommons.org/licenses/by-sa/3.0/CC BY-SA 3.0Creative Commons Attribution-Share Alike 3.0truetrue
Nahiago duzun lizentzia erabil dezakezu.
Irudi-oineko testuak
Add a one-line explanation of what this file represents
{{Information |Description= {{en|von Koch snow flake curve after 6 steps; created with Scilab, transformed into SVG by pstoedit, layout by Inkscape}} {{fr|Courbe du flocon de neige de von Koch après 6 étapes ; créé avec Scilab, transformé en SVG avec
Irudira dakarten loturak
Hurrengo orrialdeek dute fitxategi honetarako lotura:
Fitxategi honek informazio gehigarri dauka, ziurrenik kamera digital edo eskanerrak egiterako momentuan gehitutakoa. Hori dela-eta, jatorrizko fitxategi hori aldatu egin bada, baliteke xehetasun batzuek errealitatearekin bat ez egitea.