Skip to main content
chars->bytes
Source Link
algmyr
  • 918
  • 4
  • 8

Asymptote, 152 charsbytes

I'll add this, mostly since I've seen more or less no answers in asymptote on this site. A few wasted bytes for nice formatting and generality, but I can live with that. Changing A,B and C will change where the corners of the containing triangle are, but probably not in the way you think. Increase the number in the inequality to increase the depth.

pair A=(0,0),B=(1,0),C=(.5,1);void f(pair p,int d){if(++d<7){p*=2;f(p+A*2,d);f(p+B*2,d);f(p+C*2,d);}else{fill(shift(p/2)*(A--B--C--cycle));}}f((0,0),0); 

or ungolfed and readable

pair A=(0,0), B=(1,0), C=(.5,1); void f(pair p, int d) { if (++d<7) { p *= 2; f(p+A*2,d); f(p+B*2,d); f(p+C*2,d); } else { fill(shift(p/2)*(A--B--C--cycle)); } } f((0,0),0); 

So asymptote is a neat vector graphics language with somewhat C-like syntax. Quite useful for somewhat technical diagrams. Output is of course in a vector format by default (eps, pdf, svg) but can be converted into basically everything imagemagick supports. Output:

Sierpinski triangle

Asymptote, 152 chars

I'll add this, mostly since I've seen more or less no answers in asymptote on this site. A few wasted bytes for nice formatting and generality, but I can live with that. Changing A,B and C will change where the corners of the containing triangle are, but probably not in the way you think. Increase the number in the inequality to increase the depth.

pair A=(0,0),B=(1,0),C=(.5,1);void f(pair p,int d){if(++d<7){p*=2;f(p+A*2,d);f(p+B*2,d);f(p+C*2,d);}else{fill(shift(p/2)*(A--B--C--cycle));}}f((0,0),0); 

or ungolfed and readable

pair A=(0,0), B=(1,0), C=(.5,1); void f(pair p, int d) { if (++d<7) { p *= 2; f(p+A*2,d); f(p+B*2,d); f(p+C*2,d); } else { fill(shift(p/2)*(A--B--C--cycle)); } } f((0,0),0); 

So asymptote is a neat vector graphics language with somewhat C-like syntax. Quite useful for somewhat technical diagrams. Output is of course in a vector format by default (eps, pdf, svg) but can be converted into basically everything imagemagick supports. Output:

Sierpinski triangle

Asymptote, 152 bytes

I'll add this, mostly since I've seen more or less no answers in asymptote on this site. A few wasted bytes for nice formatting and generality, but I can live with that. Changing A,B and C will change where the corners of the containing triangle are, but probably not in the way you think. Increase the number in the inequality to increase the depth.

pair A=(0,0),B=(1,0),C=(.5,1);void f(pair p,int d){if(++d<7){p*=2;f(p+A*2,d);f(p+B*2,d);f(p+C*2,d);}else{fill(shift(p/2)*(A--B--C--cycle));}}f((0,0),0); 

or ungolfed and readable

pair A=(0,0), B=(1,0), C=(.5,1); void f(pair p, int d) { if (++d<7) { p *= 2; f(p+A*2,d); f(p+B*2,d); f(p+C*2,d); } else { fill(shift(p/2)*(A--B--C--cycle)); } } f((0,0),0); 

So asymptote is a neat vector graphics language with somewhat C-like syntax. Quite useful for somewhat technical diagrams. Output is of course in a vector format by default (eps, pdf, svg) but can be converted into basically everything imagemagick supports. Output:

Sierpinski triangle

Source Link
algmyr
  • 918
  • 4
  • 8

Asymptote, 152 chars

I'll add this, mostly since I've seen more or less no answers in asymptote on this site. A few wasted bytes for nice formatting and generality, but I can live with that. Changing A,B and C will change where the corners of the containing triangle are, but probably not in the way you think. Increase the number in the inequality to increase the depth.

pair A=(0,0),B=(1,0),C=(.5,1);void f(pair p,int d){if(++d<7){p*=2;f(p+A*2,d);f(p+B*2,d);f(p+C*2,d);}else{fill(shift(p/2)*(A--B--C--cycle));}}f((0,0),0); 

or ungolfed and readable

pair A=(0,0), B=(1,0), C=(.5,1); void f(pair p, int d) { if (++d<7) { p *= 2; f(p+A*2,d); f(p+B*2,d); f(p+C*2,d); } else { fill(shift(p/2)*(A--B--C--cycle)); } } f((0,0),0); 

So asymptote is a neat vector graphics language with somewhat C-like syntax. Quite useful for somewhat technical diagrams. Output is of course in a vector format by default (eps, pdf, svg) but can be converted into basically everything imagemagick supports. Output:

Sierpinski triangle