// Flocon de Koch - P5 - 250
void setup(){size(500,500);background(255);int d=9,h=5,i,k,m=1<3;i++){k=f(i%m);line(x,y,x+=kv.x,y+=kv.y);v.rotate(4k*PI/3.-PI);}} int f(int v){int c=0;while(v>0){c+=v&1;v>>=1;}return c%2;}
Inspiré par @Jean_no et @drst3f – Suite à ce tweet de Jean-Noël Lafargue j’ai tenté de reproduire le flocon de Koch en moins d’un tweet (280 caractères) avec Processing.
https://twitter.com/Jean_no/status/1353401387837763584
J’ai ainsi découvert la séquence de Thue–Morse qui permet de générer ce flocon en mode “tortue”. #logo
https://en.wikipedia.org/wiki/Thue%E2%80%93Morse_sequence
Quelques ruses plus tard, voici un flocon sur fond blanc en 250 caractères !
Voici le screenshot de Processing. Merci @Jean_no #koch #fractal #snowflake
// Koch snowflake with Processing in less than 280 chars
// Inspiration = https://twitter.com/Jean_no/status/1353401387837763584
// Thank you!!!
//
// Reading this: https://en.wikipedia.org/wiki/Koch_snowflake
// … led me to the Thue–Morse sequence:
// https://en.wikipedia.org/wiki/Thue%E2%80%93Morse_sequence
// … which led me to ideas here:
// http://blog.zacharyabel.com/2012/01/thue-morse-navigating-turtles/
//--> {1: (Step, Turn 60); 0: Turn 180}.
// … and I found a version of the generator that uses bitwise operators here:
// https://rosettacode.org/wiki/Thue-Morse#C
//
// Note: you can change d and h.
// d is the "depth" of the snowflake (number of iterations)
// and h is the length of the unit vector.
// d=9,h=5 -> this program
// d=7,h=15 or d=5,h=45 or d=3,h=135
// or d=1,h=405 -> Simple Triangle