def path(path_func, p_range, path_length="auto"): return hl.ParaObject2(path_func, region_params={ 'path_range': p_range, 'path_length': path_length }, species="path")
def circle_primitive(r, c): return hl.ParaObject2(circle_parametric(r, c), region_params={ 'path_range': (0, 2 * math.pi), 'path_length': 2 * math.pi * r }, species='circle')
def textured_path(texture, pos, polarization, path, p_range, path_length): def f(p): return tuple( np.add((texture(p - pos) * np.asarray(polarization)), path(p))) return hl.ParaObject2(f, region_params={ 'path_range': p_range, 'path_length': path_length }, species='textured_path')
def arrow(p0, direction, length=None, head_length=0, centered=False): arw = hl.Group(species='arrow') length = np.linalg.norm(direction[0] - direction[1], axis=1) if not length else length direction = np.array(direction, copy=False, dtype=float) direction /= np.linalg.norm(direction) path_range = (-length / 2, length / 2) if centered else (0, length) arw.add_component( hl.ParaObject2(line_parametric(p0, direction[0], direction[1]), region_params={ 'path_range': path_range, 'path_length': length }, species='arrow_body')) if not head_length == 0: arrow_tip_coordinates = np.add(p0, np.asarray(direction) * (length / 2)) arrowhead_dir_1 = np.matmul( hl.rotate(3 * math.pi / 4)[:2, :2], direction) arrowhead_dir_2 = np.matmul( hl.rotate(-3 * math.pi / 4)[:2, :2], direction) arw.add_component( hl.ParaObject2(line_parametric(arrow_tip_coordinates, arrowhead_dir_1[0], arrowhead_dir_1[1]), region_params={ 'path_range': (0, head_length), 'path_length': head_length }, species='arrow_head')) arw.add_component( hl.ParaObject2(line_parametric(arrow_tip_coordinates, arrowhead_dir_2[0], arrowhead_dir_2[1]), region_params={ 'path_range': (0, head_length), 'path_length': head_length }, species='arrow_head')) return arw
def vector(p1, p2): x1, y1 = p1 x2, y2 = p2 x_len = x2 - x1 y_len = y2 - y1 distance = math.hypot(x_len, y_len) return hl.ParaObject2(line_parametric(p1, x_len / distance, y_len / distance), region_params={ 'path_range': (0, distance), 'path_length': distance }, species='vector')
f = lambda u: amplitude * math.sin(frequency * u / (2 * np.pi)) center1 = (0, 0.3) center2 = (0, -0.3) source1 = hl.wave_2(f=f, v=1, source=center1, falloff=0) source2 = hl.wave_2(f=f, v=1, source=center2, falloff=0) superposition = hl.superposition(source1, source2) scene = hl.GrayscaleScene() wave = hl.ParaObject2(f=superposition, region_type="surface", region_params={"a_range": (-10, 10), "b_range": (-10, 10), "a_name": 'x', "b_name": 'y'}, species='wave_superposition') scene.add_object(wave.rotate(theta=math.pi / 2, p=(0, 0)), name='wave') hl._deprecated_video(frame_func=lambda t: scene.render_scene(params={'wave': {'t': t}}, x_range=(-12, 12), y_range=(-12, 12), resolution=20, density=5, white_ref=2.0, black_ref=-2.0, display=False, default=hl.GRAY),