Skip to content

Instantly share code, notes, and snippets.

@ymollard
Created October 13, 2016 16:39
Show Gist options
  • Save ymollard/59dc49b39dbefeedf058d6352d6b9c83 to your computer and use it in GitHub Desktop.
Save ymollard/59dc49b39dbefeedf058d6352d6b9c83 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import numpy as np\n",
"import math"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def polar_to_cartesian(a, r):\n",
" a = math.radians(a)\n",
" return (np.cos(a) * r, np.sin(a) * r)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def write_circle(f, nb_cut, size_cut, radius, offset):\n",
" arc_list = []\n",
" inter = 360. / nb_cut\n",
" for i_cut in range(nb_cut):\n",
" arc_list.append((offset + inter * i_cut + size_cut, offset + inter * (i_cut + 1)))\n",
" for arc in arc_list:\n",
" start = polar_to_cartesian(arc[0], radius)\n",
" end = polar_to_cartesian(arc[1], radius)\n",
" f.write('M{0},{1} m {2},{3} a{4},{4} -40 0,1 {5},{6} '.format(size[0] / 2, size[1]/2, start[0], start[1], radius,\n",
" end[0] - start[0], end[1] - start[1]))"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"nb_cut = 7\n",
"size_cut = 0.5\n",
"radius = 60\n",
"start_radius = 70.\n",
"max_radius = 230.\n",
"nb_circles = 300\n",
"size = (500, 500)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"with open(\"tmp.svg\", \"w\") as f:\n",
" f.write('<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"{}\" width=\"{}\">'.format(size[0], size[1]))\n",
" f.write('<path d=\"')\n",
" for i in range(nb_circles):\n",
" write_circle(f, 16, 5, start_radius + (max_radius - start_radius) / nb_circles * i, (i % 2) * 360. / 32 )\n",
" f.write('\" fill=\"none\" stroke=\"red\" stroke-width=\"0.1\"/>')\n",
" f.write('</svg>')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 18
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment