| 84 | } |
| 85 | |
| 86 | func (model *Model) SVG() string { |
| 87 | bg := model.Background |
| 88 | var lines []string |
| 89 | lines = append(lines, fmt.Sprintf("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"%d\" height=\"%d\">", model.Sw, model.Sh)) |
| 90 | lines = append(lines, fmt.Sprintf("<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%02x%02x%02x\" />", model.Sw, model.Sh, bg.R, bg.G, bg.B)) |
| 91 | lines = append(lines, fmt.Sprintf("<g transform=\"scale(%f) translate(0.5 0.5)\">", model.Scale)) |
| 92 | for i, shape := range model.Shapes { |
| 93 | c := model.Colors[i] |
| 94 | attrs := "fill=\"#%02x%02x%02x\" fill-opacity=\"%f\"" |
| 95 | attrs = fmt.Sprintf(attrs, c.R, c.G, c.B, float64(c.A)/255) |
| 96 | lines = append(lines, shape.SVG(attrs)) |
| 97 | } |
| 98 | lines = append(lines, "</g>") |
| 99 | lines = append(lines, "</svg>") |
| 100 | return strings.Join(lines, "\n") |
| 101 | } |
| 102 | |
| 103 | func (model *Model) Add(shape Shape, alpha int) { |
| 104 | before := copyRGBA(model.Current) |