[PYTHON] Manim's method 5

Overview

I checked manim's method. I tried using Clock.

Sample code

from manimlib.imports import *

def rev_to_rgba(alpha):
	alpha = (0.5 - alpha) % 1
	hue_list = [0, 0.5 / 6.0, 1 / 6.0, 1.1 / 6.0, 2 / 6.0, 3 / 6.0, 4 / 6.0, 5 / 6.0]
	num_hues = len(hue_list)
	start_index = int(np.floor(num_hues * alpha)) % num_hues
	end_index = (start_index + 1) % num_hues
	beta = (alpha % (1.0 / num_hues)) * num_hues
	start_hue = hue_list[start_index]
	end_hue = hue_list[end_index]
	if end_hue < start_hue:
		end_hue = end_hue + 1
	hue = interpolate(start_hue, end_hue, beta)
	return color_to_rgba(Color(hue = hue, saturation = 1, luminance = 0.5))

def rev_to_color(alpha):
	return rgba_to_color(rev_to_rgba(alpha))

class test(Scene):
	CONFIG = {
		"run_time" : 90,
	}
	def construct(self):
		clock = Clock()
		clock.set_height(FRAME_HEIGHT - 1)
		clock.to_edge(LEFT)
		lines = [clock.hour_hand, clock.minute_hand]
		def update_line(line):
			rev = line.get_angle() / TAU
			line.set_color(rev_to_color(rev))
		for line in lines:
			self.add(Mobject.add_updater(line, update_line))
		run_time = self.run_time
		self.play(ClockPassesTime(clock, run_time = run_time, hours_passed = 0.1 * run_time))




Generated video

https://www.youtube.com/watch?v=04gvK-94CJ0

that's all.

Recommended Posts

Manim's method 7
Manim's method 13
Manim's method 2
Manim's method 18
Manim's method 17
Manim's method 5
Manim's method 3
Manim's method 15
Manim's method 11
Manim's method 16
Manim's method 20
Manim's method 10
Manim's method 9
Manim's method 6
Manim's method 21
Manim's method 4
Manim's method 8
Manim's method 14
Manim's method 22
Manim's method 19
Manim's method 12
Manim's method part 23
Binary method
Special method
Special method
Understand k-means method
Clustering of clustering method
Dictionary items method
[PyTorch] Installation method
N cross method
Image collection method
Regression analysis method
Gradient method implementation 1
Python-peewee connection method
Class method static method
youtube-dl update method
Monte Carlo method
Mode-Matching Method Simulation_Python
Johnson method (python)
[Python] Semi-Lagrange method