Ejemplo n.º 1
0
def SurroundLayout(width, height, source_widget, subwidgets_of, scale=1, subwidgets_center_offset=None):
    if subwidgets_center_offset is None:
        subwidgets_center_offset = Point(0,source_widget.size.norm()*scale)
        span = pi
    else:
        span = pi
    source_widget.scale = scale
    subwidgets = reversed(sorted((widget.order.sublevel, widget) for widget in list(subwidgets_of(source_widget))))
    subwidgets = list(subwidgets)
    num = len(subwidgets)
    if num <= 1:
        return
    center_angle = subwidgets_center_offset.angle() - (span/2)
    radius = subwidgets_center_offset.norm()
    angle_step = span/(num-1)
    center = source_widget.pos
    for i,(sublevel, subwidget) in enumerate(subwidgets):
        angle = center_angle + angle_step*i
        subwidget.pos = center + Point.from_polar(angle, radius)
        new_offset = Point.from_polar(angle, radius/3.0)
        SurroundLayout(width, height, subwidget, subwidgets_of, scale=scale*0.8, subwidgets_center_offset=new_offset)
Ejemplo n.º 2
0
    def update_pos(self):
        
        #self._pos += (self.target_pos - self._pos)*self.speed
        global_scale = 0.5
        
        self.accel = Point(0,0) #(self.target_pos - self._pos)*self.speed
        for puller in self.puller_node.iter_all_connections():
            w = puller.value
            this_scale = global_scale
            if w in [n.value for n in self.node.connections['out']]:
                # Decrease forces!
                this_scale = global_scale*2.0
                
            vec = (w.pos - self.pos)
            r = vec.norm()
            if r==0:
                continue
            vec = vec*r*(1/(self.scale*12.0*this_scale))
            if vec.norm() > 15: # don't let them get too close!
                self.accel += vec
            else:
                self.accel -= vec
        for pusher in self.pusher_node.iter_all_connections():
            w = pusher.value
            vec = (w.pos - self.pos)
            r = vec.norm()
            if r==0:
                continue
            vec = vec*(1/r)*(self.scale*1500*global_scale)
            if vec.norm() > 15: # don't let them get too close!
                self.accel -= vec
            else:
                self.accel += vec

            
        self.vel += self.accel
        self.vel *= 0.02 # "friction"
        if (self.vel.norm() > self.MAX_VEL):
            self.vel = Point.from_polar(self.vel.angle(), self.MAX_VEL)

        
        self.pos += self.vel
        self._pos = self.pos