-
Notifications
You must be signed in to change notification settings - Fork 0
/
pen.go
59 lines (49 loc) · 848 Bytes
/
pen.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package turtle
import (
"fmt"
"image/color"
)
// A simple Pen.
type Pen struct {
Color color.Color // Line color.
Size int // Line width.
On bool // State of the Pen.
}
// Create a new Pen.
func NewPen() *Pen {
p := new(Pen)
p.Color = White
p.Size = 3
return p
}
// Start writing.
func (p *Pen) PenDown() {
p.On = true
}
// Stop writing.
func (p *Pen) PenUp() {
p.On = false
}
// Toggle the pen state.
func (p *Pen) PenToggle() {
if p.On {
p.On = false
} else {
p.On = true
}
}
// Change the Pen color.
func (p *Pen) SetColor(c color.Color) {
p.Color = c
}
// Change the Pen size.
func (p *Pen) SetSize(s int) {
p.Size = s
}
var _ fmt.Stringer = &Pen{}
// Write the Pen state.
//
// Implements: fmt.Stringer
func (p *Pen) String() string {
return fmt.Sprintf("%v, %d, %t", p.Color, p.Size, p.On)
}