/
genarchitecture.go
174 lines (154 loc) · 4.22 KB
/
genarchitecture.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package genarchitecture
import (
"math/rand"
"os"
svg "github.com/ajstarks/svgo"
)
func GenerateStyle(availableMaterials []string) Style {
return Style{
OuterDoorStyle: generateDoorStyle(availableMaterials),
InnerDoorStyle: generateDoorStyle(availableMaterials),
WindowStyle: generateWindowStyle(availableMaterials),
InnerWallStyle: generateWallStyle(availableMaterials),
OuterWallStyle: generateWallStyle(availableMaterials),
FloorStyle: generateFloorStyle(availableMaterials),
CeilingStyle: generateCeilingStyle(availableMaterials),
RoofStyle: generateRoofStyle(availableMaterials),
}
}
type Style struct {
OuterDoorStyle DoorStyle
InnerDoorStyle DoorStyle
WindowStyle WindowStyle
InnerWallStyle WallStyle
OuterWallStyle WallStyle
FloorStyle FloorStyle
CeilingStyle CeilingStyle
RoofStyle RoofStyle
}
func (s *Style) ExportSvg(path string) error {
f, err := os.Create(path)
if err != nil {
return err
}
defer f.Close()
sv := svg.New(f)
sv.Start(1000, 1000)
s.OuterDoorStyle.DrawToSVG(sv, 0, 0, 100, 200)
s.InnerDoorStyle.DrawToSVG(sv, 200, 0, 100, 200)
sv.End()
return nil
}
func (s Style) Description() string {
// Describe the outside of the building.
var description string
description += "The outside of the building is made of " + s.OuterWallStyle.Description() + ". "
description += "The roof is made of " + s.RoofStyle.Description() + ". "
description += "The floor is made of " + s.FloorStyle.Description() + ". "
description += "The ceiling is made of " + s.CeilingStyle.Description() + ". "
description += "The outer door is made of " + s.OuterDoorStyle.Description() + ". "
description += "The windows are made of " + s.WindowStyle.Description() + ". "
// Describe the inside of the building.
description += "The inside of the building is made of " + s.InnerWallStyle.Description() + ". "
description += "The inner door is made of " + s.InnerDoorStyle.Description() + ". "
return description
}
// BaseStyle is a struct that contains the basic style information for a
// building component. It can be embedded in other structs to provide
// a common set of style information.
type BaseStyle struct {
Ornate *Decoration // decoration of the component
Material string // main material of the component
Finish string // finish of the component
}
// Description returns a string describing the style of the component.
func (b BaseStyle) Description() string {
var leader string
if b.Finish != FinishNone {
leader = b.Finish + " "
}
leader += b.Material
if b.Ornate == nil || b.Ornate.Type == DecorationTypeNone {
return leader
}
return leader + " " + b.Ornate.Description()
}
func generateBaseStyle(availableMaterials []string) BaseStyle {
// Generate a random decoration
var ornate *Decoration
if rand.Intn(4) == 0 {
ornate = genDecoration()
}
return BaseStyle{
Ornate: ornate,
Material: randomString(availableMaterials),
Finish: randomString(finishes),
}
}
const (
SizeNone = 0
SizeTiny = 1
SizeSmall = 2
SizeMedium = 3
SizeLarge = 4
SizeHuge = 5
)
const (
MaterialStone = "stone"
MaterialWood = "wood"
MaterialBrick = "brick"
MaterialGlass = "glass"
MaterialMetal = "metal"
MaterialMarble = "marble"
MaterialPlaster = "plaster"
MaterialPaper = "paper"
MaterialClay = "clay"
MaterialCeramic = "ceramic"
MaterialPlastic = "plastic"
MaterialLeather = "leather"
MaterialFur = "fur"
MaterialBone = "bone"
MaterialShell = "shell"
)
var Materials = []string{
MaterialStone,
MaterialWood,
MaterialBrick,
MaterialGlass,
MaterialMetal,
MaterialMarble,
MaterialPlaster,
MaterialPaper,
MaterialClay,
MaterialCeramic,
MaterialPlastic,
MaterialLeather,
MaterialFur,
MaterialBone,
MaterialShell,
}
const (
FinishNone = "none"
FinishPolished = "polished"
FinishRough = "rough"
FinishBurnished = "burnished"
FinishPainted = "painted"
FinishPlastered = "plastered"
)
var finishes = []string{
FinishNone,
FinishPolished,
FinishRough,
FinishBurnished,
FinishPainted,
FinishPlastered,
}
func randomString(options []string) string {
if len(options) == 0 {
return ""
}
return options[rand.Intn(len(options)-1)]
}
func randomInt(min, max int) int {
return rand.Intn(max-min) + min
}