summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-01-06 01:20:54 +0100
committerDimitri Sokolyuk <demon@dim13.org>2017-01-06 01:20:54 +0100
commit3d6763f8217c06989e44b6661409c5dbf6db45ef (patch)
tree3b9b1cc13057eab8883af6e67975c096bed030a8
parentf4951f468ac7a85499d0d24738a4e0f907ca21a8 (diff)
Works
-rw-r--r--main.go26
-rw-r--r--patch.go19
-rw-r--r--tek.go92
3 files changed, 132 insertions, 5 deletions
diff --git a/main.go b/main.go
index 65e12d0..8ee9471 100644
--- a/main.go
+++ b/main.go
@@ -1,7 +1,6 @@
package main
import (
- "fmt"
"log"
"os"
)
@@ -14,12 +13,29 @@ func main() {
defer fd.Close()
patches := Parse(fd)
+
+ out := NewOut(os.Stdout)
+ out.Clear()
+ out.Enable()
+ defer out.Disable()
+ step := 1.0 / float64(10)
for _, p := range patches {
- for u := 0.0; u <= 1.0; u += 1.0 {
- for v := 0.0; v <= 1.0; v += 1.0 {
- fmt.Print(Calc(u, v, p))
+ 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.Draw(x, y)
+ }
+ out.PenUp()
+
+ out.PenDown()
+ for v := 0.0; v <= 1.0; v += step {
+ vertex := Calc(v, u, p)
+ x, y := vertex.Project()
+ out.Draw(x, y)
}
+ out.PenUp()
}
- fmt.Println("")
}
}
diff --git a/patch.go b/patch.go
index 496b727..ff0d6ac 100644
--- a/patch.go
+++ b/patch.go
@@ -27,3 +27,22 @@ func (p Patch) Z() []float64 {
}
return f
}
+
+func (v Vertex) RotX() Vertex {
+ v.Y = 0.5*v.Y + 0.866*v.Z
+ v.Z = 0.5*v.Z - 0.866*v.Y
+ return v
+}
+
+func (v Vertex) Project() (int, int) {
+ dist := 1000.0
+ zoom := 1000.0
+ v = v.RotX()
+ v.X *= dist / (2*dist - v.Z)
+ v.Y *= dist / (2*dist - v.Z)
+ v.X *= zoom
+ v.Y *= zoom
+ v.X += width / 2
+ v.Y += height / 3
+ return int(v.X), int(v.Y)
+}
diff --git a/tek.go b/tek.go
new file mode 100644
index 0000000..7d1451e
--- /dev/null
+++ b/tek.go
@@ -0,0 +1,92 @@
+package main
+
+import (
+ "bufio"
+ "io"
+)
+
+const (
+ height = 3072
+ width = 4096
+)
+
+type Out struct {
+ *bufio.Writer
+ hix, hiy, lox, loy, eb int
+}
+
+func NewOut(w io.Writer) *Out {
+ return &Out{Writer: bufio.NewWriter(w)}
+}
+
+func (o Out) Enable() {
+ o.WriteByte(0x1b)
+ o.WriteString("[?38h")
+ o.Flush()
+}
+
+func (o Out) Disable() {
+ o.WriteByte(0x1b)
+ o.WriteByte(0x03)
+ o.Flush()
+}
+
+func (o Out) Clear() {
+ o.Enable()
+ o.WriteByte(0x1b)
+ o.WriteByte(0x0c)
+ o.Disable()
+ o.Flush()
+}
+
+func (o Out) PenUp() {
+ o.WriteByte(0x1d)
+ o.WriteByte(0x07)
+ o.Flush()
+}
+
+func (o Out) PenDown() {
+ o.WriteByte(0x1d)
+ o.Flush()
+}
+
+func limit(val, max int) int {
+ if val < 0 {
+ return 0
+ }
+ if val >= max {
+ return max - 1
+ }
+ return val
+}
+
+func (o *Out) Draw(x, y int) {
+ x = limit(x, width)
+ y = limit(y, height)
+
+ hix := (x >> 7) & 0x1f
+ hiy := (y >> 7) & 0x1f
+ lox := (x >> 2) & 0x1f
+ loy := (y >> 2) & 0x1f
+ eb := (x & 3) | ((y & 3) << 2)
+
+ if hiy != o.hiy {
+ o.WriteByte(byte(hiy | 0x20))
+ }
+ if eb != o.eb {
+ o.WriteByte(byte(eb | 0x60))
+ }
+ if eb != o.eb || loy != o.loy || hix != o.hix {
+ o.WriteByte(byte(loy | 0x60))
+ }
+ if hix != o.hix {
+ o.WriteByte(byte(hix | 0x20))
+ }
+ o.WriteByte(byte(lox | 0x40))
+ o.hix = hix
+ o.hiy = hiy
+ o.lox = lox
+ o.loy = loy
+ o.eb = eb
+ o.Flush()
+}