data-oriented-patterns #9
@ -19,13 +19,16 @@ func (pattern Texture) Draw (destination canvas.Canvas, clip image.Rectangle) {
|
|||||||
dstData, dstStride := destination.Buffer()
|
dstData, dstStride := destination.Buffer()
|
||||||
srcData, srcStride := pattern.Buffer()
|
srcData, srcStride := pattern.Buffer()
|
||||||
srcBounds := pattern.Bounds()
|
srcBounds := pattern.Bounds()
|
||||||
|
|
||||||
for y := bounds.Min.Y; y < bounds.Max.Y; y ++ {
|
point := image.Point { }
|
||||||
for x := bounds.Min.X; x < bounds.Max.X; x ++ {
|
for point.Y = bounds.Min.Y; point.Y < bounds.Max.Y; point.Y ++ {
|
||||||
dstIndex := x + y * dstStride
|
for point.X = bounds.Min.X; point.X < bounds.Max.X; point.X ++ {
|
||||||
|
srcPoint := point.Sub(realBounds.Min).Add(srcBounds.Min)
|
||||||
|
|
||||||
|
dstIndex := point.X + point.Y * dstStride
|
||||||
srcIndex :=
|
srcIndex :=
|
||||||
wrap(x - realBounds.Min.X, srcBounds.Min.X, srcBounds.Max.X) +
|
wrap(srcPoint.X, srcBounds.Min.X, srcBounds.Max.X) +
|
||||||
wrap(y - realBounds.Min.Y, srcBounds.Min.Y, srcBounds.Max.Y) * srcStride
|
wrap(srcPoint.Y, srcBounds.Min.Y, srcBounds.Max.Y) * srcStride
|
||||||
dstData[dstIndex] = srcData[srcIndex]
|
dstData[dstIndex] = srcData[srcIndex]
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,16 @@ func (element *Artist) draw () {
|
|||||||
c32 := element.cellAt(3, 2)
|
c32 := element.cellAt(3, 2)
|
||||||
shapes.StrokeRectangle(c32, c41, 5)
|
shapes.StrokeRectangle(c32, c41, 5)
|
||||||
|
|
||||||
|
// 4, 2
|
||||||
|
c42 := element.cellAt(4, 2)
|
||||||
|
|
||||||
|
// 0, 3
|
||||||
|
c03 := element.cellAt(0, 3)
|
||||||
|
patterns.Border {
|
||||||
|
Canvas: element.thingy(c42),
|
||||||
|
Inset: artist.Inset { 8, 8, 8, 8 },
|
||||||
|
}.Draw(c03, c03.Bounds())
|
||||||
|
|
||||||
// how long did that take to render?
|
// how long did that take to render?
|
||||||
drawTime := time.Since(drawStart)
|
drawTime := time.Since(drawStart)
|
||||||
textDrawer := textdraw.Drawer { }
|
textDrawer := textdraw.Drawer { }
|
||||||
@ -165,3 +175,14 @@ func (element *Artist) cellAt (x, y int) (canvas.Canvas) {
|
|||||||
x * cellBounds.Dx(),
|
x * cellBounds.Dx(),
|
||||||
y * cellBounds.Dy())))
|
y * cellBounds.Dy())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (element *Artist) thingy (destination canvas.Canvas) (result canvas.Canvas) {
|
||||||
|
bounds := destination.Bounds()
|
||||||
|
bounds = image.Rect(0, 0, 32, 32).Add(bounds.Min)
|
||||||
|
shapes.FillColorRectangle(destination, artist.Hex(0x440000FF), bounds)
|
||||||
|
shapes.StrokeColorRectangle(destination, artist.Hex(0xFF0000FF), bounds, 1)
|
||||||
|
shapes.StrokeColorRectangle(destination, artist.Hex(0x004400FF), bounds.Inset(4), 1)
|
||||||
|
shapes.FillColorRectangle(destination, artist.Hex(0x004444FF), bounds.Inset(12))
|
||||||
|
shapes.StrokeColorRectangle(destination, artist.Hex(0x888888FF), bounds.Inset(8), 1)
|
||||||
|
return canvas.Cut(destination, bounds)
|
||||||
|
}
|
||||||
|
@ -37,19 +37,19 @@ func init () {
|
|||||||
// PatternDead
|
// PatternDead
|
||||||
atlasCol(0, artist.Inset { })
|
atlasCol(0, artist.Inset { })
|
||||||
// PatternRaised
|
// PatternRaised
|
||||||
atlasCol(1, artist.Inset { 6, 6, 6, 6 })
|
atlasCol(1, artist.Inset { 6, 6, 6, 6 }) // broken
|
||||||
// PatternSunken
|
// PatternSunken
|
||||||
atlasCol(2, artist.Inset { 4, 4, 4, 4 })
|
atlasCol(2, artist.Inset { 4, 4, 4, 4 })
|
||||||
// PatternPinboard
|
// PatternPinboard
|
||||||
atlasCol(3, artist.Inset { 2, 2, 2, 2 })
|
atlasCol(3, artist.Inset { 2, 2, 2, 2 })
|
||||||
// PatternButton
|
// PatternButton
|
||||||
atlasCol(4, artist.Inset { 6, 6, 6, 6 })
|
atlasCol(4, artist.Inset { 6, 6, 6, 6 }) // broken
|
||||||
// PatternInput
|
// PatternInput
|
||||||
atlasCol(5, artist.Inset { 4, 4, 4, 4 })
|
atlasCol(5, artist.Inset { 4, 4, 4, 4 })
|
||||||
// PatternGutter
|
// PatternGutter
|
||||||
atlasCol(6, artist.Inset { 4, 4, 4, 4 })
|
atlasCol(6, artist.Inset { 4, 4, 4, 4 })
|
||||||
// PatternHandle
|
// PatternHandle
|
||||||
atlasCol(7, artist.Inset { 6, 6, 6, 6 })
|
atlasCol(7, artist.Inset { 6, 6, 6, 6 }) // broken
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default is the default theme.
|
// Default is the default theme.
|
||||||
|
Reference in New Issue
Block a user