Better Programming

Advice for programmers.

Follow publication

Member-only story

Create Beautiful Programmatic Random Drawing Easily With Perlin Noise in Jetpack Compose

Making beautiful art under 40 lines of code using Perlin Noise

Elye - A One Eye Dev By His Grace
Better Programming
Published in
4 min readDec 8, 2021
Photo by Benjamin Voros on Unsplash

Random numbers are useful for many things. However, sometimes they are too random. We want to draw something which is smooth programmatically like below:

Here I will try to explain what Perlin Noise is, and also explore the code that generates the above wavey animation above.

What is Perlin Noise?

A random value is having a parameter of min and max. If we plot it, between 0 and height, 1 for each X pixel, it will look like below, all over the place.

for (x in 0 until width) {
val drawHeight = height - (0..height)
drawPoints(
listOf(Offset(x, drawHeight)),
PointMode.Points,
Color.WHITE,
2f
)
}

Perlin Noise is a function with 1, 2, or 3 parameters, depending on how many…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Elye - A One Eye Dev By His Grace
Elye - A One Eye Dev By His Grace

Written by Elye - A One Eye Dev By His Grace

Sharing Software Learning, Life and Faith Journey

No responses yet

Write a response