mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-07-27 22:20:07 +00:00
feat(misc): move wheel beta pointer right
This commit is contained in:
@@ -361,21 +361,34 @@ func TestWheelOfNamesBeta_SpinProfileProgressIsMonotonic(t *testing.T) {
|
||||
func TestWheelOfNamesBeta_PointerPointsIntoWheel(t *testing.T) {
|
||||
img := renderWheelBetaFrame([]string{"Alice", "Bob"}, 0, finalWheelRotation(2, 0), false)
|
||||
cx := wheelBetaSize / 2
|
||||
tipY := wheelBetaSize/2 - wheelBetaRadius
|
||||
if got := img.ColorIndexAt(cx, tipY); got != 1 {
|
||||
cy := wheelBetaSize / 2
|
||||
tipX := cx + wheelBetaRadius
|
||||
if got := img.ColorIndexAt(tipX, cy); got != 1 {
|
||||
t.Fatalf("pointer tip color = %d, want 1", got)
|
||||
}
|
||||
if got := img.ColorIndexAt(cx+5, tipY-10); got != 1 {
|
||||
if got := img.ColorIndexAt(tipX+10, cy+5); got != 1 {
|
||||
t.Fatalf("pointer shoulder color = %d, want 1", got)
|
||||
}
|
||||
if got := img.ColorIndexAt(cx, tipY-12); got != wheelBetaSliceColorIndexes[0] {
|
||||
if got := img.ColorIndexAt(tipX+12, cy); got != wheelBetaSliceColorIndexes[0] {
|
||||
t.Fatalf("pointer body color = %d, want current slice color %d", got, wheelBetaSliceColorIndexes[0])
|
||||
}
|
||||
if got := img.ColorIndexAt(cx+5, tipY); got == 1 {
|
||||
t.Fatalf("pointer tip is too wide at color index %d", got)
|
||||
if got := img.ColorIndexAt(tipX, cy+5); got == 1 {
|
||||
t.Fatalf("pointer tip is too tall at color index %d", got)
|
||||
}
|
||||
if got := img.ColorIndexAt(cx+12, tipY+20); got == 1 {
|
||||
t.Fatalf("pointer widens below wheel edge at color index %d", got)
|
||||
if got := img.ColorIndexAt(tipX-20, cy+12); got == 1 {
|
||||
t.Fatalf("pointer widens inside wheel edge at color index %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWheelOfNamesBeta_FinalSliceRendersAtRightPointer(t *testing.T) {
|
||||
options := []string{"Alice", "Bob", "Carol", "Dana"}
|
||||
winner := 2
|
||||
img := renderWheelBetaFrame(options, winner, finalWheelRotation(len(options), winner), true)
|
||||
x := wheelBetaSize/2 + wheelBetaRadius - 20
|
||||
y := wheelBetaSize / 2
|
||||
want := wheelBetaSliceColorIndexes[winner%len(wheelBetaSliceColorIndexes)]
|
||||
if got := img.ColorIndexAt(x, y); got != want {
|
||||
t.Fatalf("right pointer slice color = %d, want winner slice color %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ const (
|
||||
wheelBetaHoldDelay = wheelBetaSpinDelay
|
||||
wheelBetaDuration = wheelBetaSpinDuration + wheelBetaHoldDuration
|
||||
wheelBetaCelebrateFrames = 8
|
||||
wheelBetaPointerAngle = 0.0
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -133,7 +134,7 @@ func renderWheelBetaFrameWithCelebration(options []string, winner int, rotation
|
||||
drawWheelSliceLabels(img, options, rotation)
|
||||
drawCircle(img, cx, cy, 24, wheelBetaPaperColorIndex)
|
||||
drawCircle(img, cx, cy, 18, wheelBetaInkColorIndex)
|
||||
drawPointer(img, cx, cy-wheelBetaRadius, pointerColor)
|
||||
drawPointer(img, cx+wheelBetaRadius, cy, pointerColor)
|
||||
drawCenteredText(img, "WHEELOFNAMES BETA", cy+wheelBetaRadius+34, wheelBetaInkColorIndex)
|
||||
label := status
|
||||
if label == "" {
|
||||
@@ -154,12 +155,12 @@ func finalWheelRotation(optionCount, winner int) float64 {
|
||||
|
||||
func finalWheelRotationWithOffset(optionCount, winner int, sliceOffset float64) float64 {
|
||||
segment := 2 * math.Pi / float64(optionCount)
|
||||
return -math.Pi/2 - (float64(winner)+0.5+sliceOffset)*segment
|
||||
return wheelBetaPointerAngle - (float64(winner)+0.5+sliceOffset)*segment
|
||||
}
|
||||
|
||||
func currentWheelBetaIndex(optionCount int, rotation float64) int {
|
||||
segment := 2 * math.Pi / float64(optionCount)
|
||||
return int(normalizeAngle(-math.Pi/2-rotation) / segment)
|
||||
return int(normalizeAngle(wheelBetaPointerAngle-rotation) / segment)
|
||||
}
|
||||
|
||||
func normalizeAngle(theta float64) float64 {
|
||||
|
||||
@@ -130,22 +130,22 @@ func drawCircleOutline(img *image.Paletted, cx, cy, radius, thickness int, color
|
||||
}
|
||||
}
|
||||
|
||||
func drawPointer(img *image.Paletted, cx, tipY int, fillColorIndex byte) {
|
||||
for y := 0; y < 34; y++ {
|
||||
half := y / 2
|
||||
rowY := tipY - y
|
||||
for x := cx - half; x <= cx+half; x++ {
|
||||
setWheelBetaPixel(img, x, rowY, wheelBetaInkColorIndex)
|
||||
func drawPointer(img *image.Paletted, tipX, cy int, fillColorIndex byte) {
|
||||
for xOffset := 0; xOffset < 34; xOffset++ {
|
||||
half := xOffset / 2
|
||||
x := tipX + xOffset
|
||||
for y := cy - half; y <= cy+half; y++ {
|
||||
setWheelBetaPixel(img, x, y, wheelBetaInkColorIndex)
|
||||
}
|
||||
}
|
||||
for y := 3; y < 30; y++ {
|
||||
half := y/2 - 2
|
||||
for xOffset := 3; xOffset < 30; xOffset++ {
|
||||
half := xOffset/2 - 2
|
||||
if half < 0 {
|
||||
continue
|
||||
}
|
||||
rowY := tipY - y
|
||||
for x := cx - half; x <= cx+half; x++ {
|
||||
setWheelBetaPixel(img, x, rowY, fillColorIndex)
|
||||
x := tipX + xOffset
|
||||
for y := cy - half; y <= cy+half; y++ {
|
||||
setWheelBetaPixel(img, x, y, fillColorIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user