| @@ -20,7 +20,7 @@ func main() { | |||||
| pat := broek.GenereerPatroon() | pat := broek.GenereerPatroon() | ||||
| c := canvas.New(200, 200) | c := canvas.New(200, 200) | ||||
| err := pat.ToCanvas(c) | |||||
| err := pat.ToCanvas(c, false) | |||||
| if err != nil { | if err != nil { | ||||
| panic(err) | panic(err) | ||||
| } | } | ||||
| @@ -20,11 +20,13 @@ func main() { | |||||
| templateDir string | templateDir string | ||||
| outputDir string | outputDir string | ||||
| help bool | help bool | ||||
| debug bool | |||||
| ) | ) | ||||
| flag.StringVar(&templateDir, "templates", "templates", "Directory with template files") | flag.StringVar(&templateDir, "templates", "templates", "Directory with template files") | ||||
| flag.StringVar(&outputDir, "out", ".", "output directory") | flag.StringVar(&outputDir, "out", ".", "output directory") | ||||
| flag.BoolVar(&help, "help", false, "show help") | flag.BoolVar(&help, "help", false, "show help") | ||||
| flag.BoolVar(&debug, "debug", false, "enable debug mode") | |||||
| if err := env.ParseWithFlags(); err != nil { | if err := env.ParseWithFlags(); err != nil { | ||||
| slog.Error("parsing flags failed", "err", err) | slog.Error("parsing flags failed", "err", err) | ||||
| @@ -59,7 +61,7 @@ gopatterns [-templates <template-dir>] [-out <output-dir>] input-file | |||||
| return | return | ||||
| } | } | ||||
| filenames, err := storage.RenderPatterns(pattern, outputDir) | |||||
| filenames, err := storage.RenderPatterns(pattern, outputDir, debug) | |||||
| if err != nil { | if err != nil { | ||||
| slog.Error("error occurred while creating pattern", "pattern", arg, "err", err) | slog.Error("error occurred while creating pattern", "pattern", arg, "err", err) | ||||
| return | return | ||||
| @@ -58,7 +58,7 @@ func NewPattern() *Pattern { | |||||
| } | } | ||||
| // ToCanvas draws the pattern on the provided [canvas.Canvas]. | // ToCanvas draws the pattern on the provided [canvas.Canvas]. | ||||
| func (p *Pattern) ToCanvas(c *canvas.Canvas) error { | |||||
| func (p *Pattern) ToCanvas(c *canvas.Canvas, debug bool) error { | |||||
| fontDejaVu := canvas.NewFontFamily("latin") | fontDejaVu := canvas.NewFontFamily("latin") | ||||
| if err := fontDejaVu.LoadFont(goregular.TTF, 0, canvas.FontRegular); err != nil { | if err := fontDejaVu.LoadFont(goregular.TTF, 0, canvas.FontRegular); err != nil { | ||||
| @@ -67,7 +67,7 @@ func (p *Pattern) ToCanvas(c *canvas.Canvas) error { | |||||
| face := fontDejaVu.Face(12.0, canvas.Black, canvas.FontRegular) | face := fontDejaVu.Face(12.0, canvas.Black, canvas.FontRegular) | ||||
| for _, pp := range p.points { | for _, pp := range p.points { | ||||
| point.Draw(c, pp, face) | |||||
| point.Draw(c, pp, face, debug) | |||||
| } | } | ||||
| for _, path := range p.lines { | for _, path := range p.lines { | ||||
| @@ -44,8 +44,8 @@ type Point interface { | |||||
| // Draw draws a specific Point to the provided [canvas.Canvas]. | // Draw draws a specific Point to the provided [canvas.Canvas]. | ||||
| // The point is only drawn when the point states that it should be drawn and not must be hidden. | // The point is only drawn when the point states that it should be drawn and not must be hidden. | ||||
| func Draw(c *canvas.Canvas, point Point, face *canvas.FontFace) { | |||||
| if !point.Draw() || point.Hide() { | |||||
| func Draw(c *canvas.Canvas, point Point, face *canvas.FontFace, debug bool) { | |||||
| if !debug && (!point.Draw() || point.Hide()) { | |||||
| return | return | ||||
| } | } | ||||
| @@ -13,7 +13,7 @@ import ( | |||||
| ) | ) | ||||
| // RenderPatterns loads a [Request] from yaml file and renders the pattern to an SVG. | // RenderPatterns loads a [Request] from yaml file and renders the pattern to an SVG. | ||||
| func (s Storage) RenderPatterns(request Request, outputDir string) ([]string, error) { | |||||
| func (s Storage) RenderPatterns(request Request, outputDir string, debug bool) ([]string, error) { | |||||
| template, err := s.LoadTemplate(request.Template) | template, err := s.LoadTemplate(request.Template) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, fmt.Errorf("load pattern %q: %w", request.Template, err) | return nil, fmt.Errorf("load pattern %q: %w", request.Template, err) | ||||
| @@ -40,7 +40,7 @@ func (s Storage) RenderPatterns(request Request, outputDir string) ([]string, er | |||||
| c := canvas.New(200, 200) | c := canvas.New(200, 200) | ||||
| err = pat.ToCanvas(c) | |||||
| err = pat.ToCanvas(c, debug) | |||||
| if err != nil { | if err != nil { | ||||
| return nil, fmt.Errorf("write pattern to canvas: %w", err) | return nil, fmt.Errorf("write pattern to canvas: %w", err) | ||||
| } | } | ||||