{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Gallery" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib widget" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import HBox, VBox, Output, Label" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "url = \"https://raw.githubusercontent.com/gbrault/jupytersketches/master/\"" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "26e6eccfb7b749e3882da260f9579fb5", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gallery = Output()\n", "gallery" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "from pysketcher import *" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import time" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from IPython.display import HTML, SVG, display, clear_output" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "files = [(\"dryfriction\",\"friction\"),(\"pendulum\",\"pendulum\"),(\"car\",\"car\"),(\"springmass\",\"springmass\"),\n", " (\"springdashpotmass\",\"springdashpotmass\"),(\"jet_pump\",\"jet_pump\")]" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "i = 0\n", "horiz = []\n", "vert = []\n", "outputs = [Output() for file in files]\n", "for output in outputs:\n", " if i == 3:\n", " vert.append(HBox(horiz))\n", " horiz = [output]\n", " i = 0\n", " else:\n", " i += 1\n", " horiz.append(output)\n", "if i >= 0 and i < 3:\n", " vert.append(HBox(horiz))\n", "with gallery:\n", " display(VBox(vert))\n", "\n", "i = 0\n", "for file in files:\n", " sketch = Sketch({})\n", " sketch.url2Sketch(url + file[0] +\".yml\")\n", " drawing_tool.erase()\n", " sketch.container[file[1]].draw()\n", " with outputs[i]:\n", " clear_output(wait=True)\n", " display(HTML(f\"

{file[0]}

\"),SVG(Sketch.matplotlib2SVG()))\n", " i += 1\n", " time.sleep(0.1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }