aboutsummaryrefslogtreecommitdiff
path: root/pic.go
blob: a7c782783e13108956e135bd424d8545626fb6fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package robo

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strings"
)

type Page []Path

func parseLine(s string) (pa Path) {
	if strings.HasPrefix(s, "line from ") {
		for _, p := range strings.Split(s[10:], " to ") {
			var po Point
			fmt.Sscanf(p, "%v,%v", &po.X, &po.Y)
			po.X = po.X * IN
			po.Y = po.Y * IN
			pa = append(pa, po)
		}
	}
	return pa
}

func parsePage() (pa Page) {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		if p := parseLine(scanner.Text()); p != nil {
			pa = append(pa, p)
		}
	}
	if err := scanner.Err(); err != nil {
		log.Fatal(err)
	}
	return pa
}

func (r Robo) DrawPic() {
	//Landscape.Orientation(c)
	for _, p := range parsePage() {
		r.Line(p...)
	}
}