2023-01-20 23:05:48 +00:00
|
|
|
package testing
|
|
|
|
|
2023-01-21 01:07:01 +00:00
|
|
|
import "fmt"
|
|
|
|
import "time"
|
2023-01-20 23:05:48 +00:00
|
|
|
import "image"
|
|
|
|
import "image/color"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
2023-02-12 02:07:35 +00:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/shatter"
|
2023-01-21 01:07:01 +00:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/defaultfont"
|
2023-01-20 23:05:48 +00:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
|
|
|
|
|
|
|
// Artist is an element that displays shapes and patterns drawn by the artist
|
|
|
|
// package in order to test it.
|
|
|
|
type Artist struct {
|
|
|
|
*core.Core
|
|
|
|
core core.CoreControl
|
|
|
|
cellBounds image.Rectangle
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewArtist creates a new artist test element.
|
|
|
|
func NewArtist () (element *Artist) {
|
|
|
|
element = &Artist { }
|
2023-02-08 19:36:14 +00:00
|
|
|
element.Core, element.core = core.NewCore(element.draw)
|
2023-01-30 07:22:16 +00:00
|
|
|
element.core.SetMinimumSize(480, 600)
|
2023-01-20 23:05:48 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-31 19:57:02 +00:00
|
|
|
func (element *Artist) draw () {
|
2023-01-20 23:05:48 +00:00
|
|
|
bounds := element.Bounds()
|
2023-02-13 06:49:33 +00:00
|
|
|
artist.FillRectangle(element.core, artist.NewUniform(hex(0)), bounds)
|
2023-02-03 23:32:22 +00:00
|
|
|
|
2023-01-31 23:39:17 +00:00
|
|
|
element.cellBounds.Max.X = bounds.Min.X + bounds.Dx() / 5
|
|
|
|
element.cellBounds.Max.Y = bounds.Min.Y + (bounds.Dy() - 48) / 8
|
2023-01-20 23:05:48 +00:00
|
|
|
|
2023-01-21 01:07:01 +00:00
|
|
|
drawStart := time.Now()
|
|
|
|
|
2023-01-20 23:05:48 +00:00
|
|
|
// 0, 0
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-21 04:00:26 +00:00
|
|
|
artist.Beveled {
|
2023-01-24 05:02:11 +00:00
|
|
|
artist.NewUniform(hex(0xFF0000FF)),
|
|
|
|
artist.NewUniform(hex(0x0000FFFF)),
|
2023-01-20 23:05:48 +00:00
|
|
|
},
|
|
|
|
element.cellAt(0, 0))
|
|
|
|
|
|
|
|
// 1, 0
|
|
|
|
artist.StrokeRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-20 23:05:48 +00:00
|
|
|
artist.NewUniform(hex(0x00FF00FF)), 3,
|
|
|
|
element.cellAt(1, 0))
|
|
|
|
|
|
|
|
// 2, 0
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-21 00:24:21 +00:00
|
|
|
artist.NewMultiBordered (
|
2023-01-21 00:07:16 +00:00
|
|
|
artist.Stroke { Pattern: uhex(0xFF0000FF), Weight: 1 },
|
|
|
|
artist.Stroke { Pattern: uhex(0x888800FF), Weight: 2 },
|
|
|
|
artist.Stroke { Pattern: uhex(0x00FF00FF), Weight: 3 },
|
|
|
|
artist.Stroke { Pattern: uhex(0x008888FF), Weight: 4 },
|
|
|
|
artist.Stroke { Pattern: uhex(0x0000FFFF), Weight: 5 },
|
2023-01-20 23:05:48 +00:00
|
|
|
),
|
|
|
|
element.cellAt(2, 0))
|
2023-01-20 23:39:08 +00:00
|
|
|
|
2023-01-21 00:24:21 +00:00
|
|
|
// 3, 0
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-21 00:24:21 +00:00
|
|
|
artist.Bordered {
|
|
|
|
Stroke: artist.Stroke { Pattern: uhex(0x0000FFFF), Weight: 5 },
|
|
|
|
Fill: uhex(0xFF0000FF),
|
|
|
|
},
|
|
|
|
element.cellAt(3, 0))
|
|
|
|
|
2023-01-30 07:22:16 +00:00
|
|
|
// 4, 0
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-30 07:22:16 +00:00
|
|
|
artist.Padded {
|
|
|
|
Stroke: uhex(0xFFFFFFFF),
|
|
|
|
Fill: uhex(0x666666FF),
|
|
|
|
Sides: []int { 4, 13, 2, 0 },
|
|
|
|
},
|
|
|
|
element.cellAt(4, 0))
|
|
|
|
|
2023-01-21 00:52:35 +00:00
|
|
|
// 0, 1 - 3, 1
|
2023-01-20 23:39:08 +00:00
|
|
|
for x := 0; x < 4; x ++ {
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-20 23:39:08 +00:00
|
|
|
artist.Striped {
|
2023-01-21 00:07:16 +00:00
|
|
|
First: artist.Stroke { Pattern: uhex(0xFF8800FF), Weight: 7 },
|
|
|
|
Second: artist.Stroke { Pattern: uhex(0x0088FFFF), Weight: 2 },
|
2023-01-21 04:19:54 +00:00
|
|
|
Orientation: artist.Orientation(x),
|
2023-01-20 23:39:08 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
element.cellAt(x, 1))
|
|
|
|
}
|
2023-01-21 00:40:38 +00:00
|
|
|
|
2023-01-21 00:52:35 +00:00
|
|
|
// 0, 2 - 3, 2
|
2023-01-21 00:40:38 +00:00
|
|
|
for x := 0; x < 4; x ++ {
|
2023-01-21 00:52:35 +00:00
|
|
|
element.lines(x + 1, element.cellAt(x, 2))
|
2023-01-21 00:40:38 +00:00
|
|
|
}
|
2023-01-21 01:07:01 +00:00
|
|
|
|
2023-01-21 01:52:06 +00:00
|
|
|
// 0, 3
|
2023-01-21 03:13:14 +00:00
|
|
|
artist.StrokeRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core, uhex(0x888888FF), 1,
|
2023-01-21 03:13:14 +00:00
|
|
|
element.cellAt(0, 3))
|
2023-02-13 06:49:33 +00:00
|
|
|
artist.FillEllipse(element.core, uhex(0x00FF00FF), element.cellAt(0, 3))
|
2023-01-21 01:52:06 +00:00
|
|
|
|
2023-01-21 03:13:14 +00:00
|
|
|
// 1, 3 - 3, 3
|
2023-01-21 02:59:48 +00:00
|
|
|
for x := 1; x < 4; x ++ {
|
2023-01-21 03:13:14 +00:00
|
|
|
artist.StrokeRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,uhex(0x888888FF), 1,
|
2023-01-21 03:13:14 +00:00
|
|
|
element.cellAt(x, 3))
|
2023-01-21 02:59:48 +00:00
|
|
|
artist.StrokeEllipse (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-21 02:59:48 +00:00
|
|
|
[]artist.Pattern {
|
|
|
|
uhex(0xFF0000FF),
|
|
|
|
uhex(0x00FF00FF),
|
|
|
|
uhex(0xFF00FFFF),
|
|
|
|
} [x - 1],
|
|
|
|
x, element.cellAt(x, 3))
|
|
|
|
}
|
|
|
|
|
2023-02-12 02:07:35 +00:00
|
|
|
// 4, 3
|
|
|
|
shatterPos := element.cellAt(4, 3).Min
|
|
|
|
rocks := []image.Rectangle {
|
|
|
|
image.Rect(3, 12, 13, 23).Add(shatterPos),
|
|
|
|
// image.Rect(30, 10, 40, 23).Add(shatterPos),
|
|
|
|
image.Rect(55, 40, 70, 49).Add(shatterPos),
|
|
|
|
image.Rect(30, -10, 40, 43).Add(shatterPos),
|
|
|
|
image.Rect(80, 30, 90, 45).Add(shatterPos),
|
|
|
|
}
|
|
|
|
tiles := shatter.Shatter(element.cellAt(4, 3), rocks...)
|
|
|
|
for index, tile := range tiles {
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core, []artist.Pattern {
|
2023-02-12 02:07:35 +00:00
|
|
|
uhex(0xFF0000FF),
|
|
|
|
uhex(0x00FF00FF),
|
|
|
|
uhex(0x0000FFFF),
|
|
|
|
uhex(0xFF00FFFF),
|
|
|
|
uhex(0xFFF00FFF),
|
|
|
|
uhex(0xAAAAAAFF),
|
|
|
|
uhex(0x699669FF),
|
|
|
|
uhex(0x077777FF),
|
|
|
|
} [index % 8], tile)
|
|
|
|
}
|
|
|
|
|
2023-01-21 04:19:54 +00:00
|
|
|
// 0, 4 - 3, 4
|
|
|
|
for x := 0; x < 4; x ++ {
|
|
|
|
artist.FillEllipse (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-21 04:19:54 +00:00
|
|
|
artist.Split {
|
2023-01-24 23:27:36 +00:00
|
|
|
First: uhex(0xFF0000FF),
|
|
|
|
Second: uhex(0x0000FFFF),
|
2023-01-21 04:19:54 +00:00
|
|
|
Orientation: artist.Orientation(x),
|
|
|
|
},
|
|
|
|
element.cellAt(x, 4))
|
|
|
|
}
|
2023-01-21 04:00:26 +00:00
|
|
|
|
|
|
|
// how long did that take to render?
|
2023-01-21 01:07:01 +00:00
|
|
|
drawTime := time.Since(drawStart)
|
|
|
|
textDrawer := artist.TextDrawer { }
|
|
|
|
textDrawer.SetFace(defaultfont.FaceRegular)
|
|
|
|
textDrawer.SetText ([]rune (fmt.Sprintf (
|
2023-01-21 01:29:02 +00:00
|
|
|
"%dms\n%dus",
|
2023-01-21 01:07:01 +00:00
|
|
|
drawTime.Milliseconds(),
|
2023-01-21 01:29:02 +00:00
|
|
|
drawTime.Microseconds())))
|
2023-02-13 06:49:33 +00:00
|
|
|
textDrawer.Draw(element.core, uhex(0xFFFFFFFF), image.Pt(8, bounds.Max.Y - 24))
|
2023-01-24 04:54:12 +00:00
|
|
|
|
|
|
|
// 0, 5
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-24 04:54:12 +00:00
|
|
|
artist.QuadBeveled {
|
2023-01-24 23:27:36 +00:00
|
|
|
uhex(0x880000FF),
|
|
|
|
uhex(0x00FF00FF),
|
|
|
|
uhex(0x0000FFFF),
|
|
|
|
uhex(0xFF00FFFF),
|
2023-01-24 04:54:12 +00:00
|
|
|
},
|
|
|
|
element.cellAt(0, 5))
|
2023-01-24 15:25:37 +00:00
|
|
|
|
|
|
|
// 1, 5
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-24 15:25:37 +00:00
|
|
|
artist.Checkered {
|
|
|
|
First: artist.QuadBeveled {
|
2023-01-24 23:27:36 +00:00
|
|
|
uhex(0x880000FF),
|
|
|
|
uhex(0x00FF00FF),
|
|
|
|
uhex(0x0000FFFF),
|
|
|
|
uhex(0xFF00FFFF),
|
2023-01-24 15:25:37 +00:00
|
|
|
},
|
|
|
|
Second: artist.Striped {
|
|
|
|
First: artist.Stroke { Pattern: uhex(0xFF8800FF), Weight: 1 },
|
|
|
|
Second: artist.Stroke { Pattern: uhex(0x0088FFFF), Weight: 1 },
|
|
|
|
Orientation: artist.OrientationVertical,
|
|
|
|
},
|
|
|
|
CellWidth: 32,
|
|
|
|
CellHeight: 16,
|
|
|
|
},
|
|
|
|
element.cellAt(1, 5))
|
|
|
|
|
|
|
|
// 2, 5
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-24 15:25:37 +00:00
|
|
|
artist.Dotted {
|
|
|
|
Foreground: uhex(0x00FF00FF),
|
|
|
|
Background: artist.Checkered {
|
|
|
|
First: uhex(0x444444FF),
|
|
|
|
Second: uhex(0x888888FF),
|
|
|
|
CellWidth: 16,
|
|
|
|
CellHeight: 16,
|
|
|
|
},
|
|
|
|
Size: 8,
|
|
|
|
Spacing: 16,
|
|
|
|
},
|
|
|
|
element.cellAt(2, 5))
|
2023-01-24 19:08:47 +00:00
|
|
|
|
|
|
|
// 3, 5
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-24 19:08:47 +00:00
|
|
|
artist.Tiled {
|
|
|
|
Pattern: artist.QuadBeveled {
|
2023-01-24 23:27:36 +00:00
|
|
|
uhex(0x880000FF),
|
|
|
|
uhex(0x00FF00FF),
|
|
|
|
uhex(0x0000FFFF),
|
|
|
|
uhex(0xFF00FFFF),
|
2023-01-24 19:08:47 +00:00
|
|
|
},
|
|
|
|
CellWidth: 17,
|
|
|
|
CellHeight: 23,
|
|
|
|
},
|
|
|
|
element.cellAt(3, 5))
|
2023-01-24 19:24:30 +00:00
|
|
|
|
|
|
|
// 0, 6 - 3, 6
|
|
|
|
for x := 0; x < 4; x ++ {
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-24 19:24:30 +00:00
|
|
|
artist.Gradient {
|
2023-01-24 23:27:36 +00:00
|
|
|
First: uhex(0xFF0000FF),
|
|
|
|
Second: uhex(0x0000FFFF),
|
2023-01-24 19:24:30 +00:00
|
|
|
Orientation: artist.Orientation(x),
|
|
|
|
},
|
|
|
|
element.cellAt(x, 6))
|
|
|
|
}
|
2023-01-24 20:35:00 +00:00
|
|
|
|
|
|
|
// 0, 7
|
|
|
|
artist.FillEllipse (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-24 20:35:00 +00:00
|
|
|
artist.EllipticallyBordered {
|
2023-01-24 21:02:35 +00:00
|
|
|
Fill: artist.Gradient {
|
2023-01-24 23:27:36 +00:00
|
|
|
First: uhex(0x00FF00FF),
|
|
|
|
Second: uhex(0x0000FFFF),
|
2023-01-24 21:02:35 +00:00
|
|
|
Orientation: artist.OrientationVertical,
|
|
|
|
},
|
2023-01-24 20:35:00 +00:00
|
|
|
Stroke: artist.Stroke { Pattern: uhex(0x00FF00), Weight: 5 },
|
|
|
|
},
|
|
|
|
element.cellAt(0, 7))
|
2023-01-24 23:15:46 +00:00
|
|
|
|
|
|
|
// 1, 7
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-24 23:15:46 +00:00
|
|
|
artist.Noisy {
|
|
|
|
Low: uhex(0x000000FF),
|
|
|
|
High: uhex(0xFFFFFFFF),
|
|
|
|
Seed: 0,
|
|
|
|
},
|
|
|
|
element.cellAt(1, 7),
|
|
|
|
)
|
2023-01-24 23:27:36 +00:00
|
|
|
|
|
|
|
// 2, 7
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-24 23:27:36 +00:00
|
|
|
artist.Noisy {
|
|
|
|
Low: uhex(0x000000FF),
|
|
|
|
High: artist.Gradient {
|
|
|
|
First: uhex(0x000000FF),
|
|
|
|
Second: uhex(0xFFFFFFFF),
|
|
|
|
Orientation: artist.OrientationVertical,
|
|
|
|
},
|
|
|
|
Seed: 0,
|
|
|
|
},
|
|
|
|
element.cellAt(2, 7),
|
|
|
|
)
|
|
|
|
|
|
|
|
// 3, 7
|
|
|
|
artist.FillRectangle (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core,
|
2023-01-24 23:27:36 +00:00
|
|
|
artist.Noisy {
|
|
|
|
Low: uhex(0x000000FF),
|
|
|
|
High: uhex(0xFFFFFFFF),
|
|
|
|
Seed: 0,
|
|
|
|
Harsh: true,
|
|
|
|
},
|
|
|
|
element.cellAt(3, 7),
|
|
|
|
)
|
2023-01-21 00:40:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (element *Artist) lines (weight int, bounds image.Rectangle) {
|
2023-01-21 04:40:59 +00:00
|
|
|
bounds = bounds.Inset(4)
|
2023-01-21 00:40:38 +00:00
|
|
|
c := uhex(0xFFFFFFFF)
|
2023-02-13 06:49:33 +00:00
|
|
|
artist.Line(element.core, c, weight, bounds.Min, bounds.Max)
|
2023-01-21 00:40:38 +00:00
|
|
|
artist.Line (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core, c, weight,
|
2023-01-21 00:40:38 +00:00
|
|
|
image.Pt(bounds.Max.X, bounds.Min.Y),
|
|
|
|
image.Pt(bounds.Min.X, bounds.Max.Y))
|
|
|
|
artist.Line (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core, c, weight,
|
2023-01-21 00:40:38 +00:00
|
|
|
image.Pt(bounds.Max.X, bounds.Min.Y + 16),
|
|
|
|
image.Pt(bounds.Min.X, bounds.Max.Y - 16))
|
|
|
|
artist.Line (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core, c, weight,
|
2023-01-21 00:40:38 +00:00
|
|
|
image.Pt(bounds.Min.X, bounds.Min.Y + 16),
|
|
|
|
image.Pt(bounds.Max.X, bounds.Max.Y - 16))
|
|
|
|
artist.Line (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core, c, weight,
|
2023-01-21 00:40:38 +00:00
|
|
|
image.Pt(bounds.Min.X + 20, bounds.Min.Y),
|
|
|
|
image.Pt(bounds.Max.X - 20, bounds.Max.Y))
|
|
|
|
artist.Line (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core, c, weight,
|
2023-01-21 00:40:38 +00:00
|
|
|
image.Pt(bounds.Max.X - 20, bounds.Min.Y),
|
|
|
|
image.Pt(bounds.Min.X + 20, bounds.Max.Y))
|
|
|
|
artist.Line (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core, c, weight,
|
2023-01-21 00:40:38 +00:00
|
|
|
image.Pt(bounds.Min.X, bounds.Min.Y + bounds.Dy() / 2),
|
|
|
|
image.Pt(bounds.Max.X, bounds.Min.Y + bounds.Dy() / 2))
|
|
|
|
artist.Line (
|
2023-02-13 06:49:33 +00:00
|
|
|
element.core, c, weight,
|
2023-01-21 00:40:38 +00:00
|
|
|
image.Pt(bounds.Min.X + bounds.Dx() / 2, bounds.Min.Y),
|
|
|
|
image.Pt(bounds.Min.X + bounds.Dx() / 2, bounds.Max.Y))
|
2023-01-20 23:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (element *Artist) cellAt (x, y int) (image.Rectangle) {
|
|
|
|
return element.cellBounds.Add (image.Pt (
|
|
|
|
x * element.cellBounds.Dx(),
|
|
|
|
y * element.cellBounds.Dy()))
|
|
|
|
}
|
|
|
|
|
|
|
|
func hex (n uint32) (c color.RGBA) {
|
|
|
|
c.A = uint8(n)
|
|
|
|
c.B = uint8(n >> 8)
|
|
|
|
c.G = uint8(n >> 16)
|
|
|
|
c.R = uint8(n >> 24)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func uhex (n uint32) (artist.Pattern) {
|
|
|
|
return artist.NewUniform (color.RGBA {
|
|
|
|
A: uint8(n),
|
|
|
|
B: uint8(n >> 8),
|
|
|
|
G: uint8(n >> 16),
|
|
|
|
R: uint8(n >> 24),
|
|
|
|
})
|
|
|
|
}
|