projects
/
experiments
/
RadialSymmetry.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
350bd1d
)
Diagram.py: simplify setting fill and stroke when drawing rectangles
author
Antonio Ospite <ao2@ao2.it>
Thu, 18 Jun 2015 10:06:54 +0000
(12:06 +0200)
committer
Antonio Ospite <ao2@ao2.it>
Thu, 18 Jun 2015 10:06:54 +0000
(12:06 +0200)
Diagram.py
patch
|
blob
|
history
diff --git
a/Diagram.py
b/Diagram.py
index
74c3bb2
..
b6de388
100755
(executable)
--- a/
Diagram.py
+++ b/
Diagram.py
@@
-163,8
+163,7
@@
class Diagram(object):
cr.stroke()
def draw_rect_from_center(self, cx, cy, width, height, theta=0,
cr.stroke()
def draw_rect_from_center(self, cx, cy, width, height, theta=0,
- fill=True, fill_color=[1, 1, 1, 0.8],
- stroke=False, stroke_color=[0, 0, 0, 0.5]):
+ fill_color=[1, 1, 1, 0.8], stroke_color=None):
cr = self.cr
# the position of the center of a rectangle at (0,0)
cr = self.cr
# the position of the center of a rectangle at (0,0)
@@
-176,24
+175,23
@@
class Diagram(object):
rx = cx - (mx * cos(theta) - my * sin(theta))
ry = cy - (mx * sin(theta) + my * cos(theta))
rx = cx - (mx * cos(theta) - my * sin(theta))
ry = cy - (mx * sin(theta) + my * cos(theta))
- self.draw_rect(rx, ry, width, height, theta, fill, fill_color, stroke,
- stroke_color)
+ self.draw_rect(rx, ry, width, height, theta, fill_color, stroke_color)
- def draw_rect(self, x, y, width, height, theta=0,
fill=True, fill_color=[1, 1, 1, 0.8],
-
stroke=False, stroke_color=[0, 0, 0, 0.5]
):
+ def draw_rect(self, x, y, width, height, theta=0,
+
fill_color=[1, 1, 1, 0.8], stroke_color=None
):
cr = self.cr
cr.save()
cr.translate(x, y)
cr.rotate(theta)
cr = self.cr
cr.save()
cr.translate(x, y)
cr.rotate(theta)
- if fill:
+ if fill
_color
:
cr.rectangle(0, 0, width, height)
r, g, b, a = self.color_to_rgba(fill_color)
cr.set_source_rgba(r, g, b, a)
cr.fill()
cr.rectangle(0, 0, width, height)
r, g, b, a = self.color_to_rgba(fill_color)
cr.set_source_rgba(r, g, b, a)
cr.fill()
- if stroke:
+ if stroke
_color
:
cr.rectangle(0, 0, width, height)
r, g, b, a = self.color_to_rgba(stroke_color)
cr.set_source_rgba(r, g, b, a)
cr.rectangle(0, 0, width, height)
r, g, b, a = self.color_to_rgba(stroke_color)
cr.set_source_rgba(r, g, b, a)
@@
-236,8
+234,8
@@
class Diagram(object):
cr.translate(rx, ry)
cr.rotate(theta)
cr.translate(rx, ry)
cr.rotate(theta)
- if bb_fill
or bb_stroke
:
- self.draw_rect(bb[0], bb[1], bb[2], bb[3], 0, bb_fill
, bb_fill_color, bb_stroke
, bb_stroke_color)
+ if bb_fill
_color or bb_stroke_color
:
+ self.draw_rect(bb[0], bb[1], bb[2], bb[3], 0, bb_fill
_color
, bb_stroke_color)
r, g, b, a = self.color_to_rgba(color)
cr.set_source_rgba(r, g, b, a)
r, g, b, a = self.color_to_rgba(color)
cr.set_source_rgba(r, g, b, a)
@@
-287,10
+285,10
@@
if __name__ == "__main__":
diagram.draw_line(0, y, 400, y, [0, 0, 1, 0.2])
diagram.draw_line(0, y, 400, y, [0, 0, 1, 0.2])
- diagram.draw_rect(40, 40, 300, 100, stroke
=True
)
- diagram.draw_rect(40, 40, 300, 100, pi / 30, stroke
=True
)
+ diagram.draw_rect(40, 40, 300, 100, stroke
_color=[0, 0, 0, 0.8]
)
+ diagram.draw_rect(40, 40, 300, 100, pi / 30, stroke
_color=[0, 0, 0, 0.8]
)
- diagram.draw_rect(40, 250, 300, 100, stroke
=True
)
- diagram.draw_rect_from_center(40 + 150, 250 + 50, 300, 100, theta=
pi / 40, stroke=True, stroke_color=[1, 0, 0], fill=Fals
e)
+ diagram.draw_rect(40, 250, 300, 100, stroke
_color=[0, 0, 0, 0.8]
)
+ diagram.draw_rect_from_center(40 + 150, 250 + 50, 300, 100, theta=
(pi / 40), stroke_color=[1, 0, 0], fill_color=Non
e)
diagram.show()
diagram.show()