本文整理汇总了Python中svgwrite.rgb函数的典型用法代码示例。如果您正苦于以下问题:Python rgb函数的具体用法?Python rgb怎么用?Python rgb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rgb函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: svg_shape
def svg_shape(self):
"""return the SVG shape that this object represents"""
r, g, b = my_colormap[self.label]
x, y, dx, dy = self.get_rect_data()
return svgwrite.shapes.Rect(
insert=(x, y), size=(dx, dy), stroke=svgwrite.rgb(r, g, b, "RGB"), fill=svgwrite.rgb(r, g, b, "RGB")
)
示例2: run_script
def run_script(args):
matplotlib.interactive(False)
left = (args.left[0], args.left[1])
right = (args.right[0], args.right[1])
l1 = (150,110,110)
l2 = (110,150,110)
l3 = (110,110,150)
layers= [l1,l2]
# This is a hack to conserve colors
colourmap = { rgb(l1[0],l1[1],l1[2]): args.Rock0,
rgb(l2[0],l2[1],l2[2]): args.Rock1 }
if not isinstance(args.Rock2, str):
colourmap[rgb( l3[0],l3[1],l3[2])] = args.Rock2
layers.append( l3 )
model = mb.body( traces = args.ntraces,
pad = args.pad,
margin=args.margin,
left = left,
right = right,
layers = layers
)
return modelr_plot(model, colourmap, args)
示例3: printmatrixmonthly
def printmatrixmonthly(m,d): #matrix, drawing
x_pos = 0
y_pos = 0
yearnum = 0
for y in m: #for every year in the matrix
curmo = 1
weeknum = 0
x_pos = 0
#print(yearnum+startyear)
for w in y: #for every week in the year
#print(weeknum)
if(isnewmonth(yearnum+startyear,weeknum+1,curmo)):
x_pos = 0
curmo += 1
y_pos += shape_size + 2 #new month
#d.add(d.text(curmo, insert=(x_pos, y_pos), fill='red'))
#x_pos += 5
typecount = 0
for t in w: #for every square count in the week
n = 0 #count number of squares
while n < t:
#d.add(d.rect((x_pos, y_pos), (shape_size, shape_size), fill=svgwrite.rgb(worktypes[typecount][1], worktypes[typecount][2], worktypes[typecount][3]))) #print square
d.add(d.circle((x_pos, y_pos), shape_size/2, fill=svgwrite.rgb(worktypes[typecount][1], worktypes[typecount][2], worktypes[typecount][3]))) #print circle
x_pos += shape_size + 1
n += 1
typecount += 1
weeknum += 1
d.add(d.rect((0, y_pos+1), (6, 4), fill=svgwrite.rgb(0,0,0))) #new year marker
y_pos += 6 #new year
yearnum += 1
d.save()
示例4: get_reflectivity
def get_reflectivity(data,
colourmap,
theta=0,
reflectivity_method=reflection.zoeppritz
):
'''
Create reflectivities from an image of an earth model and a
mapping of colours to rock properties. Will find each interface
and use the specified reflectivity method to calculate the Vp
reflection coefficient.
:param data: The image data of the earth model. A 3D array indexed
as [samples, traces, colour].
:param colourmap: A lookup table (dict) that maps colour values to
rock property structures.
:keyword theta: Angle of incidence to use reflectivity. Can be a
float or an array of angles [deg].
:keyword reflectivity_method: The reflectivity algorithm to use.
See bruges.reflection for methods.
:returns: The vp reflectivity coefficients corresponding to the
earth model. Data will be indexed as
[sample, trace, theta]
'''
# Check if we only have one trace of data, and reform the array
if(data.ndim == 2):
reflect_data = np.zeros((data.size, 1, np.size(theta)))
data = np.reshape(data, (data.shape[0], 1, 3))
else:
reflect_data = np.zeros((data.shape[0], data.shape[1],
np.size(theta)))
# Make an array that only has the boundaries in it
boundaries = get_boundaries(data)
for i in boundaries:
# These are the indices in data
j = i.copy()
j[0] += 1
# Get the colourmap dictionary keys
c1 = rgb(data[i[0], i[1], 0], data[i[0], i[1], 1],
data[i[0], i[1], 2])
c2 = rgb(data[j[0], j[1], 0], data[j[0], j[1], 1],
data[j[0], j[1], 2])
# Don't calculate if not in the cmap. If the model was
# build properly this shouldn't happen.
if((c1 not in colourmap) or (c2 not in colourmap)):
continue
# Get the reflectivity
reflect_data[i[0], i[1], :] = rock_reflectivity(
colourmap[c1], colourmap[c2], theta=theta,
method=reflectivity_method)
return reflect_data
示例5: graphic_output
def graphic_output(self):
cell_size = 100
canvas_width = self.grid_width * cell_size
canvas_height = self.grid_height * cell_size
fname = "graph i=" + str(self.number_of_iterations_yet) + " width=" + str(canvas_width) + " height=" +str(canvas_height) + ".svg"
dwg = svgwrite.Drawing(filename = fname, size = (canvas_width, canvas_height), debug = True)
# Draw horizontal grid lines
#for x in range(0, self.grid_width):
# dwg.add( dwg.line((x*cell_size, 0), (x*cell_size, canvas_height), stroke=svgwrite.rgb(0, 0, 0, "%")) )
#for y in range(0, self.grid_height):
# dwg.add( dwg.line((0, y*cell_size), (canvas_width, y*cell_size), stroke=svgwrite.rgb(0, 0, 0, "%")) )
for row in self.grid:
for square in row:
shapes = dwg.add(dwg.g(id='shapes', fill='red'))
color_numerator = float(square.get_utility()) if type(square.get_utility()) is IntType else 0
color_denominator = 2
fill_color = svgwrite.rgb(255, 255, 255)
if color_numerator > 0:
fill_color = svgwrite.rgb(255-250*(color_numerator/color_denominator), 220, 255-200*(color_denominator/color_denominator))
elif color_numerator < 0:
fill_color = svgwrite.rgb(220, 255-250*(abs(color_numerator)/color_denominator), 255-250*(abs(color_numerator)/color_denominator) )
shapes.add( dwg.rect(insert=(square.x*cell_size, square.y*cell_size), size=(cell_size, cell_size), fill=fill_color) )
paragraph = dwg.add(dwg.g(font_size=16))
paragraph.add(dwg.text(square.get_utility(), ( (square.x + 0.5) * cell_size, (square.y + 0.5) * cell_size)))
dwg.save()
print "grid.graphic_output() successful"
return 0
示例6: visualize_graph
def visualize_graph(graph, graph_parameters, output_file = None):
if not graph_parameters.is_correct:
raise Exception() #!!!!!
graph_utilities = GraphUtilities(graph_parameters)
drawing = svgwrite.Drawing()
for node in graph_utilities.nodes(graph):
node_view_points = \
[(node_vertex.real * 1, - node_vertex.imag * 1) for node_vertex \
in graph_utilities.compute_node_vertices(node)]
node_view = \
svgwrite.shapes.Polygon(
node_view_points,
fill = svgwrite.rgb(0, 0, 0),
fill_opacity = 1.0,
stroke = svgwrite.rgb(0, 0, 0),
stroke_width = 0.1,
stroke_opacity = 1.0
)
drawing.add(node_view)
if output_file is not None:
drawing.write(output_file)
else:
return drawing
示例7: run_script
def run_script(args):
matplotlib.interactive(False)
"""if args.transparent == 'False' or args.transparent == 'No':
transparent = False
else:
transparent = True"""
args.ntraces = 300
args.pad = 150
args.reflectivity_method = zoeppritz
args.title = "Channel - angle gather (AVA)"
args.theta = (0, 50, 0.5)
args.wavelet = ricker
args.wiggle_skips = 10
args.aspect_ratio = 1
args.thickness = 50
args.margin = 1
args.slice = "angle"
transparent = False
# This is a hack to conserve colors
l1 = (150, 110, 110)
l2 = (110, 150, 110)
l3 = (110, 110, 150)
layers = [l1, l2]
colourmap = {rgb(150, 110, 110): args.Rock0, rgb(110, 150, 110): args.Rock1}
if not isinstance(args.Rock2, str):
colourmap[rgb(110, 110, 150)] = args.Rock2
layers.append(l3)
# Get the physical model (an array of rocks)
model = mb.channel(pad=args.pad, thickness=args.thickness, traces=args.ntraces, layers=layers)
return modelr_plot(model, colourmap, args)
示例8: writeShape
def writeShape(shape, params):
if isinstance(shape, list):
for i in shape:
writeShape(i, params)
elif isinstance(shape, tuple):
if len(shape) == 2:
x, y = shape
c = 0
elif len(shape) == 3:
x, y, c = shape
else:
raise Exception('Invalid point {}'.format(shape))
x = (x * params['scale']) + (params['size'] / 2)
y = (-y * params['scale']) + (params['size'] / 2)
c = (c - params['colour_min']) / params['colour_range']
if 0 < x < params['size'] and 0 < y < params['size']:
r, g, b = colorsys.hsv_to_rgb(c, 1, 1)
params['svg'].add(params['svg'].circle(center = (x, y), r = 1, stroke = svgwrite.rgb(r * 255, g * 255, b * 255)))
elif isinstance(shape, data.Line):
for (x1, y1), (x2, y2) in zip(shape.points[:-1], shape.points[1:]):
x1 = (x1 * params['scale']) + (params['size'] / 2)
y1 = (-y1 * params['scale']) + (params['size'] / 2)
x2 = (x2 * params['scale']) + (params['size'] / 2)
y2 = (-y2 * params['scale']) + (params['size'] / 2)
if 0 < x1 < params['size'] and 0 < y1 < params['size'] and 0 < x2 < params['size'] and 0 < y2 < params['size']:
params['svg'].add(params['svg'].line((x1, y1), (x2, y2), stroke = svgwrite.rgb(255, 0, 0)))
else:
print('Cannot plot type', type(shape))
示例9: getline
def getline(startcoord):
startcoord = startcoord
endcoord = calculateEndCoord(startcoord)
dwg.add(dwg.circle(startcoord, 2.5, stroke=svgwrite.rgb(10, 10, 16, '%'), fill='white'))
for i in range(50):
dwg.add(dwg.line(startcoord, endcoord, stroke=svgwrite.rgb(10, 10, 16, '%')))
startcoord = endcoord
endcoord = calculateEndCoord(startcoord)
dwg.add(dwg.circle(startcoord, 2.5, stroke=svgwrite.rgb(10, 10, 16, '%'),fill='white'))
示例10: draw_grid
def draw_grid(self):
for i, n in enumerate(range(self.offset, self.width + 1, self.square_size)):
self._draw_square(i, i, self.nodes[i - 1], fill='gray')
self.dwg.add(self.dwg.line((self.offset, n),
(self.width, n),
stroke_width=self.line_width,
stroke=svgwrite.rgb(10, 10, 16, '%')))
self.dwg.add(self.dwg.line((n, self.offset),
(n, self.height),
stroke_width=self.line_width,
stroke=svgwrite.rgb(10, 10, 16, '%')))
示例11: plotfaces
def plotfaces():
for i in range(-N,N):
for j in range(-N,N):
if(i+j+1 <= N and i+j >= -N):
stroke=svgwrite.rgb(10, 10, 16, '%')
dwg.add(dwg.polygon(points=[coords(i+1,j),coords(i,j+1),coords(i,j)],fill='blue'))
for i in range(-N,N):
for j in range(-N,N):
if(i+j+2 <= N and i+j+1 >= -N):
stroke=svgwrite.rgb(10, 10, 16, '%')
dwg.add(dwg.polygon(points=[coords(i+1,j),coords(i,j+1),coords(i+1,j+1)],fill='red'))
示例12: zadani3_B_c
def zadani3_B_c():
polomer = 100
krok = 9
dwg = svgwrite.Drawing("results/kulata_mriz.svg")
offset = polomer
for i in range(krok/2, polomer+1, krok):
x = i
y = (polomer**2 - x ** 2) ** 0.5
dwg.add(dwg.line((x + offset, y + offset), (x + offset, -y + offset), stroke=svgwrite.rgb(10, 10, 16, '%')))
dwg.add(dwg.line((-x + offset, y + offset), (-x + offset, -y + offset), stroke=svgwrite.rgb(10, 10, 16, '%')))
dwg.add(dwg.line((-y + offset, x + offset), (y + offset, x + offset), stroke=svgwrite.rgb(10, 10, 16, '%')))
dwg.add(dwg.line((-y + offset, -x + offset), (y + offset, -x + offset), stroke=svgwrite.rgb(10, 10, 16, '%')))
dwg.save()
示例13: channel_svg
def channel_svg(pad, thickness, traces, layers):
"""
Makes a rounded channel.
Give it pad, thickness, traces, and an iterable of layers.
Returns an SVG file.
:param pad: The number (n) of points on top of the channel.
:param: thickness: The radius of the channel (npoints).
:param traces: The number of traces in the channel model.
:param layers: An 3X3 array or tuple of RGB values corresponding
to each rock layer. ((R,G,B),(R,G,B),(R,G,B)).
Indexed as (top, channel, bottom ).
:returns: a tempfile object pointed to the model svg file.
"""
outfile = tempfile.NamedTemporaryFile(suffix='.svg', delete=True )
top_colour = rgb( layers[0][0],layers[0][1], layers[0][2] )
body_colour = rgb( layers[1][0],layers[1][1], layers[1][2] )
bottom_colour = rgb( layers[2][0],layers[2][1], layers[2][2] )
width = traces
height = 2.5*pad + thickness
dwg = svgwrite.Drawing(outfile.name, size=(width,height),
profile='tiny')
# Draw the bottom layer
bottom_layer = \
svgwrite.shapes.Rect(insert=(0,0),
size=(width,height)).fill(bottom_colour)
dwg.add(bottom_layer)
# Draw the body
body = \
svgwrite.shapes.Ellipse(center=(width/2,pad/2),
r=(0.3*width,pad+thickness)).fill(body_colour)
dwg.add(body)
# Draw the top layer
top_layer = \
svgwrite.shapes.Rect(insert=(0,0),
size=(width,pad)).fill(top_colour)
dwg.add(top_layer)
# Do this for a file
dwg.save()
return outfile
示例14: recur_triangle
def recur_triangle():
verts = ngram_vertexes(3, 400)
triang = Polygon(verts)
dwg = svgwrite.Drawing('triang.svg')
offset = 0
dwg.add(dwg.circle((verts[0][0] + offset, verts[0][1] + offset), r=1, stroke=svgwrite.rgb(255, 0, 0, '%')))
dwg.add(dwg.circle((verts[1][0] + offset, verts[1][1] + offset), r=1, stroke=svgwrite.rgb(255, 0, 0, '%')))
dwg.add(dwg.circle((verts[2][0] + offset, verts[2][1] + offset), r=1, stroke=svgwrite.rgb(255, 0, 0, '%')))
recurse_transformations(triang, dwg, 7, 100)
dwg.save()
示例15: displaySVGPaths
def displaySVGPaths(pathList,*colors): #creates and saves an svf file displaying the input paths
show_closed_discont=True
import svgwrite
from svgpathtools import Path, Line, CubicBezier
# from time import strftime
# from re import sub
# dwg = svgwrite.Drawing('temporary_displaySVGPaths%s.svg'%time_date, size= ("%spx"%(int(xmax-xmin+1)), "%spx"%(int(ymax-ymin+1))))
# dwg = svgwrite.Drawing('temporary_displaySVGPaths%s.svg'%time_date)
dwg = svgwrite.Drawing('temporary_displaySVGPaths.svg')
dwg.add(dwg.rect(insert=(0, 0), size=('100%', '100%'), rx=None, ry=None, fill='white')) #add white background
dc = 100/len(pathList)
for i,p in enumerate(pathList):
if isinstance(p,Path):
startpt = p[0].start
ps = path2str(p)
elif isinstance(p,Line) or isinstance(p,CubicBezier):
startpt = p.start
ps = path2str(p)
else:
startpt = parse_path(p)[0].start
ps = p
if colors !=tuple():
dwg.add(dwg.path(ps, stroke=colors[0][i], fill='none'))
else:
dwg.add(dwg.path(ps, stroke=svgwrite.rgb(0+dc, 0+dc, 16, '%'), fill='none'))
if show_closed_discont and isApproxClosedPath(p):
startpt = (startpt.real,startpt.imag)
dwg.add(dwg.circle(startpt,1, stroke='gray', fill='gray'))
dwg.save()