-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ju Liu
committed
Mar 5, 2019
1 parent
cd0507d
commit e259ba4
Showing
4 changed files
with
150 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
defmodule Shape do | ||
defmodule Figure do | ||
def george do | ||
pts1 = [ | ||
%Vector{x: 0.00, y: 0.55}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
defmodule Picture do | ||
# A picture is a lambda function that takes a box and produces a list | ||
# of {shape, style} tuples. Think of it as something like this: | ||
# | ||
# picture = | ||
# fn box -> | ||
# render_stuff_with box | ||
# end | ||
# | ||
# The nice thing about this idea is that we can transform the picture | ||
# by just transforming the box. For example, if we want to turn the picture | ||
# we could just do something like: | ||
# | ||
# turned_picture = | ||
# fn box -> | ||
# box | ||
# |> Box.turn | ||
# |> picture.() | ||
# end | ||
|
||
def turn(picture) do | ||
fn box -> | ||
box | ||
|> Box.turn() | ||
|> picture.() | ||
end | ||
end | ||
|
||
def flip(picture) do | ||
fn box -> | ||
box | ||
|> Box.flip() | ||
|> picture.() | ||
end | ||
end | ||
|
||
def above_ratio(m, n, p1, p2) do | ||
fn box -> | ||
factor = m / (m + n) | ||
|
||
{box_above, box_below} = Box.split_horizontally(factor, box) | ||
|
||
p1.(box_above) ++ p2.(box_below) | ||
end | ||
end | ||
|
||
def above(p1, p2) do | ||
above_ratio(1, 1, p1, p2) | ||
end | ||
|
||
def beside_ratio(m, n, p1, p2) do | ||
fn box -> | ||
factor = m / (m + n) | ||
|
||
{box_left, box_right} = Box.split_vertically(factor, box) | ||
|
||
p1.(box_left) ++ p2.(box_right) | ||
end | ||
end | ||
|
||
def beside(p1, p2) do | ||
beside_ratio(1, 1, p1, p2) | ||
end | ||
|
||
def quartet(p1, p2, p3, p4) do | ||
above( | ||
beside(p1, p2), | ||
beside(p3, p4) | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters