lout-users
[Top][All Lists]

## Triangle spiral (Was: Margin kerning, inter-sentence spacing and drawing

 From: Valeriy E. Ushakov Subject: Triangle spiral (Was: Margin kerning, inter-sentence spacing and drawings) Date: Sat, 14 Jul 2012 03:39:47 +0400 User-agent: Mutt/1.4.2.3i

```On Fri, Jul 13, 2012 at 17:41:22 +0200, Matej Nanut wrote:

> 3. Is it possible to do something like this:
> "http://www.texample.net/tikz/examples/rotated-triangle/"; in Lout? The
> first problem I come accross is how to implement addition (like +10)
> cleanly.

I guess the following quick hack would be a good start.  Adding color
gradient is left as an exercise :)

import @Geometry @Diag
def @TriangleSpiral
right count
{
# a bit of syntactic sugar
def @PointOn
named from {}
named to {}
named at {}
{
from ** { 1 - at } ++ to ** at
}

def @NestedTriangle
body @Body
{
@Node
outline {
# XXX: cannot define Pi directly because of shadowing (think
# LET* vs LET), so local P1 would shadow container's P1 and mess
# up location of local P3
MYP1:: @PointOn from { P1 } to { P2 } at { 0.85 }
MYP2:: @PointOn from { P2 } to { P3 } at { 0.85 }
MYP3:: @PointOn from { P3 } to { P1 } at { 0.85 }

# give them desired names
P1:: MYP1 P2:: MYP2 P3:: MYP3

# define the path
P1 P2 P3 P1
}
{ @Body }
}

def @RepeatNestedTriangles
right i
{
@NestedTriangle {
i @Case {
count @Yield @Null
else  @Yield @RepeatNestedTriangles @Next i
}
}
}

@Polygon {
"12c" @Wide {} //0io

# we start at "2" b/c this initial polygon is "1"
@RepeatNestedTriangles 2
}
}

To test:

@Doc @Text @Begin
//4c
@Diag { @TriangleSpiral 15 }
@End @Text

A bit of a wart here is that @Polygon produces a triangle that is
actually smaller than the total object width, you can see it in the
User's Guide example (Section 9.12 "Summary").  @Isosceles makes the
base vertex of the right width, but you would need to compute the
hight manually and add some retagging to provide Pi tags referred by
the nested triangles.

Also, the //4c gap in the test is to accomodate the parts of the outer
triangle outside the object boundaries.  Again, @Isosceles should help
with this.

Note that "12c" needs to be quoted to avoid "c" from @Geometry.  More
hygienic imports (only @PointOn needs @Geometry) should solve this.

-uwe

```