summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-01-08 23:05:09 +0100
committerDimitri Sokolyuk <demon@dim13.org>2017-01-08 23:05:09 +0100
commit97bf78219fb94f8a6490f7cd0d72de37f6965549 (patch)
tree35f26d19359dec6f2ca342ef67c87581a2f2417e
parent0add289317bf4acca0992f9cf2df71e937227873 (diff)
pen
-rw-r--r--main.go13
-rw-r--r--patch.go14
-rw-r--r--tek.go13
3 files changed, 22 insertions, 18 deletions
diff --git a/main.go b/main.go
index bf56d0d..ceae156 100644
--- a/main.go
+++ b/main.go
@@ -17,18 +17,23 @@ func main() {
out := NewOut(os.Stdout)
out.Enable()
defer out.Disable()
+ plot(out, patches)
+}
+
+func plot(out Plotter, patches []Patch) {
+ out.Clear()
step := 1.0 / float64(5)
for _, p := range patches {
for u := 0.0; u <= 1.0; u += step {
- out.PenDown()
+ out.Pen()
for v := 0.0; v <= 1.0; v += step {
- p.Calc(u, v).Project(out)
+ p.Calc(u, v).Project(out, -60, 0, -15)
}
}
for u := 0.0; u <= 1.0; u += step {
- out.PenDown()
+ out.Pen()
for v := 0.0; v <= 1.0; v += step {
- p.Calc(v, u).Project(out)
+ p.Calc(v, u).Project(out, -60, 0, -15)
}
}
}
diff --git a/patch.go b/patch.go
index e7aca39..0401588 100644
--- a/patch.go
+++ b/patch.go
@@ -30,26 +30,26 @@ func (p Patch) Z() []float64 {
return f
}
-func rot(deg float64) (float64, float64) {
- rad := deg * math.Pi / 180.0
+func rot(deg int) (float64, float64) {
+ rad := float64(deg) * math.Pi / 180.0
return math.Sin(rad), math.Cos(rad)
}
-func (v Vertex) RotX(deg float64) Vertex {
+func (v Vertex) RotX(deg int) Vertex {
sin, cos := rot(deg)
v.Y = cos*v.Y - sin*v.Z
v.Z = sin*v.Y + cos*v.Z
return v
}
-func (v Vertex) RotY(deg float64) Vertex {
+func (v Vertex) RotY(deg int) Vertex {
sin, cos := rot(deg)
v.X = cos*v.X + sin*v.Z
v.Z = -sin*v.X + cos*v.Z
return v
}
-func (v Vertex) RotZ(deg float64) Vertex {
+func (v Vertex) RotZ(deg int) Vertex {
sin, cos := rot(deg)
v.X = cos*v.X - sin*v.Y
v.Y = sin*v.X + cos*v.Y
@@ -63,9 +63,9 @@ func (v Vertex) Zoom(zoom float64) Vertex {
return v
}
-func (v Vertex) Project(p Plotter) {
+func (v Vertex) Project(p Plotter, rx, ry, rz int) {
dist := 100000.0
- v = v.Zoom(1000).RotZ(-15).RotX(-60)
+ v = v.Zoom(1000).RotZ(rz).RotY(ry).RotX(rx)
w, h := p.Dim()
v.X *= dist / (2*dist - v.Z)
diff --git a/tek.go b/tek.go
index 38ee8d9..d0909e1 100644
--- a/tek.go
+++ b/tek.go
@@ -36,11 +36,14 @@ func NewOut(w io.Writer) *Out {
}
}
+func (o Out) Clear() {
+ o.writeByte(ESC, FF) // Tek Page
+}
+
func (o Out) Enable() {
if o.xterm {
o.escString("[?38h")
- o.writeByte(ESC, FF) // Tek Page
- o.writeByte(ESC, '`') // solid lines
+ o.Clear()
}
}
@@ -52,11 +55,7 @@ func (o Out) Disable() {
}
}
-func (o Out) PenUp() {
- o.writeByte(GS, 7)
-}
-
-func (o Out) PenDown() {
+func (o Out) Pen() {
o.writeByte(GS)
}