From: <jd...@us...> - 2008-05-16 12:50:22
|
Revision: 5144 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5144&view=rev Author: jdh2358 Date: 2008-05-16 05:50:00 -0700 (Fri, 16 May 2008) Log Message: ----------- moved deprecated examples to storage Added Paths: ----------- trunk/matplotlib/examples/cold_storage/ trunk/matplotlib/examples/cold_storage/README trunk/matplotlib/examples/cold_storage/agg_resize.py trunk/matplotlib/examples/cold_storage/agg_test.py trunk/matplotlib/examples/cold_storage/clippath_test.py trunk/matplotlib/examples/cold_storage/glyph_to_path.py Removed Paths: ------------- trunk/matplotlib/examples/agg_resize.py trunk/matplotlib/examples/agg_test.py trunk/matplotlib/examples/clippath_test.py trunk/matplotlib/examples/glyph_to_path.py Deleted: trunk/matplotlib/examples/agg_resize.py =================================================================== --- trunk/matplotlib/examples/agg_resize.py 2008-05-15 19:25:14 UTC (rev 5143) +++ trunk/matplotlib/examples/agg_resize.py 2008-05-16 12:50:00 UTC (rev 5144) @@ -1,7 +0,0 @@ -# test the resizing methods in the agg wrapper - -import matplotlib.agg as agg - - -imMatrix = agg.trans_affine(1,0,0,1,0,0) -interp = agg.span_interpolator_linear(imMatrix); Deleted: trunk/matplotlib/examples/agg_test.py =================================================================== --- trunk/matplotlib/examples/agg_test.py 2008-05-15 19:25:14 UTC (rev 5143) +++ trunk/matplotlib/examples/agg_test.py 2008-05-16 12:50:00 UTC (rev 5144) @@ -1,154 +0,0 @@ -# this example uses the agg python module directly there is no -# documentation -- you have to know how to use the agg c++ API to use -# it -import matplotlib.agg as agg -from math import pi - -## Define some colors -red = agg.rgba8(255,0,0,255) -blue = agg.rgba8(0,0,255,255) -green = agg.rgba8(0,255,0,255) -black = agg.rgba8(0,0,0,255) -white = agg.rgba8(255,255,255,255) -yellow = agg.rgba8(192,192,255,255) - -## Create the rendering buffer, rasterizer, etc -width, height = 600,400 -stride = width*4 -buffer = agg.buffer(width, height, stride) - -rbuf = agg.rendering_buffer() -rbuf.attachb(buffer) - -pf = agg.pixel_format_rgba(rbuf) -rbase = agg.renderer_base_rgba(pf) -rbase.clear_rgba8(blue) - -renderer = agg.renderer_scanline_aa_solid_rgba(rbase); -renderer.color_rgba8( red ) -rasterizer = agg.rasterizer_scanline_aa() -scanline = agg.scanline_p8() - -## A polygon path -path = agg.path_storage() -path.move_to(10,10) -path.line_to(100,100) -path.line_to(200,200) -path.line_to(100,200) -path.close_polygon() - -# stroke it -stroke = agg.conv_stroke_path(path) -stroke.width(3.0) -rasterizer.add_path(stroke) -agg.render_scanlines_rgba(rasterizer, scanline, renderer); - -## A curved path -path = agg.path_storage() -path.move_to(200,10) -path.line_to(350,50) -path.curve3(150,200) -path.curve3(100,70) -path.close_polygon() -curve = agg.conv_curve_path(path) - -# fill it -rasterizer.add_path(curve) -renderer.color_rgba8( green ) -agg.render_scanlines_rgba(rasterizer, scanline, renderer); - -# and stroke it -stroke = agg.conv_stroke_curve(curve) -stroke.width(5.0) -rasterizer.add_path(stroke) -renderer.color_rgba8( yellow ) -agg.render_scanlines_rgba(rasterizer, scanline, renderer); - -## Transforming a path -path = agg.path_storage() -path.move_to(0,0) -path.line_to(1,0) -path.line_to(1,1) -path.line_to(0,1) -path.close_polygon() - -rotation = agg.trans_affine_rotation(pi/4) -scaling = agg.trans_affine_scaling(30,30) -translation = agg.trans_affine_translation(300,300) -trans = rotation*scaling*translation - -transpath = agg.conv_transform_path(path, trans) -stroke = agg.conv_stroke_transpath(transpath) -stroke.width(2.0) -rasterizer.add_path(stroke) -renderer.color_rgba8( black ) -agg.render_scanlines_rgba(rasterizer, scanline, renderer); - -## Converting a transformed path to a curve -path = agg.path_storage() -path.move_to(0,0) -path.curve3(1,0) -path.curve3(1,1) -path.curve3(0,1) -path.close_polygon() - -rotation = agg.trans_affine_rotation(pi/4) -scaling = agg.trans_affine_scaling(30,30) -translation = agg.trans_affine_translation(300,250) -trans = rotation*scaling*translation -trans.flip_y() - -transpath = agg.conv_transform_path(path, trans) -curvetrans = agg.conv_curve_trans(transpath) -stroke = agg.conv_stroke_curvetrans(curvetrans) -stroke.width(2.0) -rasterizer.add_path(stroke) -renderer.color_rgba8( white ) -agg.render_scanlines_rgba(rasterizer, scanline, renderer); - -if 0: - ## Copy a rectangle from the buffer the rectangle defined by - ## x0,y0->x1,y1 and paste it at xdest, ydest - x0, y0 = 10, 50 - x1, y1 = 110, 190 - xdest, ydest = 350, 200 - - - - widthr, heightr = x1-x0, y1-y0 - strider = widthr*4 - copybuffer = agg.buffer(widthr, heightr, strider) - - - rbufcopy = agg.rendering_buffer() - rbufcopy.attachb(copybuffer) - pfcopy = agg.pixel_format_rgba(rbufcopy) - rbasecopy = agg.renderer_base_rgba(pfcopy) - - rect = agg.rect(x0, y0, x1, y1) - print rect.is_valid() - rectp = agg.rectPtr(rect) - #print dir(rbasecopy) - - # agg is funny about the arguments to copy from; the last 2 args are - # dx, dy. If the src and dest buffers are the same size and you omit - # the dx and dy args, the position of the copy in the dest buffer is - # the same as in the src. Since our dest buffer is smaller than our - # src buffer, we have to offset the location by -x0, -y0 - rbasecopy.copy_from(rbuf, rect, -x0, -y0); - - # paste the rectangle at a new location xdest, ydest - rbase.copy_from(rbufcopy, None, xdest, ydest); - - - -## Display it with PIL -s = buffer.to_string() -print len(s) -import Image -im = Image.fromstring( "RGBA", (width, height), s) -im.show() - - - - Deleted: trunk/matplotlib/examples/clippath_test.py =================================================================== --- trunk/matplotlib/examples/clippath_test.py 2008-05-15 19:25:14 UTC (rev 5143) +++ trunk/matplotlib/examples/clippath_test.py 2008-05-16 12:50:00 UTC (rev 5144) @@ -1,56 +0,0 @@ -from matplotlib.pyplot import figure, show -import matplotlib.transforms as transforms -from matplotlib.patches import RegularPolygon -import matplotlib.agg as agg -from numpy import arange, sin, pi -from numpy.random import rand - -class ClipWindow: - def __init__(self, ax, line): - self.ax = ax - ax.set_title('drag polygon around to test clipping') - self.canvas = ax.figure.canvas - self.line = line - self.poly = RegularPolygon( - (200, 200), numVertices=10, radius=100, - facecolor='yellow', alpha=0.25, - transform=transforms.IdentityTransform()) - - ax.add_patch(self.poly) - self.canvas.mpl_connect('button_press_event', self.onpress) - self.canvas.mpl_connect('button_release_event', self.onrelease) - self.canvas.mpl_connect('motion_notify_event', self.onmove) - self.x, self.y = None, None - - def onpress(self, event): - self.x, self.y = event.x, event.y - - def onrelease(self, event): - self.x, self.y = None, None - - def onmove(self, event): - - if self.x is None: return - dx = event.x - self.x - dy = event.y - self.y - self.x, self.y = event.x, event.y - x, y = self.poly.xy - x += dx - y += dy - #print self.y, event.y, dy, y - self.poly.xy = x,y - self._clip() - - def _clip(self): - self.line.set_clip_path(self.poly.get_path(), self.poly.get_transform()) - self.canvas.draw_idle() - - -fig = figure(figsize=(8,8)) -ax = fig.add_subplot(111) -t = arange(0.0, 4.0, 0.01) -s = 2*sin(2*pi*8*t) - -line, = ax.plot(t, 2*(rand(len(t))-0.5), 'b-') -clipwin = ClipWindow(ax, line) -show() Added: trunk/matplotlib/examples/cold_storage/README =================================================================== --- trunk/matplotlib/examples/cold_storage/README (rev 0) +++ trunk/matplotlib/examples/cold_storage/README 2008-05-16 12:50:00 UTC (rev 5144) @@ -0,0 +1,4 @@ +These are old examples that are now derecated and most likely +non-functional but we are keeping them around in case we want to +resurrect them on day. You can safely ignore them. + Copied: trunk/matplotlib/examples/cold_storage/agg_resize.py (from rev 5143, trunk/matplotlib/examples/agg_resize.py) =================================================================== --- trunk/matplotlib/examples/cold_storage/agg_resize.py (rev 0) +++ trunk/matplotlib/examples/cold_storage/agg_resize.py 2008-05-16 12:50:00 UTC (rev 5144) @@ -0,0 +1,7 @@ +# test the resizing methods in the agg wrapper + +import matplotlib.agg as agg + + +imMatrix = agg.trans_affine(1,0,0,1,0,0) +interp = agg.span_interpolator_linear(imMatrix); Copied: trunk/matplotlib/examples/cold_storage/agg_test.py (from rev 5143, trunk/matplotlib/examples/agg_test.py) =================================================================== --- trunk/matplotlib/examples/cold_storage/agg_test.py (rev 0) +++ trunk/matplotlib/examples/cold_storage/agg_test.py 2008-05-16 12:50:00 UTC (rev 5144) @@ -0,0 +1,154 @@ +# this example uses the agg python module directly there is no +# documentation -- you have to know how to use the agg c++ API to use +# it +import matplotlib.agg as agg +from math import pi + +## Define some colors +red = agg.rgba8(255,0,0,255) +blue = agg.rgba8(0,0,255,255) +green = agg.rgba8(0,255,0,255) +black = agg.rgba8(0,0,0,255) +white = agg.rgba8(255,255,255,255) +yellow = agg.rgba8(192,192,255,255) + +## Create the rendering buffer, rasterizer, etc +width, height = 600,400 +stride = width*4 +buffer = agg.buffer(width, height, stride) + +rbuf = agg.rendering_buffer() +rbuf.attachb(buffer) + +pf = agg.pixel_format_rgba(rbuf) +rbase = agg.renderer_base_rgba(pf) +rbase.clear_rgba8(blue) + +renderer = agg.renderer_scanline_aa_solid_rgba(rbase); +renderer.color_rgba8( red ) +rasterizer = agg.rasterizer_scanline_aa() +scanline = agg.scanline_p8() + +## A polygon path +path = agg.path_storage() +path.move_to(10,10) +path.line_to(100,100) +path.line_to(200,200) +path.line_to(100,200) +path.close_polygon() + +# stroke it +stroke = agg.conv_stroke_path(path) +stroke.width(3.0) +rasterizer.add_path(stroke) +agg.render_scanlines_rgba(rasterizer, scanline, renderer); + +## A curved path +path = agg.path_storage() +path.move_to(200,10) +path.line_to(350,50) +path.curve3(150,200) +path.curve3(100,70) +path.close_polygon() +curve = agg.conv_curve_path(path) + +# fill it +rasterizer.add_path(curve) +renderer.color_rgba8( green ) +agg.render_scanlines_rgba(rasterizer, scanline, renderer); + +# and stroke it +stroke = agg.conv_stroke_curve(curve) +stroke.width(5.0) +rasterizer.add_path(stroke) +renderer.color_rgba8( yellow ) +agg.render_scanlines_rgba(rasterizer, scanline, renderer); + +## Transforming a path +path = agg.path_storage() +path.move_to(0,0) +path.line_to(1,0) +path.line_to(1,1) +path.line_to(0,1) +path.close_polygon() + +rotation = agg.trans_affine_rotation(pi/4) +scaling = agg.trans_affine_scaling(30,30) +translation = agg.trans_affine_translation(300,300) +trans = rotation*scaling*translation + +transpath = agg.conv_transform_path(path, trans) +stroke = agg.conv_stroke_transpath(transpath) +stroke.width(2.0) +rasterizer.add_path(stroke) +renderer.color_rgba8( black ) +agg.render_scanlines_rgba(rasterizer, scanline, renderer); + +## Converting a transformed path to a curve +path = agg.path_storage() +path.move_to(0,0) +path.curve3(1,0) +path.curve3(1,1) +path.curve3(0,1) +path.close_polygon() + +rotation = agg.trans_affine_rotation(pi/4) +scaling = agg.trans_affine_scaling(30,30) +translation = agg.trans_affine_translation(300,250) +trans = rotation*scaling*translation +trans.flip_y() + +transpath = agg.conv_transform_path(path, trans) +curvetrans = agg.conv_curve_trans(transpath) +stroke = agg.conv_stroke_curvetrans(curvetrans) +stroke.width(2.0) +rasterizer.add_path(stroke) +renderer.color_rgba8( white ) +agg.render_scanlines_rgba(rasterizer, scanline, renderer); + +if 0: + ## Copy a rectangle from the buffer the rectangle defined by + ## x0,y0->x1,y1 and paste it at xdest, ydest + x0, y0 = 10, 50 + x1, y1 = 110, 190 + xdest, ydest = 350, 200 + + + + widthr, heightr = x1-x0, y1-y0 + strider = widthr*4 + copybuffer = agg.buffer(widthr, heightr, strider) + + + rbufcopy = agg.rendering_buffer() + rbufcopy.attachb(copybuffer) + pfcopy = agg.pixel_format_rgba(rbufcopy) + rbasecopy = agg.renderer_base_rgba(pfcopy) + + rect = agg.rect(x0, y0, x1, y1) + print rect.is_valid() + rectp = agg.rectPtr(rect) + #print dir(rbasecopy) + + # agg is funny about the arguments to copy from; the last 2 args are + # dx, dy. If the src and dest buffers are the same size and you omit + # the dx and dy args, the position of the copy in the dest buffer is + # the same as in the src. Since our dest buffer is smaller than our + # src buffer, we have to offset the location by -x0, -y0 + rbasecopy.copy_from(rbuf, rect, -x0, -y0); + + # paste the rectangle at a new location xdest, ydest + rbase.copy_from(rbufcopy, None, xdest, ydest); + + + +## Display it with PIL +s = buffer.to_string() +print len(s) +import Image +im = Image.fromstring( "RGBA", (width, height), s) +im.show() + + + + Copied: trunk/matplotlib/examples/cold_storage/clippath_test.py (from rev 5143, trunk/matplotlib/examples/clippath_test.py) =================================================================== --- trunk/matplotlib/examples/cold_storage/clippath_test.py (rev 0) +++ trunk/matplotlib/examples/cold_storage/clippath_test.py 2008-05-16 12:50:00 UTC (rev 5144) @@ -0,0 +1,56 @@ +from matplotlib.pyplot import figure, show +import matplotlib.transforms as transforms +from matplotlib.patches import RegularPolygon +import matplotlib.agg as agg +from numpy import arange, sin, pi +from numpy.random import rand + +class ClipWindow: + def __init__(self, ax, line): + self.ax = ax + ax.set_title('drag polygon around to test clipping') + self.canvas = ax.figure.canvas + self.line = line + self.poly = RegularPolygon( + (200, 200), numVertices=10, radius=100, + facecolor='yellow', alpha=0.25, + transform=transforms.IdentityTransform()) + + ax.add_patch(self.poly) + self.canvas.mpl_connect('button_press_event', self.onpress) + self.canvas.mpl_connect('button_release_event', self.onrelease) + self.canvas.mpl_connect('motion_notify_event', self.onmove) + self.x, self.y = None, None + + def onpress(self, event): + self.x, self.y = event.x, event.y + + def onrelease(self, event): + self.x, self.y = None, None + + def onmove(self, event): + + if self.x is None: return + dx = event.x - self.x + dy = event.y - self.y + self.x, self.y = event.x, event.y + x, y = self.poly.xy + x += dx + y += dy + #print self.y, event.y, dy, y + self.poly.xy = x,y + self._clip() + + def _clip(self): + self.line.set_clip_path(self.poly.get_path(), self.poly.get_transform()) + self.canvas.draw_idle() + + +fig = figure(figsize=(8,8)) +ax = fig.add_subplot(111) +t = arange(0.0, 4.0, 0.01) +s = 2*sin(2*pi*8*t) + +line, = ax.plot(t, 2*(rand(len(t))-0.5), 'b-') +clipwin = ClipWindow(ax, line) +show() Copied: trunk/matplotlib/examples/cold_storage/glyph_to_path.py (from rev 5143, trunk/matplotlib/examples/glyph_to_path.py) =================================================================== --- trunk/matplotlib/examples/cold_storage/glyph_to_path.py (rev 0) +++ trunk/matplotlib/examples/cold_storage/glyph_to_path.py 2008-05-16 12:50:00 UTC (rev 5144) @@ -0,0 +1,84 @@ +import os +import matplotlib +from matplotlib.ft2font import FT2Font +import matplotlib.agg as agg + +MOVETO, LINETO, CURVE3, CURVE4, ENDPOLY = range(5) + +def glyph_to_agg_path(glyph): + path = agg.path_storage() + for tup in glyph.path: + print tup + code = tup[0] + if code == MOVETO: + x,y = tup[1:] + path.move_to(x,y) + elif code == LINETO: + x,y = tup[1:] + path.line_to(x,y) + elif code == CURVE3: + xctl, yctl, xto, yto= tup[1:] + path.curve3(xctl, yctl, xto, yto) + + elif code == CURVE4: + xctl1, yctl1, xctl2, yctl2, xto, yto= tup[1:] + path.curve4(xctl1, yct1, xctl2, yctl2, xto, yto) + elif code == ENDPOLY: + path.end_poly() + + return path + +width, height = 300,300 +fname = os.path.join(matplotlib.get_data_path(), 'fonts/ttf/Vera.ttf') +font = FT2Font(fname) +glyph = font.load_char(ord('y')) +path = glyph_to_agg_path(glyph) + +curve = agg.conv_curve_path(path) + + +scaling = agg.trans_affine_scaling(20,20) +translation = agg.trans_affine_translation(4,4) +rotation = agg.trans_affine_rotation(3.1415926) +mtrans = translation*scaling # cannot use this as a temporary +tpath = agg.conv_transform_path(path, mtrans) + +curve = agg.conv_curve_trans(tpath) + +stride = width*4 +buffer = agg.buffer(width, height, stride) + +rbuf = agg.rendering_buffer() +rbuf.attachb(buffer) + +red = agg.rgba8(255,0,0,255) +blue = agg.rgba8(0,0,255,255) +white = agg.rgba8(255,255,255,255) + +pf = agg.pixel_format_rgba(rbuf) +rbase = agg.renderer_base_rgba(pf) +rbase.clear_rgba8(white) + +renderer = agg.renderer_scanline_aa_solid_rgba(rbase); + + +rasterizer = agg.rasterizer_scanline_aa() +scanline = agg.scanline_p8() + +# first fill +rasterizer.add_path(curve) +renderer.color_rgba8(blue) +agg.render_scanlines_rgba(rasterizer, scanline, renderer); + +# then stroke +stroke = agg.conv_stroke_curvetrans(curve) +stroke.width(2.0) +renderer.color_rgba8( red ) +rasterizer.add_path(stroke) +agg.render_scanlines_rgba(rasterizer, scanline, renderer); + +s = buffer.to_string() +import Image +im = Image.fromstring( "RGBA", (width, height), s) +im.show() + Deleted: trunk/matplotlib/examples/glyph_to_path.py =================================================================== --- trunk/matplotlib/examples/glyph_to_path.py 2008-05-15 19:25:14 UTC (rev 5143) +++ trunk/matplotlib/examples/glyph_to_path.py 2008-05-16 12:50:00 UTC (rev 5144) @@ -1,84 +0,0 @@ -import os -import matplotlib -from matplotlib.ft2font import FT2Font -import matplotlib.agg as agg - -MOVETO, LINETO, CURVE3, CURVE4, ENDPOLY = range(5) - -def glyph_to_agg_path(glyph): - path = agg.path_storage() - for tup in glyph.path: - print tup - code = tup[0] - if code == MOVETO: - x,y = tup[1:] - path.move_to(x,y) - elif code == LINETO: - x,y = tup[1:] - path.line_to(x,y) - elif code == CURVE3: - xctl, yctl, xto, yto= tup[1:] - path.curve3(xctl, yctl, xto, yto) - - elif code == CURVE4: - xctl1, yctl1, xctl2, yctl2, xto, yto= tup[1:] - path.curve4(xctl1, yct1, xctl2, yctl2, xto, yto) - elif code == ENDPOLY: - path.end_poly() - - return path - -width, height = 300,300 -fname = os.path.join(matplotlib.get_data_path(), 'fonts/ttf/Vera.ttf') -font = FT2Font(fname) -glyph = font.load_char(ord('y')) -path = glyph_to_agg_path(glyph) - -curve = agg.conv_curve_path(path) - - -scaling = agg.trans_affine_scaling(20,20) -translation = agg.trans_affine_translation(4,4) -rotation = agg.trans_affine_rotation(3.1415926) -mtrans = translation*scaling # cannot use this as a temporary -tpath = agg.conv_transform_path(path, mtrans) - -curve = agg.conv_curve_trans(tpath) - -stride = width*4 -buffer = agg.buffer(width, height, stride) - -rbuf = agg.rendering_buffer() -rbuf.attachb(buffer) - -red = agg.rgba8(255,0,0,255) -blue = agg.rgba8(0,0,255,255) -white = agg.rgba8(255,255,255,255) - -pf = agg.pixel_format_rgba(rbuf) -rbase = agg.renderer_base_rgba(pf) -rbase.clear_rgba8(white) - -renderer = agg.renderer_scanline_aa_solid_rgba(rbase); - - -rasterizer = agg.rasterizer_scanline_aa() -scanline = agg.scanline_p8() - -# first fill -rasterizer.add_path(curve) -renderer.color_rgba8(blue) -agg.render_scanlines_rgba(rasterizer, scanline, renderer); - -# then stroke -stroke = agg.conv_stroke_curvetrans(curve) -stroke.width(2.0) -renderer.color_rgba8( red ) -rasterizer.add_path(stroke) -agg.render_scanlines_rgba(rasterizer, scanline, renderer); - -s = buffer.to_string() -import Image -im = Image.fromstring( "RGBA", (width, height), s) -im.show() - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |