Skip to content

Commit

Permalink
Add star shape type
Browse files Browse the repository at this point in the history
  • Loading branch information
zadeviggers committed Apr 15, 2024
1 parent 4f6ead3 commit b031ebe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/src/main/java/net/viggers/zade/wallpaper/WallpaperService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,17 @@ class WallpaperService : WallpaperService() {
angle
)

"star" -> drawPolygon(
canvas,
paint,
x,
y,
size,
10f,
angle,
true
)

else -> canvas.drawCircle(x, y, size, paint)
}
}
Expand All @@ -423,11 +434,13 @@ class WallpaperService : WallpaperService() {
radius: Float,
sides: Float,
startAngle: Float,
starMode: Boolean = false
) {
// From https://stackoverflow.com/a/36792553
if (sides < 3) {
return
}
val innerRadius = radius * 0.4f
val a = Math.PI.toFloat() * 2 / sides
mCanvas.save()
mCanvas.translate(x, y)
Expand All @@ -436,10 +449,13 @@ class WallpaperService : WallpaperService() {
path.moveTo(radius, 0f)
var i = 1
while (i < sides) {
val pointRadius = if (starMode && i % 2 != 0) innerRadius else radius;

path.lineTo(
radius * cos((a * i).toDouble()).toFloat(),
radius * sin((a * i).toDouble()).toFloat()
pointRadius * cos((a * i).toDouble()).toFloat(),
pointRadius * sin((a * i).toDouble()).toFloat()
)

i++
}
path.close()
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<item>@string/shape_option_label_triangle</item>
<item>@string/shape_option_label_pentagon</item>
<item>@string/shape_option_label_hexagon</item>
<item>@string/shape_option_label_star</item>
</array>

<array name="shape_types">
Expand All @@ -14,6 +15,7 @@
<item>triangle</item>
<item>pentagon</item>
<item>hexagon</item>
<item>star</item>
</array>

<string-array name="colourPalette" translatable="false">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@
<string name="enable_random_shape_rotations_preference_title">Rotate shapes randomly</string>
<string name="enable_random_shape_rotations_preference_summary">Shapes will spawn with random rotation. You probably won\'t notice this with circles though.</string>
<string name="none_selected_multiselect_input_toast">Select at least one option</string>
<string name="shape_option_label_star">Star</string>
</resources>

0 comments on commit b031ebe

Please sign in to comment.