From f0ca9f2ca922c9bd5587a2371b4ad1b81c404cb0 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 8 Jan 2017 19:20:51 +0100 Subject: Cleanup plotter --- main.go | 12 +++++------- patch.go | 10 ++++++---- tek.go | 16 +++++++++------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index 8e437c8..a6019d3 100644 --- a/main.go +++ b/main.go @@ -22,17 +22,15 @@ func main() { for u := 0.0; u <= 1.0; u += step { out.PenDown() for v := 0.0; v <= 1.0; v += step { - vertex := Calc(u, v, p) - x, y := vertex.Project() - out.Plot(x, y) + Calc(u, v, p).Project(out) } out.PenUp() + } + for v := 0.0; v <= 1.0; v += step { out.PenDown() - for v := 0.0; v <= 1.0; v += step { - vertex := Calc(v, u, p) - x, y := vertex.Project() - out.Plot(x, y) + for u := 0.0; u <= 1.0; u += step { + Calc(u, v, p).Project(out) } out.PenUp() } diff --git a/patch.go b/patch.go index 43ef277..7a72f98 100644 --- a/patch.go +++ b/patch.go @@ -63,13 +63,15 @@ func (v Vertex) Zoom(zoom float64) Vertex { return v } -func (v Vertex) Project() (int, int) { +func (v Vertex) Project(p Plotter) { dist := 100000.0 v = v.Zoom(1000).RotZ(-15).RotX(-60) + w, h := p.Dim() v.X *= dist / (2*dist - v.Z) v.Y *= dist / (2*dist - v.Z) - v.X += width / 2 - v.Y += height / 3 - return int(v.X), int(v.Y) + v.X += float64(w) / 2 + v.Y += float64(h) / 2 + + p.Plot(int(v.X), int(v.Y)) } diff --git a/tek.go b/tek.go index 34c3bb6..84adc65 100644 --- a/tek.go +++ b/tek.go @@ -5,15 +5,11 @@ import ( "os" ) -const ( - height = 3072 - width = 4096 -) - type Out struct { io.Writer hix, hiy, lox, loy, eb byte xterm bool + height, width int } func (o *Out) escString(s string) { @@ -29,6 +25,8 @@ func NewOut(w io.Writer) *Out { return &Out{ Writer: w, xterm: os.Getenv("TERM") == "xterm", + height: 3072, + width: 4096, } } @@ -64,9 +62,13 @@ func limit(val, max int) int { return val } +func (o *Out) Dim() (w, h int) { + return o.width, o.height +} + func (o *Out) Plot(x, y int) { - x = limit(x, width) - y = limit(y, height) + x = limit(x, o.width) + y = limit(y, o.height) hiy := byte(y>>7) & 0x1f loy := byte(y>>2) & 0x1f -- cgit v1.2.3