{ "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": [ { "output_type": "display_data", "data": { "text/plain": "Output()", "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "52ea7cdf6d824834862f556af8859788" } }, "metadata": {} } ], "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\"),\n", " (\"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", " link = f\"

{file[0]}

\"\n", " with outputs[i]:\n", " clear_output(wait=True)\n", " display(HTML(link),\n", " 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" } }, "nbformat": 4, "nbformat_minor": 4 }