Skip to content

Commit

Permalink
Implement ttile and utile
Browse files Browse the repository at this point in the history
  • Loading branch information
Ju Liu committed Mar 6, 2019
1 parent d71c168 commit 9b6cda4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
8 changes: 8 additions & 0 deletions lib/box.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ defmodule Box do
%Box{a: Vector.add(a, c), b: b, c: Vector.neg(c)}
end

def toss(%Box{a: a, b: b, c: c}) do
%Box{
a: Vector.add(a, Vector.scale(0.5, Vector.add(b, c))),
b: Vector.scale(0.5, Vector.add(b, c)),
c: Vector.scale(0.5, Vector.add(c, Vector.neg(b)))
}
end

def split_horizontally(factor, %Box{a: a, b: b, c: c}) do
above_ratio = factor

Expand Down
3 changes: 2 additions & 1 deletion lib/fitting.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ defmodule Fitting do
end

def get_stroke_width(%Box{b: b, c: c}) do
max(Vector.length(b), Vector.length(c)) / 100.0
ratio = max(Vector.length(b), Vector.length(c)) / 100.0
max(ratio, 1.0)
end

def create_picture(shapes, options \\ []) do
Expand Down
47 changes: 47 additions & 0 deletions lib/picture.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ defmodule Picture do
end
end

def toss(picture) do
fn box ->
box
|> Box.toss()
|> picture.()
end
end

def above_ratio(m, n, p1, p2) do
fn box ->
factor = m / (m + n)
Expand Down Expand Up @@ -68,4 +76,43 @@ defmodule Picture do
beside(p3, p4)
)
end

def over(p1, p2) do
fn box ->
p1.(box) ++ p2.(box)
end
end

def over(list) when is_list(list) do
fn box ->
Enum.flat_map(list, fn elem ->
elem.(box)
end)
end
end

def ttile(fish) do
fn box ->
side = fish |> toss |> flip

over([
fish,
side |> turn,
side |> turn |> turn
]).(box)
end
end

def utile(fish) do
fn box ->
side = fish |> toss |> flip

over([
side,
side |> turn,
side |> turn |> turn,
side |> turn |> turn |> turn
]).(box)
end
end
end
26 changes: 20 additions & 6 deletions lib/scenes/home.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,33 @@ defmodule ScenicEscher.Scene.Home do
fn g ->
box = %Box{
a: %Vector{x: 75.0, y: 75.0},
b: %Vector{x: 300.0, y: 0.0},
c: %Vector{x: 0.0, y: 300.0}
b: %Vector{x: 500.0, y: 0.0},
c: %Vector{x: 0.0, y: 500.0}
}

{width, height} = Box.dimensions(box)

fish =
Fitting.create_picture(
Fishy.fish_shapes(),
debug: true
Fishy.fish_shapes()
# debug: true
)

picture = fish
atom =
Picture.quartet(
Picture.ttile(fish),
Picture.ttile(fish) |> Picture.turn(),
Picture.ttile(fish) |> Picture.turn() |> Picture.turn() |> Picture.turn(),
Picture.ttile(fish) |> Picture.turn() |> Picture.turn()
)

picture =
Picture.quartet(
atom,
atom,
atom,
atom
)

paths =
box
Expand All @@ -38,7 +52,7 @@ defmodule ScenicEscher.Scene.Home do
|> path(elem, options)
end)
end,
translate: {20, 20}
translate: {20, 60}
)

def init(_, _) do
Expand Down

0 comments on commit 9b6cda4

Please sign in to comment.