def simple_2d(seed=13, num_particles=2): np.random.seed(seed) positions = np.random.uniform(0, 3, (num_particles, 2)) colors = np.random.rand(num_particles, 4) orientations = np.random.rand(num_particles, 4) orientations[:, 1:3] = 0 orientations /= np.linalg.norm(orientations, axis=-1, keepdims=True) thetas = np.linspace(0, 2*np.pi, 5, endpoint=False) vertices = np.array([np.cos(thetas), np.sin(thetas)]).T prim1 = draw.Arrows2D(positions=positions, colors=colors*.5, orientations=orientations, magnitudes=[.25, .5]) prim1.vertices = prim1.vertices - (-.5, 0) prim2 = draw.Disks(outline=.05, positions=positions, colors=colors, diameters=np.ones((num_particles,))) prim3 = draw.Polygons(positions=-positions, colors=colors, vertices=vertices, outline=.05, orientations=orientations) prim4 = draw.Spheropolygons(positions=-positions, colors=colors, vertices=vertices, outline=.05, orientations=orientations) prim4.radius = .1 prim4.positions = prim3.positions + (3, 2) scene = draw.Scene([prim2, prim3, prim4, prim1], zoom=4, features=dict(pan=True)) return scene
def sunflower_2d(seed=13): center_disk = draw.Disks(outline=.05, positions=np.zeros((1, 2)), colors=np.array([0.225, 0.1, 0., 1]), diameters=np.sqrt(3)) thetas = np.linspace(0, 2*np.pi, 6, endpoint=False) vertices = np.array([np.cos(thetas), np.sin(thetas)]).T orientations = np.array([[np.cos(np.pi/12), 0, 0, np.sin(np.pi/12)]] * 6) petals = draw.Polygons(positions=np.sqrt(3)*vertices, colors=np.array([[0.9, 0.7, 0, 1]]*6), vertices=vertices, outline=.05, orientations=orientations) """ prim2 = draw.Disks(outline=.05, positions=positions, colors=colors, diameters=np.ones((num_particles,))) prim3 = draw.Polygons(positions=-positions, colors=colors, vertices=vertices, outline=.05, orientations=orientations) """ scene = draw.Scene([center_disk, petals], zoom=4, features=dict(pan=True)) return scene
def concave_2d(seed=16, num_particles=3): np.random.seed(seed) positions = np.random.uniform(0, 6, (num_particles, 2)) colors = np.random.rand(num_particles, 4) colors[:, 3] = 1 angles = np.random.uniform(0, 2 * np.pi, num_particles) thetas = np.linspace(0, 2 * np.pi, 7, endpoint=False) rs = [.1, .5, .5, .2, .5, .5, .5] vertices = np.array([rs * np.cos(thetas), rs * np.sin(thetas)]).T prim1 = draw.Polygons(positions=positions, colors=colors, angles=angles, vertices=vertices) prim2 = draw.Spheropolygons(radius=.1, colors=colors, angles=angles, vertices=vertices) prim2.positions = -prim1.positions scene = draw.Scene([prim1, prim2], zoom=4, features=dict(pan=True)) return scene