func DrawTiger(gc draw2d.GraphicContext) { if postscriptContent == "" { src, err := os.OpenFile("../../resource/postscript/tiger.ps", 0, 0) if err != nil { fmt.Println("can't find postscript file.") return } defer src.Close() bytes, err := ioutil.ReadAll(src) postscriptContent = string(bytes) } interpreter := postscript.NewInterpreter(gc) reader := strings.NewReader(postscriptContent) interpreter.Execute(reader) }
func main() { i := image.NewRGBA(image.Rect(0, 0, 600, 800)) gc := draw2d.NewGraphicContext(i) gc.Translate(0, 380) gc.Scale(1, -1) gc.Translate(0, -380) src, err := os.OpenFile("../resource/postscript/tiger.ps", 0, 0) if err != nil { return } defer src.Close() bytes, err := ioutil.ReadAll(src) reader := strings.NewReader(string(bytes)) interpreter := postscript.NewInterpreter(gc) interpreter.Execute(reader) saveToPngFile("../resource/result/TestPostscript.png", i) }
func display() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.LineWidth(1) gc := draw2dgl.NewGraphicContext(width, height) gc.Translate(380, 400) gc.Scale(1, -1) rotate = (rotate + 1) % 360 gc.Rotate(float64(rotate) * math.Pi / 180) gc.Translate(-380, -400) interpreter := postscript.NewInterpreter(gc) reader := strings.NewReader(postscriptContent) lastTime := time.Now() interpreter.Execute(reader) dt := time.Now().Sub(lastTime) log.Printf("Redraw in : %f ms\n", float64(dt)*1e-6) gl.Flush() /* Single buffered, so needs a flush. */ glut.PostRedisplay() }