summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-01-08 19:20:51 +0100
committerDimitri Sokolyuk <demon@dim13.org>2017-01-08 19:20:51 +0100
commitf0ca9f2ca922c9bd5587a2371b4ad1b81c404cb0 (patch)
tree4fe0bf06edf2cbde541a9f8d43cc1e56d7dedb86
parent6950c110be1d69237d701133eaac00b962217f17 (diff)
Cleanup plotter
-rw-r--r--main.go12
-rw-r--r--patch.go10
-rw-r--r--tek.go16
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