diff --git a/renderer/gopher.go b/renderer/gopher.go index ee6f911..8abc39b 100644 --- a/renderer/gopher.go +++ b/renderer/gopher.go @@ -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 @@ -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 } diff --git a/renderer/gopher_test.go b/renderer/gopher_test.go index d103fe3..d6f3d81 100644 --- a/renderer/gopher_test.go +++ b/renderer/gopher_test.go @@ -1,12 +1,8 @@ package renderer import ( - "bytes" - "fmt" "image/color" - "image/gif" "testing" - "time" ) func TestRenderGopherFrame(t *testing.T) { @@ -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) - } - } - } - } - -}