THICC LINES
This commit is contained in:
parent
268e7981b5
commit
a87d806e54
@ -1,8 +1,11 @@
|
||||
package artist
|
||||
|
||||
import "image"
|
||||
import "image/color"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
|
||||
// TODO: draw thick lines more efficiently
|
||||
|
||||
// Line draws a line from one point to another with the specified weight and
|
||||
// pattern.
|
||||
func Line (
|
||||
@ -14,7 +17,6 @@ func Line (
|
||||
) (
|
||||
updatedRegion image.Rectangle,
|
||||
) {
|
||||
// TODO: respect weight
|
||||
|
||||
updatedRegion = image.Rectangle { Min: min, Max: max }.Canon()
|
||||
updatedRegion.Max.X ++
|
||||
@ -68,7 +70,8 @@ func lineLow (
|
||||
|
||||
for x := min.X; x < max.X; x ++ {
|
||||
if !(image.Point { x, y }).In(bounds) { break }
|
||||
data[x + y * stride] = source.AtWhen(x, y, width, height)
|
||||
squareAround(data, stride, source, x, y, width, height, weight)
|
||||
// data[x + y * stride] = source.AtWhen(x, y, width, height)
|
||||
if D > 0 {
|
||||
y += yi
|
||||
D += 2 * (deltaY - deltaX)
|
||||
@ -103,7 +106,8 @@ func lineHigh (
|
||||
|
||||
for y := min.Y; y < max.Y; y ++ {
|
||||
if !(image.Point { x, y }).In(bounds) { break }
|
||||
data[x + y * stride] = source.AtWhen(x, y, width, height)
|
||||
squareAround(data, stride, source, x, y, width, height, weight)
|
||||
// data[x + y * stride] = source.AtWhen(x, y, width, height)
|
||||
if D > 0 {
|
||||
x += xi
|
||||
D += 2 * (deltaX - deltaY)
|
||||
@ -118,3 +122,20 @@ func abs (in int) (out int) {
|
||||
out = in
|
||||
return
|
||||
}
|
||||
|
||||
func squareAround (
|
||||
data []color.RGBA,
|
||||
stride int,
|
||||
source Pattern,
|
||||
x, y, patternWidth, patternHeight, diameter int,
|
||||
) {
|
||||
minY := y - diameter
|
||||
minX := x - diameter
|
||||
maxY := y + diameter
|
||||
maxX := x + diameter
|
||||
for y = minY; y < maxY; y ++ {
|
||||
for x = minX; x < maxX; x ++ {
|
||||
data[x + y * stride] =
|
||||
source.AtWhen(x, y, patternWidth, patternHeight)
|
||||
}}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ func (element *Artist) Resize (width, height int) {
|
||||
},
|
||||
element.cellAt(3, 0))
|
||||
|
||||
// 0, 1 - 0, 3
|
||||
// 0, 1 - 3, 1
|
||||
for x := 0; x < 4; x ++ {
|
||||
artist.FillRectangle (
|
||||
element,
|
||||
@ -76,8 +76,9 @@ func (element *Artist) Resize (width, height int) {
|
||||
element.cellAt(x, 1))
|
||||
}
|
||||
|
||||
// 0, 2 - 3, 2
|
||||
for x := 0; x < 4; x ++ {
|
||||
element.lines(x, element.cellAt(x, 2))
|
||||
element.lines(x + 1, element.cellAt(x, 2))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user