.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/Geometry/plot_xcellLogo.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_Geometry_plot_xcellLogo.py: Logo ============= Generates the xc logo from point cloud Original text layout in Inkscape, text bounds resampled using Roughen path effect with all displacements=0, then exported with Path to Gcode extension. Original canvas bounds are ((0,32), (0,32)) .. GENERATED FROM PYTHON SOURCE LINES 13-34 .. code-block:: default import xcell as xc import pandas import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import ArtistAnimation import re import pickle import time csv = 'pts.csv' ptsFile = 'logo.xpts' convertGcode = False showOriginalPoints = False bbox = np.array([0, 0, -32, 32, 32, 32]) xc.colors.use_dark_style() color = 'base' logoFPS = 6 .. GENERATED FROM PYTHON SOURCE LINES 35-38 Convert gcode to array of points --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 38-56 .. code-block:: default if convertGcode: f = open('xcdense.ngc', 'r') txt = f.read() f.close() regex = re.compile('X.*Y[\d\.]*') txtpts = regex.findall(txt) ctext = open(csv, 'w') extract = ',0.0\n'.join(txtpts) ctext.write(extract.replace('Y', '').replace('X', '').replace(' ', ',')) ctext.close() pts = pandas.read_csv(csv).to_numpy() okPts = ~np.any(np.isnan(pts), axis=1) pickle.dump(pts[okPts], open(ptsFile, 'wb')) .. GENERATED FROM PYTHON SOURCE LINES 57-60 Generate meshes from points --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 60-90 .. code-block:: default pts = pickle.load(open(ptsFile, 'rb')) tstart = time.monotonic() setup = xc.Simulation('', bbox) meshPts = [] artists = [] npts = pts.shape[0] for d in range(0, 12): depths = d*np.ones(npts, dtype=int) co = np.ones(npts) setup.make_adaptive_grid(ref_pts=pts, max_depth=depths, coefs=co, min_l0_function=xc.general_metric, coarsen=False) setup.finalize_mesh() _, _, elPts = setup.get_elements_in_plane() meshPts.append(elPts) t_tot = time.monotonic()-tstart pickle.dump(meshPts, open('logoMesh.p', 'wb')) .. GENERATED FROM PYTHON SOURCE LINES 91-94 Make logo image and animation ------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 94-131 .. code-block:: default dpi = 100 with plt.rc_context({'figure.figsize': [19.2, 10.8], 'figure.dpi': dpi, 'toolbar': 'None', }): fig, ax = plt.subplots() ax.set_xlim(1., 31.) ax.set_ylim(1., 23.) ax.axis('Off') ax.margins(0) col = xc.colors.BASE artists = [[xc.visualizers.show_2d_edges( ax, p, edge_colors=col, alpha=0.2, linewidth=1.5)] for p in meshPts[:13]] # pad ending frame artists.append(artists[-1]) artists.append(artists[-1]) ani = ArtistAnimation( fig, artists, interval=1000//logoFPS) outFile = 'logo' ani.save(outFile+'.mp4', fps=logoFPS, dpi=dpi) fig.savefig(outFile+'.svg', dpi=dpi) tlogo = len(artists)/logoFPS print('%.2f second logo made in %.0f seconds' % (tlogo, t_tot)) if showOriginalPoints: # Optionally visualize guide points x, y, _ = np.hsplit(pts, 3) plt.scatter(x, y) .. container:: sphx-glr-animation .. raw:: html
.. rst-class:: sphx-glr-script-out .. code-block:: none 2.33 second logo made in 40 seconds .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 44.740 seconds) .. _sphx_glr_download_auto_examples_Geometry_plot_xcellLogo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_xcellLogo.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_xcellLogo.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_