Created
February 9, 2023 20:36
-
-
Save todbot/58bcf7ea3a85aede3f951f8176e3aad5 to your computer and use it in GitHub Desktop.
Play with simplex noise in CircuitPython
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# noise_square_code.py -- playing with simplex noise in CircuitPython | |
# 9 Feb 2023 - @todbot / Tod Kurt | |
# https://github.com/todbot/CircuitPython_Noise | |
# Uses Lolin ESP32-S2 Mini and 8x8 LED shield | |
# https://circuitpython.org/board/lolin_s2_mini/ | |
# | |
import time | |
import board | |
import neopixel | |
import rainbowio | |
import noise | |
leds = neopixel.NeoPixel(board.IO16, 64, brightness=0.1, pixel_order=neopixel.RGB, auto_write=False) | |
leds.fill(0xff00ff) # say hello | |
noise_scale = 0.1 | |
noise_x = 0 | |
noise_y = 0 | |
while True: | |
for i in range(8): # for each pixel row | |
for j in range(8): # for each pixel column | |
# get a noise value in 2D noise space | |
n = noise.noise( noise_x + noise_scale*i, noise_y + noise_scale*j ) | |
c = int((n+1) * 255) # scale it from -1-1 -> 0-255 | |
leds[j*8+i] = rainbowio.colorwheel(c) # convert to hue | |
leds.show() | |
noise_y += 0.01 # slide down in noise space | |
time.sleep(0.01) |
Another example from the repo: https://github.com/todbot/CircuitPython_Noise
import time
from noise import noise
i = 0
while True:
n = noise(0.02 * i) # get a 1D noise value
i += 1
# print a random terrain with asterisks
print(" " * int(max(n + 1, 0) * 40), "*")
time.sleep(0.01)
which makes a really nice terrain-like output to the terminal
simplex_noise_terminal_demo.mp4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo video of this code:
noise_square_code_demo.mp4