2024-09-15 09:01:13 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-09-15 10:46:07 +02:00
|
|
|
"context"
|
|
|
|
"fmt"
|
2024-09-15 09:01:13 +02:00
|
|
|
"github.com/Crocmagnon/display-epaper/epd"
|
2024-09-15 10:46:07 +02:00
|
|
|
"github.com/Crocmagnon/display-epaper/transports"
|
2024-09-15 09:01:13 +02:00
|
|
|
"github.com/llgcode/draw2d"
|
|
|
|
"github.com/llgcode/draw2d/draw2dimg"
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
)
|
|
|
|
|
2024-09-15 10:46:07 +02:00
|
|
|
func getBlack(ctx context.Context, transportsClient *transports.Client) (*image.RGBA, error) {
|
|
|
|
passages, err := transportsClient.GetTCLPassages(ctx, 290)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("getting passages: %w", err)
|
|
|
|
}
|
|
|
|
|
2024-09-15 09:01:13 +02:00
|
|
|
img := newWhite()
|
|
|
|
|
|
|
|
gc := draw2dimg.NewGraphicContext(img)
|
|
|
|
|
2024-09-15 10:46:07 +02:00
|
|
|
gc.SetFillRule(draw2d.FillRuleWinding)
|
2024-09-15 09:01:13 +02:00
|
|
|
gc.SetFillColor(color.RGBA{0, 0, 0, 255})
|
|
|
|
gc.SetStrokeColor(color.RGBA{0, 0, 0, 255})
|
|
|
|
|
2024-09-15 10:46:07 +02:00
|
|
|
for i, passage := range passages.Passages {
|
|
|
|
x := float64(10 + i*100)
|
|
|
|
text(gc, passage.Ligne, 15, x, 20)
|
|
|
|
for j, delay := range passage.Delays {
|
|
|
|
y := float64(20 + (j+1)*30)
|
|
|
|
text(gc, delay, 15, x, y)
|
|
|
|
}
|
|
|
|
}
|
2024-09-15 09:01:13 +02:00
|
|
|
|
|
|
|
return img, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func text(gc *draw2dimg.GraphicContext, s string, size, x, y float64) {
|
|
|
|
gc.SetFontData(draw2d.FontData{Name: fontName})
|
|
|
|
gc.SetFontSize(size)
|
2024-09-15 10:46:07 +02:00
|
|
|
gc.FillStringAt(s, x, y)
|
|
|
|
gc.SetLineWidth(2)
|
2024-09-15 09:01:13 +02:00
|
|
|
gc.StrokeStringAt(s, x, y)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newWhite() *image.RGBA {
|
|
|
|
img := image.NewRGBA(image.Rect(0, 0, epd.Width, epd.Height))
|
|
|
|
for y := 0; y < epd.Height; y++ {
|
|
|
|
for x := 0; x < epd.Width; x++ {
|
|
|
|
img.Set(x, y, color.White)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return img
|
|
|
|
}
|
|
|
|
|
|
|
|
func newBlack() *image.RGBA {
|
|
|
|
img := image.NewRGBA(image.Rect(0, 0, epd.Width, epd.Height))
|
|
|
|
for y := 0; y < epd.Height; y++ {
|
|
|
|
for x := 0; x < epd.Width; x++ {
|
|
|
|
img.Set(x, y, color.Black)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return img
|
|
|
|
}
|
|
|
|
|
|
|
|
func rect(gc *draw2dimg.GraphicContext, x1, y1, x2, y2 float64) {
|
|
|
|
gc.BeginPath()
|
|
|
|
gc.MoveTo(x1, y1)
|
|
|
|
gc.LineTo(x2, y1)
|
|
|
|
gc.LineTo(x2, y2)
|
|
|
|
gc.LineTo(x1, y2)
|
|
|
|
gc.Close()
|
|
|
|
gc.FillStroke()
|
|
|
|
}
|