0
私はguide by Alan Donovanに従ってgifを作ろうとします。しかし、出力ではいつも私は読めないgifイメージを得ました。私はWindows 8.0を使用していたときにこの例を簡単に作り直すことができますが、今日はUbuntu16.04でどこでエラーが発生していたのか、どうやって解決するのか分かりません。私のコード:gifエラーをデバッグする方法
package main
import (
"image/color"
"os"
"io"
"math/rand"
"time"
"image/gif"
"image"
"math"
)
var palette = []color.Color{color.White, color.Black}
const (
whiteIndex = 0
blackIndex = 1
)
func main() {
lissajous(os.Stdout)
}
func lissajous(out io.Writer) {
const (
cycles = 5
res = 0.001
size = 100
nframes = 64
delay = 8
)
rand.Seed(time.Now().UTC().UnixNano())
freq := rand.Float64()*3.0
anim := gif.GIF{LoopCount:nframes}
phase := 0.0
for i := 0; i < nframes; i++ {
rect := image.Rect(0, 0, 2*size+1, 2*size+1)
img := image.NewPaletted(rect, palette)
for t:=0.0; t< cycles*2*math.Pi; t+= res {
x:= math.Sin(t)
y:= math.Sin(t*freq + phase)
img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), blackIndex)
}
phase += 0.2
anim.Delay = append(anim.Delay, delay)
anim.Image = append(anim.Image, img)
}
gif.EncodeAll(out, &anim)
}
ちょうど本からコピーしました。 '〜/ go/src/learning /'にあるソースファイル
これは判読不能なgifであることをどのように知っていますか?どのようにテストしていますか?どのようなエラーメッセージが表示されますか? – Flimzy
私の問題は、Webブラウザで開いて、ミラージュのようなプログラムを試してみたということでした... T_T –
あなたのコメントは私の質問に答えることはできません。どのようなエラーメッセージが表示されますか? – Flimzy