aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfaiface <faiface2202@gmail.com>2019-05-06 18:44:54 +0200
committerfaiface <faiface2202@gmail.com>2019-05-06 18:44:54 +0200
commit8a67ed9e640b830d307bfa56d7f445673cc576ed (patch)
treeed69819b6ff49ba5ba6b589d7136c45501b6a5e2
parenteb2426aae90421f4ca6940b623a7f94d73b8662f (diff)
downloadgui-8a67ed9e640b830d307bfa56d7f445673cc576ed.zip
examples: add READMEs for the ramaining examples
-rw-r--r--examples/imageviewer/README.md2
-rw-r--r--examples/paint/README.md9
-rw-r--r--examples/paint/screenshot.pngbin0 -> 39552 bytes
-rw-r--r--examples/pexeso/README.md31
-rw-r--r--examples/pexeso/screenshot.pngbin0 -> 5206 bytes
5 files changed, 42 insertions, 0 deletions
diff --git a/examples/imageviewer/README.md b/examples/imageviewer/README.md
index c0cc189..45062c2 100644
--- a/examples/imageviewer/README.md
+++ b/examples/imageviewer/README.md
@@ -15,3 +15,5 @@ The file browser accepts messages from the `cd` channel of type `chan string`. T
The viewer element accepts messages from the `view` channel of type `chan string`. When you click two times on a file in the file browser, the browser sends the file name to the viewer over this channel. The viewer will attempt to open and decode the file and shows the image if it succeeds. Otherwise it shows text _'Invalid image'_.
The most visible advantage of the concurrent approach here is that when the image takes longer to load, the rest of the UI remains responsive. Another, subtler advantage is that each element is self-contained, implemented using simple loops. The program should therefore be easy to understand and extend (the only barrier to understanding could be that I wrote it over an evening, but I'll try and make the code cleaner over time).
+
+Uses [golang.org/x/image/font](https://godoc.org/golang.org/x/image/font) for drawing text.
diff --git a/examples/paint/README.md b/examples/paint/README.md
new file mode 100644
index 0000000..c02047d
--- /dev/null
+++ b/examples/paint/README.md
@@ -0,0 +1,9 @@
+# Paint
+
+This is a simple paint program. Pick colors on the right, draw on the rest.
+
+![Screenshot](screenshot.png)
+
+The canvas in the middle is controlled by a goroutine. Each of the 8 color pickers is also controlled by its own goroutine. When clicked, the color picker sends its color to the canvas over a channel. The canvas listens on the channel and changes its color.
+
+Uses [`fogleman/gg`](https://github.com/fogleman/gg) for drawing lines.
diff --git a/examples/paint/screenshot.png b/examples/paint/screenshot.png
new file mode 100644
index 0000000..34b4889
--- /dev/null
+++ b/examples/paint/screenshot.png
Binary files differ
diff --git a/examples/pexeso/README.md b/examples/pexeso/README.md
new file mode 100644
index 0000000..03288ba
--- /dev/null
+++ b/examples/pexeso/README.md
@@ -0,0 +1,31 @@
+# Pexeso
+
+The [game of pairs](https://en.wikipedia.org/wiki/Concentration_(card_game)), also know as _concentration_, _match match_, or _pexeso_. This one has an extraordinarily beautiful concurrent solution.
+
+![Screenshot](screenshot.png)
+
+The game proceeds like this: You click one card, it turns around. Then you click another card. If the two have the same color, then remain turned. Otherwise, they turn back and you don't see their color. The objective is to turn all the cards.
+
+The concurrent implementation of this game is very neat.
+
+Each card is controlled by a separate goroutine. All cards know a common channel called `pair`. They can both send and receive on this channel. It has type `chan PairMsg`.
+
+```go
+type PairMsg struct {
+ Color color.Color
+ Resp chan<- bool
+}
+```
+
+When you click a card, it sends its a `PairMsg` with its color to the `pair` channel. When you click the next card, it receives the message from the `pair` channel, compares the colors and sends `true` to the `Resp` channel if they are the same, otherwise it sends `false`. Then both cards know if they matched or not and will either turn back or stay face up.
+
+A card doesn't know if it's the first or the second one clicked, it simply uses the `select` statement to either send a message or receive it. Then, when two cards are both selecting on the channel, one of them will end up sending and the other one receiving.
+
+Another nice thing about this concurrent implementation is that animations are done using simple for-loops:
+
+```go
+for c := 32; c >= 0; c-- {
+ env.Draw() <- redraw(float64(c) / 32)
+ time.Sleep(time.Second / 32 / 4)
+}
+```
diff --git a/examples/pexeso/screenshot.png b/examples/pexeso/screenshot.png
new file mode 100644
index 0000000..7ffd406
--- /dev/null
+++ b/examples/pexeso/screenshot.png
Binary files differ