~ubuntu-branches/debian/sid/pyx3/sid

« back to all changes in this revision

Viewing changes to examples/drawing/style.ipynb

  • Committer: Package Import Robot
  • Author(s): Stuart Prescott
  • Date: 2015-05-08 00:00:33 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20150508000033-fp4theggupemhx24
Tags: 0.14-1
* New upstream release.
  - revert upstream change to sphinx conf.py to permit building with older
    python3-sphinx.
* Bump standards version to 3.9.6 (no changes required).
* Add SVG and PDF to package descriptions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
{
2
 
 "metadata": {},
3
 
 "nbformat": 3,
4
 
 "nbformat_minor": 0,
5
 
 "worksheets": [
6
 
  {
7
 
   "cells": [
8
 
    {
9
 
     "cell_type": "heading",
10
 
     "level": 1,
11
 
     "metadata": {},
12
 
     "source": [
13
 
      "Stroke and fill attributes"
14
 
     ]
15
 
    },
16
 
    {
17
 
     "cell_type": "code",
18
 
     "collapsed": false,
19
 
     "input": [
20
 
      "from pyx import *\n",
21
 
      "\n",
22
 
      "c = canvas.canvas()\n",
23
 
      "c.stroke(path.line(0, 0, 4, 0),\n",
24
 
      "         [style.linewidth.THICK, style.linestyle.dashed, color.rgb.red])\n",
25
 
      "c.stroke(path.line(0, -1, 4, -1),\n",
26
 
      "         [style.linewidth(0.2), style.linecap.round, color.rgb.green])\n",
27
 
      "c.fill(path.rect(0, -3, 4, 1), [color.rgb.blue])\n",
28
 
      "c"
29
 
     ],
30
 
     "language": "python",
31
 
     "metadata": {},
32
 
     "outputs": [
33
 
      {
34
 
       "metadata": {},
35
 
       "output_type": "pyout",
36
 
       "png": "iVBORw0KGgoAAAANSUhEUgAAAKUAAAB7CAYAAAAVH0CFAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAA9hAAAPYQGoP6dpAAAAHXRFWHRTb2Z0d2FyZQBHUEwgR2hvc3RzY3JpcHQgOS4wNx2hPKMA\nAAJ6SURBVHic7d3LTRxBGIXRWxYJkAIpOIWJBafgEOwQPCkQAoQAKUwKE8LvBX7wkrzwNHMtnyP1\nokGqKZU+qVW96Fozk1/WukpynW3sM3M4+ahrXSe5Ovm4ySEz+5OPuuUaz3zeZNzt1vguM3ev/joz\nv69kN8lsdO2e/dapruR2o/nebjTf7dZ4i/luu8Zf3vq9DxvUD39FlNQRJXVESZ2LF/fHJK93Q6dx\n3Gjch39s3C3XeCtbrcWbb2PWs1dCUMDjmzqipI4oqSNK6oiSOqKkjiipI0rqiJI6oqSOKKkjSuqI\nkjqipI4oqSNK6oiSOqKkjiipI0rqiJI6oqSOKKkjSuqIkjqipI4oqSNK6oiSOqKkzrPvU66syyQf\nzzQX/l+Hye+TQy6SZGXtknzLNsdSwB+trGOS/WQ+r0x2SW7PPSn44evK5D4e2RRZmfi+NFXsvqnz\nIcnNuScBTxxXJldJ7pNcnns2kOTTmpmf7ye/5HHDY9PDezvk8aye/WTunKNDHRsd6oiSOqKkjiip\nI0rqiJI6oqSOKKkjSuqIkjqipI4oqSNK6oiSOqKkjiipI0rqiJI6oqSOKKkjSuqIkjqipI4oqSNK\n6oiSOqKkjiipI0rqiJI6oqSOKKkjSuqIkjrPz2Zc+ZjHb5/De7qZyf7nzcWLf14m2b3vfCAPT288\nvqkjSuqIkjqipI4oqSNK6oiSOqKkjiipI0rqiJI6oqSOKKkjSuqIkjqipI4oqSNK6oiSOqKkjiip\nI0rqiJI6oqSOKKkjSuqIkjqipI4oqSNK6oiSOqKkjiipI0rqiJI6oqSOKKnz8nSIY5K7c0yE/9rh\n6c2amXNNBN70HRdp1KuC0k96AAAAAElFTkSuQmCC\n"
37
 
      }
38
 
     ]
39
 
    },
40
 
    {
41
 
     "cell_type": "markdown",
42
 
     "metadata": {},
43
 
     "source": [
44
 
      "The previous example anticipated a simple case of setting an attribute when\n",
45
 
      "stroking paths. This example shows a few more use-cases.\n",
46
 
      "\n",
47
 
      "Attributes can be passed in a list as the second optional argument of the\n",
48
 
      "`stroke` or `fill` methods of a canvas instance.  The attributes themselves are\n",
49
 
      "instances of certain attribute classes. A full list is available in the manual.\n",
50
 
      "\n",
51
 
      "In general, some useful attribute instances are predefined as class attributes\n",
52
 
      "of the corresponding attribute class. In the given example, the\n",
53
 
      "`style.linewidth.THICK`, `style.linestyle.dashed`, `style.linecap.round`,\n",
54
 
      "`color.rgb.red`, `color.rgb.green`, and `color.rgb.blue` are just some examples of\n",
55
 
      "this type of attribute instances. In contrast, `style.linewidth(0.2)` creates a\n",
56
 
      "new style instance for the given parameters.\n",
57
 
      "\n",
58
 
      "![bend](http://pyx.sourceforge.net/bend.png)![bend](http://pyx.sourceforge.net/bend.png) The linewidth instance created by `style.linewidth(0.2)` is different from the\n",
59
 
      "predefined linewidth instances in PyX in its use of *user* units. In the example\n",
60
 
      "*Adding and joining paths* of section *Path features*, the linewidth is\n",
61
 
      "scaled independently of the *user* units, but if you try to double all linewidth\n",
62
 
      "by\n",
63
 
      "\n",
64
 
      "    unit.set(wscale=2)\n",
65
 
      "\n",
66
 
      "in the beginning of the script, our self-defined linewidth will not be scaled.\n",
67
 
      "To obtain the proper scaling behaviour it would be necessary to attach the\n",
68
 
      "*width* unit by using\n",
69
 
      "\n",
70
 
      "    style.linewidth(0.2*unit.w_cm)"
71
 
     ]
 
2
 "cells": [
 
3
  {
 
4
   "cell_type": "markdown",
 
5
   "metadata": {},
 
6
   "source": [
 
7
    "# Stroke and fill attributes"
 
8
   ]
 
9
  },
 
10
  {
 
11
   "cell_type": "code",
 
12
   "execution_count": 1,
 
13
   "metadata": {},
 
14
   "outputs": [
 
15
    {
 
16
     "data": {
 
17
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKUAAAB7CAYAAAAVH0CFAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAA9hAAAPYQGoP6dpAAAAHXRFWHRTb2Z0d2FyZQBHUEwgR2hvc3RzY3JpcHQgOS4xNeq0bM4A\nAAJ6SURBVHic7d3LTRxBGIXRWxYJkAIpOIWJBafgEOwQPCkQAoQAKUwKE8LvBX7wkrzwNHMtnyP1\nokGqKZU+qVW96Fozk1/WukpynW3sM3M4+ahrXSe5Ovm4ySEz+5OPuuUaz3zeZNzt1vguM3ev/joz\nv69kN8lsdO2e/dapruR2o/nebjTf7dZ4i/luu8Zf3vq9DxvUD39FlNQRJXVESZ2LF/fHJK93Q6dx\n3Gjch39s3C3XeCtbrcWbb2PWs1dCUMDjmzqipI4oqSNK6oiSOqKkjiipI0rqiJI6oqSOKKkjSuqI\nkjqipI4oqSNK6oiSOqKkjiipI0rqiJI6oqSOKKkjSuqIkjqipI4oqSNK6oiSOqKkzrPvU66syyQf\nzzQX/l+Hye+TQy6SZGXtknzLNsdSwB+trGOS/WQ+r0x2SW7PPSn44evK5D4e2RRZmfi+NFXsvqnz\nIcnNuScBTxxXJldJ7pNcnns2kOTTmpmf7ye/5HHDY9PDezvk8aye/WTunKNDHRsd6oiSOqKkjiip\nI0rqiJI6oqSOKKkjSuqIkjqipI4oqSNK6oiSOqKkjiipI0rqiJI6oqSOKKkjSuqIkjqipI4oqSNK\n6oiSOqKkjiipI0rqiJI6oqSOKKkjSuqIkjrPz2Zc+ZjHb5/De7qZyf7nzcWLf14m2b3vfCAPT288\nvqkjSuqIkjqipI4oqSNK6oiSOqKkjiipI0rqiJI6oqSOKKkjSuqIkjqipI4oqSNK6oiSOqKkjiip\nI0rqiJI6oqSOKKkjSuqIkjqipI4oqSNK6oiSOqKkjiipI0rqiJI6oqSOKKnz8nSIY5K7c0yE/9rh\n6c2amXNNBN70HRdp1KuC0k96AAAAAElFTkSuQmCC\n",
 
18
      "image/svg+xml": [
 
19
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
 
20
       "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"88.3071pt\" fill=\"none\" stroke-miterlimit=\"10.000000\" y=\"-2.26772pt\" x=\"-2.83465pt\" version=\"1.1\" width=\"119.055pt\" stroke-width=\"0.566929\" viewBox=\"-2.83465 -2.26772 119.055 88.3071\">\n",
 
21
       " <g stroke-linecap=\"butt\" stroke-dasharray=\"16.000000\" stroke-width=\"4.535433\" stroke-dashoffset=\"0.000000\">\n",
 
22
       "  <path stroke=\"#f00\" d=\"M0 -0L113.386 -0\"/>\n",
 
23
       " </g>\n",
 
24
       " <g stroke-linecap=\"round\" stroke-width=\"5.669291\">\n",
 
25
       "  <path stroke=\"#0f0\" d=\"M0 28.3465L113.386 28.3465\"/>\n",
 
26
       " </g>\n",
 
27
       " <g>\n",
 
28
       "  <path fill=\"#00f\" d=\"M0 85.0394L113.386 85.0394L113.386 56.6929L0 56.6929Z\"/>\n",
 
29
       " </g>\n",
 
30
       "</svg>\n"
 
31
      ]
 
32
     },
 
33
     "execution_count": 1,
 
34
     "metadata": {},
 
35
     "output_type": "execute_result"
72
36
    }
73
37
   ],
74
 
   "metadata": {}
 
38
   "source": [
 
39
    "from pyx import *\n",
 
40
    "\n",
 
41
    "c = canvas.canvas()\n",
 
42
    "c.stroke(path.line(0, 0, 4, 0),\n",
 
43
    "         [style.linewidth.THICK, style.linestyle.dashed, color.rgb.red])\n",
 
44
    "c.stroke(path.line(0, -1, 4, -1),\n",
 
45
    "         [style.linewidth(0.2), style.linecap.round, color.rgb.green])\n",
 
46
    "c.fill(path.rect(0, -3, 4, 1), [color.rgb.blue])\n",
 
47
    "c"
 
48
   ]
 
49
  },
 
50
  {
 
51
   "cell_type": "markdown",
 
52
   "metadata": {},
 
53
   "source": [
 
54
    "The previous example anticipated a simple case of setting an attribute when\n",
 
55
    "stroking paths. This example shows a few more use-cases.\n",
 
56
    "\n",
 
57
    "Attributes can be passed in a list as the second optional argument of the\n",
 
58
    "`stroke` or `fill` methods of a canvas instance.  The attributes themselves are\n",
 
59
    "instances of certain attribute classes. A full list is available in the manual.\n",
 
60
    "\n",
 
61
    "In general, some useful attribute instances are predefined as class attributes\n",
 
62
    "of the corresponding attribute class. In the given example, the\n",
 
63
    "`style.linewidth.THICK`, `style.linestyle.dashed`, `style.linecap.round`,\n",
 
64
    "`color.rgb.red`, `color.rgb.green`, and `color.rgb.blue` are just some examples of\n",
 
65
    "this type of attribute instances. In contrast, `style.linewidth(0.2)` creates a\n",
 
66
    "new style instance for the given parameters.\n",
 
67
    "\n",
 
68
    "<img src=\"http://pyx.sourceforge.net/bend.png\" align=\"left\"><img src=\"http://pyx.sourceforge.net/bend.png\" align=\"left\"> The linewidth instance created by `style.linewidth(0.2)` is different from the\n",
 
69
    "predefined linewidth instances in PyX in its use of *user* units. In the example\n",
 
70
    "*Adding and joining paths* of section *Path features*, the linewidth is\n",
 
71
    "scaled independently of the *user* units, but if you try to double all linewidth\n",
 
72
    "by\n",
 
73
    "\n",
 
74
    "    unit.set(wscale=2)\n",
 
75
    "\n",
 
76
    "in the beginning of the script, our self-defined linewidth will not be scaled.\n",
 
77
    "To obtain the proper scaling behaviour it would be necessary to attach the\n",
 
78
    "*width* unit by using\n",
 
79
    "\n",
 
80
    "    style.linewidth(0.2*unit.w_cm)\n"
 
81
   ]
75
82
  }
76
 
 ]
 
83
 ],
 
84
 "metadata": {
 
85
  "language": "python"
 
86
 },
 
87
 "nbformat": 4,
 
88
 "nbformat_minor": 0
77
89
}
 
 
b'\\ No newline at end of file'