Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def clear(np):
- for i in range(np.n):
- np[i] = (0, 0, 0)
- np.write()
- def white(np, brightness=255):
- for i in range(np.n):
- np[i] = (brightness, brightness, brightness)
- np.write()
- def demo(np):
- import utime
- n = np.n
- # cycle
- for i in range(4 * n):
- for j in range(n):
- np[j] = (0, 0, 0)
- np[i % n] = (255, 255, 255)
- np.write()
- utime.sleep_ms(25)
- # bounce
- for i in range(4 * n):
- for j in range(n):
- np[j] = (0, 0, 128)
- if (i // n) % 2 == 0:
- np[i % n] = (0, 0, 0)
- else:
- np[n - 1 - (i % n)] = (0, 0, 0)
- np.write()
- utime.sleep_ms(60)
- # fade in/out
- for i in range(0, 4 * 256, 8):
- for j in range(n):
- if (i // 256) % 2 == 0:
- val = i & 0xff
- else:
- val = 255 - (i & 0xff)
- np[j] = (val, 0, 0)
- np.write()
- # clear
- for i in range(n):
- np[i] = (0, 0, 0)
- np.write()
- def slide(np):
- import utime
- position = 0
- add = False
- while True:
- position += 1
- n = np.n
- if position > n:
- position = 0
- brightness = 255
- for i in range(n):
- pos = i + position
- if pos >= n:
- pos = pos - n
- np[pos] = (brightness, brightness, brightness)
- if brightness < 10:
- add = True
- elif brightness > 250:
- add = False
- if add:
- brightness += 10
- else:
- brightness -= 10
- np.write()
- utime.sleep_ms(10)
- def gradient_light(np, position=0):
- color = [122, 255, 0]
- value = 255/np.n*2
- add = [True, False, True]
- for pos in range(np.n):
- for i in range(len(color)):
- if color[i] < 10:
- add[i] = True
- elif color[i] > 245:
- add[i] = False
- if add[i]:
- color[i] += value
- else:
- color[i] -= value
- if position+pos >= np.n:
- pos = pos - np.n
- np[position+pos] = tuple(int(i) for i in color)
- np.write()
- def gradient_light(np, position=0):
- color = [122, 255, 0]
- value = 255/np.n*2
- add = [True, False, True]
- for pos in range(np.n):
- for i in range(len(color)):
- if color[i] < value:
- add[i] = True
- elif color[i] > 255-value:
- add[i] = False
- if add[i]:
- color[i] += value
- else:
- color[i] -= value
- if position+pos >= np.n:
- pos = pos - np.n
- np[position+pos] = tuple(int(i) for i in color)
- np.write()
- def gradient_colorfull(np, position=0):
- r = 255
- g = 0
- b = 0
- value = 255/np.n*3
- r_add = -1
- g_add = +1
- b_add = 0
- for pos in range(np.n):
- if r < value and r_add == -1:
- r_add = 0
- elif r > 255-value and r_add == +1:
- r_add = -1
- g_add = +1
- if g < value and g_add == -1:
- g_add = 0
- elif g > 255-value and g_add == +1:
- g_add = -1
- b_add = +1
- if b < value and b_add == -1:
- b_add = 0
- elif b > 255-value and b_add == +1:
- b_add = -1
- r_add = +1
- r += r_add * value
- g += g_add * value
- b += b_add * value
- if position+pos >= np.n:
- pos = pos - np.n
- np[position+pos] = (int(r), int(g), int(b))
- np.write()
- def color_slide(np, gradient_f=gradient_colorfull):
- import utime
- position = 0
- n = np.n
- while True:
- position += 1
- if position > n:
- position = 0
- gradient_f(np, position=position)
- utime.sleep_ms(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement