def makeButton(string, x, y, width, boxColor, kind): # use my_vars to keep track of the visibility of the color quad my_vars = {"visible": True} def callback(): print "HOTSPOT '%s' was clicked!" % string # toggle the visibility of a drawing element my_vars["visible"] = not my_vars["visible"] win.show_group(shape_color, my_vars["visible"]) if kind == "square": # create color quad separately # this will allow us to refer to later to toggle its visibility shape_color = group(boxColor, shapes.box(x, y, x + width, y + width)) return group( shape_color, colors.white, shapes.box(x, y, x + width, y + width, fill=False), text_scale(string, x + width * 0.1, y + width * 0.1, x + width * 0.9, y + width * 0.9, "center", "middle"), color(1, 1, 1), hotspot("click", x, y, x + width, y + width, callback), ) elif kind == "circle": # create color shape separately # this will allow us to refer to later to toggle its visibility shape_color = group(boxColor, shapes.regular_polygon(x, y, 50, width)) return group( shape_color, colors.white, shapes.regular_polygon(x, y, 50, width, fill=False), text_scale(string, x - width * 0.7, y - width * 0.7, x + width * 0.7, y + width * 0.7, "center", "middle"), color(1, 1, 1), hotspot_circle("click", x, y, width, callback), ) elif kind == "polygon": # create color shape separately # this will allow us to refer to later to toggle its visibility pts = [0, 0, 30, 100, 50, 100, 80, 0] shape_color = group(boxColor, polygon(*pts)) return translate( x, y, scale( 0.1, 0.1, shape_color, colors.white, line_strip(80, 0, *pts), text_scale(string, 0, 20, 80, 80, "center", "middle"), color(1, 1, 1), hotspot_polygon("click", pts, callback), ), )
def update(self): if self.vis == None: return # plan actions self.plan() # update physics self.update_physics() if self.closest: ptr = group( color(self.color[0], self.color[1], self.color[2], 0.9), lines(self.pos[0], self.pos[1], self.closest.pos[0], self.closest.pos[1]), ) else: ptr = group() # update graphics vis = group( translate(self.pos[0], self.pos[1], color(*self.color), shapes.regular_polygon(0, 0, 8, self.size)), ptr ) if self.vis_ship: # self.vis_ship = game.win.replace_group(self.vis_ship, vis) self.vis_ship = self.vis.replace(self.vis_ship, vis) else: self.vis_ship = self.vis.append(vis)
def draw_node(node): # get node position pos = node.get_pos() if pos == None: # node is incomplete, skip return group() x, y = map(float, pos.split(",")) # get node size size = (node.get_width(), node.get_height()) if size == (None, None): size = (1.0, 1.0) else: size = map(float, size) node_radius = 37 label_radius = 30 fill_color = colors.blue text_color = colors.white nsides = 20 # get node name name = node.get_name() name = name[1:-1] return translate( x, y, zoom_clamp( # node fill fill_color, scale(size[0], size[1], shapes.regular_polygon(0, 0, nsides, node_radius)), # text label zoom_clamp( text_color, text_scale(name, -label_radius*size[0], -label_radius*size[-1], label_radius*size[0], label_radius*size[1], "center", "middle"), minx=.5, miny=.5, maxx=1, maxy=1, link=True, clip=True, link_type="smaller"), minx=.1, maxx=1, miny=.1, maxy=1, link=True, clip=True, link_type="smaller"))
def draw(self): orth = [self.vel[1], -self.vel[0]] orth = util.vmuls(orth, self.size / util.vmag(orth)) return group(colors.red, shapes.regular_polygon(self.pos[0], self.pos[1], 30, self.size), quads(color(1, 0, 0, .5), self.pos[0] + orth[0], self.pos[1] + orth[1], self.pos[0] - orth[0], self.pos[1] - orth[1], color(1, 0, 0, 0), self.pos[0] - 10*self.vel[0] - orth[0], self.pos[1] - 10*self.vel[1] - orth[1], self.pos[0] - 10*self.vel[0] + orth[0], self.pos[1] - 10*self.vel[1] + orth[1] ))
def draw(self): """Method for draw a ball""" colorval = (self.vy + 3) / 6.0 if self.group == None: self.color = group(color(colorval, self.activate, 1)) self.group = win.add_group( translate(self.x, self.y, self.color, shapes.regular_polygon(0, 0, 20, self.size), hotspot("click", - 2 * self.size, - 2*self.size, 2*self.size, 2*self.size, self.on_click))) else: self.group.set(self.x, self.y) self.color = self.color.replace_self(group(color(colorval, self.activate, 1)))
#!/usr/bin/env python-i from summon.core import * from summon import shapes, colors import summon win = summon.Window("zoom_clamp") win.add_group(group(zoom_clamp(colors.blue, shapes.regular_polygon(0, 0, 10, 10), maxx=3, maxy=3, minx=1, miny=1, clip=True), translate(0, 100, zoom_clamp(colors.red, shapes.regular_polygon(0, 0, 10, 10), translate(0, 10, color(1, .5, .5), shapes.regular_polygon(0, 0, 10, 2)), translate(0, -10, zoom_clamp( color(1, .5, .5), shapes.regular_polygon(0, 0, 10, 2), maxx=5, maxy=5, minx=1, miny=1)), maxx=3, maxy=3, minx=1, miny=1, link=True)), rotate(30, colors.white, lines(0, 0, 100, 0), translate(100, 0, lines(0, 0, -30, -30),
#!/usr/bin/env python-i import summon from summon.core import * from summon import shapes, colors step = 50 win = summon.Window("zoom_clamp2") vis = [] for i in xrange(101): for j in xrange(101): s = .01 * i vis.append(translate(i*step, j*step, zoom_clamp(colors.red, shapes.regular_polygon(0, 0, 10, 5), minx=s, miny=s, maxx=1, maxy=1))) win.add_group(group(*vis)) win.add_group(group(colors.white, shapes.box(0, 0, 100*step, 100*step, fill=False))) win.home()
def draw(self): return group(color(.3, .3, .9), shapes.regular_polygon(self.pos[0], self.pos[1], 30, self.size))