| 1 |
""" |
| 2 |
Create Our Logo |
| 3 |
~~~~~~~~~~~~~~~ |
| 4 |
|
| 5 |
Think our logo is awesome? Create it yourself! |
| 6 |
""" |
| 7 |
# sphinx_gallery_thumbnail_number = 2 |
| 8 |
import pyvista |
| 9 |
import numpy as np |
| 10 |
|
| 11 |
############################################################################### |
| 12 |
|
| 13 |
# mesh for each letter |
| 14 |
space = 0.3 |
| 15 |
mesh_letters = pyvista.MultiBlock() |
| 16 |
width = 0 |
| 17 |
density = 0.03 |
| 18 |
for letter in 'pyvista': |
| 19 |
mesh_letter = pyvista.Text3D(letter, depth=0.3) |
| 20 |
this_letter_width = mesh_letter.points[:, 0].max() |
| 21 |
mesh_letter.translate([width + space, 0, 0.0], inplace=True) |
| 22 |
width += this_letter_width |
| 23 |
mesh_letters[letter] = mesh_letter |
| 24 |
|
| 25 |
grid = pyvista.voxelize(pyvista.Text3D('pyvista'), 0.05) |
| 26 |
grid.plot(color='w', show_edges=True) |
| 27 |
|
| 28 |
############################################################################### |
| 29 |
|
| 30 |
v_grid = pyvista.voxelize(mesh_letters['v'], density=0.03) |
| 31 |
t_grid = pyvista.voxelize(mesh_letters['t'], density=0.07) |
| 32 |
k_grid = pyvista.voxelize(mesh_letters['k'], density=0.08) |
| 33 |
i_grid = pyvista.voxelize(mesh_letters['i'], 0.05) |
| 34 |
|
| 35 |
v_mesh = v_grid.triangulate().extract_geometry().decimate_pro(0.9) |
| 36 |
|
| 37 |
############################################################################### |
| 38 |
|
| 39 |
# plot letters |
| 40 |
plotter = pyvista.Plotter(window_size=np.array([1024, 512]) * 2) |
| 41 |
|
| 42 |
# Add the V |
| 43 |
plotter.add_mesh(v_mesh, color='w', show_edges=True) |
| 44 |
|
| 45 |
# Add the T |
| 46 |
plotter.add_mesh(t_grid.extract_surface(), |
| 47 |
style='points', color='r', render_points_as_spheres=True, |
| 48 |
point_size=12) |
| 49 |
plotter.add_mesh(t_grid, style='wireframe', color='k', line_width=3, ) |
| 50 |
|
| 51 |
|
| 52 |
# Add the K |
| 53 |
# isolate the cells of k_grid |
| 54 |
# cells = [] |
| 55 |
x_min, x_max, y_min, y_max, z_min, z_max = k_grid.bounds |
| 56 |
x_width = x_max - x_min |
| 57 |
x_move = 2.1 |
| 58 |
spread = 1.4 |
| 59 |
x_mean, y_mean, z_mean = k_grid.points.mean(0) |
| 60 |
keep = [] |
| 61 |
scalars = [] |
| 62 |
# as x in increases, k cells will shift outward |
| 63 |
for i in range(k_grid.n_cells): |
| 64 |
cell = k_grid.extract_cells([i]) |
| 65 |
orig_cell = cell.copy() |
| 66 |
x_dist = np.mean(cell.bounds[:2]) |
| 67 |
fac = x_dist - x_move |
| 68 |
x_shift = 0 |
| 69 |
y_dist = np.mean(cell.bounds[2:4]) |
| 70 |
z_dist = np.mean(cell.bounds[4:]) - z_mean |
| 71 |
if fac > 0: |
| 72 |
fac = fac**1.5 |
| 73 |
cell.translate([x_shift, y_dist*fac*spread, z_dist*fac*spread], inplace=True) |
| 74 |
# cells.append(cell) |
| 75 |
|
| 76 |
opacity = (x_max - x_dist)/x_width |
| 77 |
if opacity > 0.5: |
| 78 |
keep.append(i) |
| 79 |
scalars.append(x_dist + 0.2) |
| 80 |
# plotter.add_mesh(orig_cell, style='surface', color='w', cmap='Greys_r', |
| 81 |
# scalars=[x_dist + 0.2], rng=[x_min, x_max], |
| 82 |
# show_edges=True) |
| 83 |
else: |
| 84 |
# opacity = opacity |
| 85 |
plotter.add_mesh(cell, color='w', show_edges=True, opacity=opacity) |
| 86 |
|
| 87 |
keep_k = k_grid.extract_cells(keep) |
| 88 |
plotter.add_mesh(keep_k, scalars=scalars, cmap='Greys_r', rng=[x_min, x_max], |
| 89 |
show_edges=True) |
| 90 |
|
| 91 |
|
| 92 |
# Add the I |
| 93 |
plotter.add_mesh(i_grid, color='w', style='wireframe', line_width=3, |
| 94 |
scalars=i_grid.points[:, 1], cmap='bwr') |
| 95 |
|
| 96 |
# Show |
| 97 |
plotter.set_background('white') |
| 98 |
|
| 99 |
plotter.camera_position = [(0.124, 1.100, 3.338), |
| 100 |
(1.716, 0.379, 0.143), |
| 101 |
(0.091, 0.980, -0.176)] |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
save_it = False |
| 106 |
if save_it: |
| 107 |
plotter.show(auto_close=False) |
| 108 |
plotter.screenshot('pyvista_logo.png', transparent_background=True) |
| 109 |
plotter.close() |
| 110 |
else: |
| 111 |
plotter.show() |