Function to print a diamond shape
Ali Çehreli
acehreli at yahoo.com
Thu Mar 20 15:53:16 PDT 2014
On 03/20/2014 02:52 PM, Chris Williams wrote:
> On Thursday, 20 March 2014 at 21:25:03 UTC, Ali Çehreli wrote:
>> What interesting, boring, efficient, slow, etc. ways are there?
>>
>> Ali
>
> Well one of the more convoluted methods that I can think of would be to
> define a square as a set of four vectors, rotate 45 degrees, and then
> create a rasterizer that checks for the presence of the rect at
> sequential points, and plots those to the console.
A slightly convoluted solution that I've come up with considers the
diamond as three pieces:
1) Top triangle
2) The widest line
3) The bottom triangle, which happens to be the .retro of the first part
auto bottomHalf = topHalf.retro;
auto diamond = chain(topHalf, widestLine, bottomHalf).joiner("\n");
Ali
More information about the Digitalmars-d-learn
mailing list