Skip to content

Commit

Permalink
Merge pull request #8 from lingruiluo/master
Browse files Browse the repository at this point in the history
Merge pull request #1 from AaronWatters/master
  • Loading branch information
AaronWatters authored Jul 13, 2020
2 parents 3fa7018 + ddfc32f commit e0089d2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
15 changes: 10 additions & 5 deletions jp_doodle/svg_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ def line(self, x1, y1, x2, y2, color, lineWidth, **other_arguments_ignored):
)

def rect(self, x, y, w, h, color, degrees = None, lineWidth=1, fill=True, **other_arguments_ignored):
if w < 0:
x = x + w
w = abs(w)
if h < 0:
y = y + h
h = abs(h)
(x, y) = self.canvas_to_svg_axis(x, y)
atts = {}
if fill:
Expand All @@ -138,9 +144,8 @@ def rect(self, x, y, w, h, color, degrees = None, lineWidth=1, fill=True, **othe
# svg rect element does not support negative coordinates
if degrees:
atts['transform'] = "rotate(%s, %s, %s)" %(-degrees, x, y)
else:
atts['x'] = x
atts['y'] = y-h
atts['x'] = x
atts['y'] = y-h
style = ""
if lineWidth:
style += "stroke-width:" + str(lineWidth)
Expand Down Expand Up @@ -174,11 +179,11 @@ def polygon(self, points, color, fill=True, close = True, lineWidth=1, **other_a
)

def image(self, x, y, w, h, image_name, **other_arguments_ignored):
# href is hard coded
# href is hard coded: image_name must be the file path
(x, y) = self.canvas_to_svg_axis(x, y)
self.add_draw_tag(
tag_name="image",
href = image_name+".png",
href = image_name,
x = x,
y = y-h,
height = h,
Expand Down
16 changes: 8 additions & 8 deletions notebooks/misc/svg_tests/image test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "73e866324ddd4a5f904b52540e559d82",
"model_id": "6be65d542e574c5f80d5e2c1bc9073c4",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -39,15 +39,15 @@
"# Scaled the image to byte values.\n",
"inverted = (1 - img) * 255\n",
"# Load the image to the canvas and name it.\n",
"demo.name_image_array(\"mandrill\", inverted)\n",
"demo.name_image_array(\"mandrill.png\", inverted)\n",
"# Draw the image by name.\n",
"demo.named_image(\"mandrill\", 50, 50, 210, 130)\n",
"demo.named_image(\"mandrill.png\", 50, 50, 210, 130)\n",
"demo.fit()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -72,7 +72,7 @@
" 'y': 50,\n",
" 'w': 210,\n",
" 'h': 130,\n",
" 'image_name': 'mandrill',\n",
" 'image_name': 'mandrill.png',\n",
" 'degrees': 0,\n",
" 'draw_on_canvas': {},\n",
" 'object_index': 0,\n",
Expand All @@ -82,7 +82,7 @@
" 'sample_pixel': {'x': 160, 'y': 110}}]"
]
},
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -93,7 +93,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down
6 changes: 3 additions & 3 deletions notebooks/misc/svg_tests/rect test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2969f09be85a422cb7a2f307374d236d",
"model_id": "e1b19d8358734e25a87b19aba5fc2896",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -69,9 +69,9 @@
"<svg viewBox=\"0 0 320 220\" xmlns=\"http://www.w3.org/2000/svg\">\n",
" <g transform=\"scale(1.7390438239897745 1.7390438239897745) translate(76.51333851480325 39.2403876506104)\">\n",
"\t<rect width=\"50\" height=\"30\" stroke=\"green\" style=\"stroke-width:1\" fill=\"green\" x=\"0\" y=\"18.02552486507885\" />\n",
"\t<rect width=\"40\" height=\"90\" stroke=\"#7DD\" style=\"stroke-width:5\" fill=\"transparent\" transform=\"rotate(-33, 0, 68.02552486507885)\" />\n",
"\t<rect width=\"40\" height=\"90\" stroke=\"#7DD\" style=\"stroke-width:5\" fill=\"transparent\" transform=\"rotate(-33, 0, 68.02552486507885)\" x=\"0\" y=\"-21.97447513492115\" />\n",
"\t<rect width=\"100\" height=\"40\" stroke=\"rgba(2,22,222,0.5)\" style=\"stroke-width:10\" fill=\"transparent\" x=\"-20\" y=\"8.02552486507885\" />\n",
"\t<rect width=\"-30\" height=\"-50\" stroke=\"rgba(200,150,50,0.8)\" style=\"stroke-width:1\" fill=\"rgba(200,150,50,0.8)\" transform=\"rotate(10, 60, 28.02552486507885)\" />\n",
"\t<rect width=\"30\" height=\"50\" stroke=\"rgba(200,150,50,0.8)\" style=\"stroke-width:1\" fill=\"rgba(200,150,50,0.8)\" transform=\"rotate(10, 30, 78.02552486507885)\" x=\"30\" y=\"28.02552486507885\" />\n",
"\t</g>\n",
"</svg>\n"
],
Expand Down

0 comments on commit e0089d2

Please sign in to comment.