What nobody asked for, now in your hands (and Maven)!
This library includes the standalone functions for Composable Sheep, Composable Fluff and Loading Sheep.
ComposableSheep | ComposableFluff | LoadingSheep |
---|---|---|
Disclaimer: No animations have been migrated from the orignal Composable Sheep, yet.
Just add the dependency in your common module build.gradle
file. Currently supported: Android, iOS & desktop (no wasm!).
commonMain.dependencies {
implementation("dev.nstv:composablesheep:1.0.0")
}
Just add the dependency in your module build.gradle
file.
dependencies {
implementation("dev.nstv:composablesheep:1.0.0")
}
ComposableSheep use Canvas under the hood!
It's mandatory to specify the size strategy of the composables (size, fillMaxSize,...)
In order to add sheep everywhere, you only need to provide a modifier with a size strategy defined, like size(). This will create a sheep with a randomized fluff color.
ComposableSheep(
modifier = Modifier.size(300.dp),
)
If you want more control of your sheep, and don't want to create a random one every time, you can always remember it and pass it along.
val sheep = remember { Sheep() }
ComposableSheep(
modifier = Modifier.size(300.dp),
sheep = sheep
)
Composable Sheep can also be drawn using drawComposableSheep extension function
Box(modifier = Modifier.size(300.dp)
.drawBehind {
drawComposableSheep(sheep = sheep)
}
)
Renders a spinning ComposableSheep. For a best result, defining the composable size strategy is recommended.
LoadingSheep(
modifier = Modifier.size(300.dp),
spinning = true,
fluffColor = sheep.fluffColor
)
If a Sheep is too much to handle, you have the option of only adding the Fluff
ComposableFluff(
modifier = Modifier.size(300.dp),
)
In order to make them more flexible, the colors can be edited independently of the sheep model. This make it easy to "temporary" override colors, keeping the original sheep intact.
ComposableSheep(
modifier = Modifier.size(300.dp),
sheep = sheep,
fluffColor = Color.Black,
headColor = Color.LightGray,
legColor = Color.Yellow,
eyeColor = Color.Red,
glassesColor = Color.Magenta,
)
If you want to take a more creative approach, the fluff can also be defined using a Brush
ComposableSheep(
modifier = Modifier.size(300.dp),
fluffBrush = radialGradient(colors = listOf(Color.Black, Color.Yellow)),
)
The Sheep model contains both the base colors and fluff style used to build a ComposableSheep. You can modify all the values to craft the sheep of your dreams from the beginning!
data class Sheep(
val fluffStyle: FluffStyle = FluffStyle.Random(),
val headAngle: Float = DefaultHeadRotationAngle,
val glassesTranslation: Float = 0f,
val legs: List<Leg> = twoLegsStraight(),
val fluffColor: Color = SheepColor.random(),
val headColor: Color = SheepColor.Skin,
val legColor: Color = headColor,
val eyeColor: Color = SheepColor.Eye,
val glassesColor: Color = SheepColor.Black
)
FluffStyle is used to define the style of the fluff, how each of the fluff chunks (each "bump") are built. Each fluff chunk takes a percentage of the full circle to built its angle. The bigger the percentage, the bigger the fluff chunk will be.
The different types of fluffy styles are:
Uniform (default)
The fluff is divided into a number of chunks of equal size.ComposableSheep(
modifier = Modifier.size(300.dp),
sheep = Sheep(fluffStyle = FluffStyle.Uniform(numberOfFluffChunks = 10))
)
numberOfFluffChunks
represents how many fluff chunks (each "bump") the final fluff will have. In this example, I'm defining a size of 10, meaning that the final body will have 10 fluff chunks of 10% (100%/10) of the body each. In angles, each chunk takes 360°/10 = 36° degrees.
UniformIntervals
The fluff is divided into a number of chunks of iterating size according to the given intervals.
ComposableSheep(
modifier = Modifier.size(300.dp),
sheep = Sheep(
fluffStyle = FluffStyle.UniformIntervals(
percentageIntervals = listOf(5.0, 15.0)
)
)
)
percentageIntervals
represents the sequence of percentages the fluff chunks will follow. It will repeat the sequence until the 100% of the fluff is drawn.
Random
The fluff is divided into a number of chunks of random size.ComposableSheep(
modifier = Modifier.size(300.dp),
sheep = Sheep(
fluffStyle = FluffStyle.Random(
minPercentage = 10.0,
maxPercentage = 20.0
)
)
)
minPercentage
&maxPercentage
represent the range that each fluff chunk can take.
Manual
The fluff is divided into a number of chunks of size defined by the user.
ComposableSheep(
modifier = Modifier.size(300.dp),
sheep = Sheep(
fluffStyle = FluffStyle.Manual(
fluffChunksPercentages = listOf(5.0, 15.0, 10.0, 20.0, 50.0)
)
)
)
fluffChunksPercentages
represents the percentages the fluff chunks will follow. It will not repeat the sequence and will create a final chunk with the leftover percentage if needed. For the best results, ensure tht the percentages add up to 100%.
You can potentially define how the legs should be built. Two helper functions are already provided:
twoLegsStraight (default)
ComposableSheep(
modifier = Modifier.size(300.dp),
sheep = Sheep(
legs = twoLegsStraight()
)
)
Most functions accept the optional flag to showGuidelines. In case you want to take a look at the shapes being used, just change the value to true!
ComposableSheep(
modifier = Modifier.size(300.dp),
showGuidelines = true,
)
If you're interested in learning more about the Sheep or want some inspiration about what to do with them, take a look at the original Composable Sheep Repository!
Copyright 2024 Nicole Terc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.