Skip to content

Commit

Permalink
removed RenderGopherFrame impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronna Steinberg committed May 16, 2018
1 parent ff9c54d commit 509512c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 68 deletions.
17 changes: 5 additions & 12 deletions renderer/gopher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

// Gopher writes a new gif into w with delays of trackDuration normalized to
// the length so that the delay between frames is 10ms
// the length so that the delay between frames is the duration of the
// track divided by the length of points by 10ms
// for each element in points, call RenderGopherFrame
// append the returned frame (image) into gif.Image
// and append the the delay for the frame
Expand Down Expand Up @@ -36,17 +37,9 @@ func Gopher(w io.Writer, points []int, duration time.Duration, conf Config) {
// DrawRectangle:
// x1: 100-10/2 = 45, x2: x1+v=55
// y1: 120-10/2 = 55, y2: y1+v=65
// * hint: look at examples in the code to usage of
// image.NewPaletted and image.Rect
// * hint: look at examples in the code to see usages of
// image.NewPaletted and image.Rect(...)

func RenderGopherFrame(v int, width, height int, colorer Colorer) *image.Paletted {
rect := image.Rect(0, 0, width, height)
img := image.NewPaletted(rect, colorer.Palette())

x1 := (width - v) / 2
y1 := (height - v) / 2

DrawRectangle(img, (width-v)/2, (height-v)/2, x1+v, y1+v, v, colorer.Color)

return img
return nil
}
56 changes: 0 additions & 56 deletions renderer/gopher_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package renderer

import (
"bytes"
"fmt"
"image/color"
"image/gif"
"testing"
"time"
)

func TestRenderGopherFrame(t *testing.T) {
Expand Down Expand Up @@ -34,55 +30,3 @@ func TestRenderGopherFrame(t *testing.T) {
}
}
}
func TestGopher(t *testing.T) {
var b bytes.Buffer

h := 3
Gopher(&b, []int{0, 0, 1, 1}, time.Second, Config{Colorer: Colors["black"], Width: h, Height: h, Count: 4})

img, err := gif.DecodeAll(&b)
if err != nil {
t.Fatal("Decoding the retreived image was expected to succeed")
}

l := 4
if len(img.Delay) != l {
t.Fatalf("number of delayes was expected to be %d but got: %d", l, len(img.Delay))
}
d := 25
for i, v := range img.Delay {
if v != d {
t.Fatalf("delay %d returned %d but expected %d", i, v, d)
}
}

white := color.RGBA{255, 255, 255, 255}
black := color.RGBA{0, 0, 0, 255}

//First 2 frames - v = 0 - all white
for _, v := range img.Image[0:2] {
for i := 0; i < h; i++ {
if v.At(i, i) != white {
t.Fatalf("Unexpected color at (%d,%d) wanted white", i, i)
}
}
}

//Last 2 frames - v = 0 - 1 pixel in the middle must be black
for _, v := range img.Image[2:4] {
for i := 0; i < h; i++ {
if i == 1 {
if v.At(i, i) != black {
fmt.Println(i, i, v.At(i, i))
t.Fatalf("Unexpected color at (%d,%d) wanted white", i, i)
}
} else {
if v.At(i, i) != white {
fmt.Println(i, i, v.At(i, i))
t.Fatalf("Unexpected color at (%d,%d) wanted white", i, i)
}
}
}
}

}

0 comments on commit 509512c

Please sign in to comment.