def cairo_skin_fly1(cr): r = 1.0 # will be scaled by robot radius with cairo_save(cr): cr.scale(0.32, 0.32) def wing(): rw = r with cairo_save(cr): cr.scale(1.5, 1) cairo_plot_circle2(cr, rw / 2, 0, rw, fill_color=[.5, .5, .5]) wa = 3 / 2 with cairo_transform(cr, t=[0, wa], r=np.pi / 2): wing() with cairo_transform(cr, t=[0, -wa], r=(-np.pi / 2)): wing() with cairo_save(cr): cr.scale(1.5, 0.75) cairo_plot_circle2(cr, 0, 0, r, fill_color=WHITE, border_color=BLACK, border_width=0.005) cairo_plot_circle2(cr, r * 1.5, 0, r / 1.5, fill_color=WHITE, border_color=BLACK, border_width=0.005)
def cairo_plot_sources_field(cr, sources, bounds, disc=[100, 100], alpha=0.5): if not sources: return xb = bounds[0] yb = bounds[1] x = np.linspace(xb[0], xb[1], disc[0]) y = np.linspace(yb[0], yb[1], disc[1]) X, Y = np.meshgrid(x, y) C = get_field_values(sources, X, Y) C = C - C.min() C = C / C.max() C = 1 - C Cscal = ((C) * 255).astype("uint8") data = np.empty((disc[0], disc[1], 4), dtype=np.uint8) data.fill(255) data[:, :, 2] = Cscal image = cairo.ImageSurface.create_for_data( # @UndefinedVariable data, cairo.FORMAT_ARGB32, disc[0], disc[1], disc[1] * 4 # @UndefinedVariable ) with cairo_save(cr): Z = float(disc[0]) / (xb[1] - xb[0]) zoom = 1 / Z cr.scale(zoom, zoom) cr.translate(-disc[0] / 2, -disc[1] / 2) cr.set_source_surface(image) cr.paint_with_alpha(0.5)
def cairo_skin_sick(cr, size=1.0): with cairo_save(cr): cr.scale(size, size) cairo_plot_rectangle(cr, -.5, -.5, 1, 1, fill_color=YELLOW, border_color=BLACK, border_width=0.005) w2 = 1.0 / 1.6 l = 1.0 / 3 cairo_plot_rectangle(cr, .5 - l, -w2 / 2, l, w2, fill_color=BLACK)
def cairo_plot_polyline_primitive(cr, points, texture=None): with cairo_save(cr): cr.set_line_width(CC.obstacle_border_width) cairo_set_color(cr, CC.obstacle_border_color) cairo_plot_polyline(cr, points[0, :], points[1, :]) if texture is not None: cairo_plot_textured_polyline( cr, points=points, texture=texture, resolution=CC.texture_resolution, width_inside=0, width_outside=CC.texture_resolution, )
def cairo_skin_eye(cr, size=1.0): with cairo_save(cr): cr.scale(size, size) # White part cairo_plot_circle2(cr, 0, 0, 1, fill_color=WHITE, border_color=BLACK, border_width=0.05) # Brown # BROWN1 = [.4, .2, 0] BROWN2 = [.6, .3, 0] cairo_plot_circle2(cr, 0.5, 0, 0.5, fill_color=BROWN2, border_color=None, border_width=None) # Black cairo_plot_circle2(cr, 0.6, 0, 0.22, # 0.25, fill_color=BLACK, border_color=None, border_width=None)
def cairo_show_world_geometry(cr, world_state, plot_sources=False, plot_textures=False, extra_pad=0): bounds = world_state["bounds"] primitives = world_state["primitives"] with cairo_save(cr): xb = bounds[0] yb = bounds[1] xb = [xb[0] - extra_pad, xb[1] + extra_pad] yb = [yb[0] - extra_pad, yb[1] + extra_pad] cr.rectangle(xb[0], yb[0], xb[1] - xb[0], yb[1] - yb[0]) cr.clip() # Draw it twice for special effects for i in range(2): for p in primitives: ptype = p["type"] if ptype == VehiclesConstants.PRIMITIVE_POLYLINE: points = np.array(p["points"]).T texture = instantiate_spec(p["texture"]) if not plot_textures: texture = None cairo_plot_polyline_primitive(cr, points=points, texture=texture) elif ptype == VehiclesConstants.PRIMITIVE_CIRCLE: texture = instantiate_spec(p["texture"]) if not plot_textures: texture = None cairo_plot_circle_primitive( cr, center=p["center"], texture=texture, radius=p["radius"], solid=p["solid"], numpass=i ) elif ptype == VehiclesConstants.PRIMITIVE_SOURCE: if plot_sources: cairo_plot_circle( cr, center=p["center"], radius=0.05, edgecolor=[0, 0, 0], facecolor=[1, 0, 0], width=0.01 ) # TODO: parametrize else: pass # XXX
def cairo_ref_frame(cr, l=1, x_color=[1, 0, 0], y_color=[0, 1, 0]): with cairo_save(cr): cairo_arrow(cr, length=l, border_width=0.05, border_color=x_color) with cairo_transform(cr, r=np.pi / 2): cairo_arrow(cr, length=l, border_width=0.05, border_color=y_color)
def wing(): rw = r with cairo_save(cr): cr.scale(1.5, 1) cairo_plot_circle2(cr, rw / 2, 0, rw, fill_color=[.5, .5, .5])
def cairo_robot_skin_rectangle(cr, w, h): """ A simple rectangle painted like the robot. """ with cairo_save(cr): cairo_plot_rectangle(cr, -w / 2.0, -h / 2.0, w, h, **CairoConstants.robot_body_style)