Esempio n. 1
0
  def draw(self, canvas):
    Plato.draw(self, canvas)
    
    
    # draw a square
    #canvas.set_line_width(1.0)
    #canvas.set_source_rgba(0.7, 1.0, 0.7, 0.5)
    #canvas.rectangle(self.left, self.top, self.width, self.height)
    #canvas.fill()    

    Primitives.rounded_rectangle(canvas, self.left, self.top, self.width, self.height)
    
    # some numbers
    l1 = str((int(self.x),int(self.y))) 
    l2 = 'local:' + str((int(self.width),int(self.height))) 
    l3 = 'world:' + str((int(self.world_width),int(self.world_height)))
    l4 = 'rot:' + str(self.rotation)
    canvas.set_source_rgb(0,0,0)
    canvas.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
    canvas.set_font_size(16.0)
    canvas.move_to(self.left+10,self.top + 30.0)
    canvas.show_text(l1)
    canvas.move_to(self.left+10,self.top + 60.0)
    canvas.show_text(l2)
    canvas.move_to(self.left+10,self.top + 90.0)
    canvas.show_text(l3)
    canvas.move_to(self.left+10,self.top + 120.0)
    canvas.show_text(l4)
Esempio n. 2
0
  def draw(self, context):
    Plato.draw(self, context)

    # init sprites
    if self.buf == None:
      self.buf = self._make_buffer(context)
      
    # border
    context.set_line_width(1.0)
    context.set_source_rgb(0, 0, 0)
    context.rectangle(self.left, self.top, self.width, self.height)
    context.stroke()

    # reset color
    #self.color = lambda context : context.set_source_rgb(1.0, 1.0, 1.0)

    # fast grid
    inc_x = (self.width  / self.resolution_x)
    inc_y = (self.height / self.resolution_y)
     
    for x in range(self.resolution_x):
      for y in range(self.resolution_y):
        cell = self.grid[x*y]
        if cell != 0:
          pos_x = self.left + (x * inc_x) #+ (inc_x / 2.0)
          pos_y = self.top + (y * inc_y) #+ (inc_y / 2.0)
          self.colors[cell](context)
          context.rectangle(pos_x, pos_y, inc_x, inc_y)
          #context.set_source_surface(self.buf, pos_x, pos_y)
          #context.paint()
        self.grid[x*y] = self.fast_random() 
        #self.grid[x*y] = random.randint(0, 2)
        context.fill()
Esempio n. 3
0
 def draw(self, canvas):
   Plato.draw(self, canvas)
   
   canvas.set_line_width(1.0)
   canvas.set_source_rgba(1.0, 0.7, 0.7, 0.5)
   canvas.arc(0.0, 0.0, self.width / 2.0, -math.pi, math.pi)
   canvas.fill()    
Esempio n. 4
0
  def draw(self, canvas):

    #Primitives.rounded_rectangle(canvas, self.left, self.top, self.width, self.height)

    Plato.draw(self, canvas)



    # draw a square
    canvas.set_line_width(1.0)
    canvas.set_source_rgba(0.7, 0.7, 1.0, 0.5)
    canvas.rectangle(self.left, self.top, self.width, self.height)
    canvas.stroke()    
Esempio n. 5
0
 def draw(self, canvas):
   Plato.draw(self, canvas)
   
   canvas.set_line_width(1.0)
   canvas.set_source_rgb(0.0, 0.0, 0.0)
   canvas.rectangle(self.left, self.top, self.width, self.height)
   canvas.fill()    
   
   #self.rotation += 1.0
   #if self.rotation >= 360.0:
   #  self.rotation = 0.0
     
     
 #def set_newton(self, newton):
 #  self._newton = newton
 #  if self._newton is None:
 #    print "body.set_newton() - invalid newton"
 #    return
   #self.ode_init()
                               
Esempio n. 6
0
  def draw(self, context): 
    Plato.draw(self, context)

    # render text border
    if self.lock_zoom:
      context.scale(self.world_width / (self.world_width * TheWorld.scale), 
                    self.world_height / (self.world_height * TheWorld.scale))
    self.draw_background(context, self.left, self.top, self.width, self.height)

    # render the text  & cursor
    context.set_source_rgba(self.color[0], 
                            self.color[1],
                            self.color[2],
                            self.color[3])
    context.move_to(self.left, self.top)
    context.save()
    context.identity_matrix()
    if not self.lock_zoom: # todo - handle scaling when embedded too
      context.scale(TheWorld.scale, TheWorld.scale)
    if not self.lock_rotation:
      context.rotate(math.radians(self.rotation) + TheWorld.rotate)
    context.show_layout(self.layout)
    self.draw_cursor(context)
    context.restore()
Esempio n. 7
0
  def draw(self, context):
    t1 = time.time()
        
    # BEWARE: properties are dog slow! -> TODO check rest of system's inner loops for same
    # cache property lookups
    (width, height, left, right, top, bottom) = (self.width, self.height, self.left, self.right, self.top, self.bottom) 
    
    # a constant flow
    # TODO - slow random numbers 
    x = 1
    s = 10
    for y in range(10, 20, 4): #(self.resolution_y / 2.0), 12, 4):
      element = self.field.element(x, y)
      element.u = 1.0 
      element.v = 0.2 
      element.density = 1.0
      self.field.update_element(element)

    #y = self.field.resolution_y - 3
    #for x in range(10, self.field.resolution_x-3, 25):
    #  e = self.field.element(x, y)
    #  e.u = 0.1
    #  e.v = -2.5
    #  e.density = 5.0
    #  self.field.update_element(e)
    
    # update vector field & particles  
    #self.field.update_velocity()
    #self.field.update_density()        
    #self.field.update_particles(width, height);
    self.field.step(width, height);
    
    t2 = time.time()
    
    Plato.draw(self, context)

    # init sprites
    if self.buf == None:
      self.buf = self._make_buffer(context)
      
    # draw background
    context.set_line_width(1.0)
    context.set_source_rgb(0.90,0.90,1.0)
    context.rectangle(left, top, width, height)
    context.fill()
    context.set_source_rgb(0.0,0.0,1.0)
    context.rectangle(left, top, width, height)
    context.stroke()

    
    if True: # draw vector field
      inc_x = (width  / self.field.resolution_x)
      inc_y = (height / self.field.resolution_y)
      count = 0
      for element in self.field.render_elements(0.01):
        count = count + 1
        if True:  # density
          pos_x = left + (element.x * inc_x)
          pos_y = top + (element.y * inc_y)       
          c = 0.9 - min(0.9, abs(element.density))
          context.set_source_rgb(c,  c, 1.0)
          context.rectangle(pos_x, pos_y, inc_x, inc_y)
          context.fill()        
        if True:  # flow velocity vectors
          pos_x = left + (element.x * inc_x)
          pos_y = top + (element.y * inc_y)                      
          (vx, vy) = (element.u * 50.0, element.v * 50.0)
          (x1, y1) = (pos_x + (inc_x/2), pos_y + (inc_y/2))
          (x2, y2) = (x1 + (vx), y1 + (vy))
          context.set_line_width(0.2)
          context.set_source_rgb(1.0,0.0,0.0)
          context.move_to(x1, y1)
          context.line_to(x2, y2)
          context.stroke()
      #print "rendered: %d elements" % count
    if True: # draw particles
      context.save()
      context.scale(2.0/self.particle_radius,2.0/self.particle_radius) # higher res particles please
      for particle in self.field.particles():
        (x,y) = (particle.position_x, particle.position_y)
        context.set_source_surface(self.buf, x*(self.particle_radius/2.0), y*(self.particle_radius/2.0))
        context.paint()
        #context.rectangle(x, y, self.particle_radius/2.0, self.particle_radius/2.0)
        #context.stroke()
      context.restore()
  
    print 'update:', t2 - t1, 'draw:', time.time() - t2, 'total:', time.time() - t1
Esempio n. 8
0
  def draw(self, context):

    Plato.draw(self, context)
    
    now_time = time.time()
    
    if self.__reactor_output is not None and self.render_valves:
      x,y,z = self.__reactor_output.getPosition()
      w = self.__reactor_output.width
      h = self.__reactor_output.height
      context.set_line_width(0.5)
      #context.move_to(x+r,y)
      context.set_source_rgb(1.0, 0.0, 0.0)
      #context.arc(x, y, r, 0, math.pi * 2.0)
      context.rectangle(x-(w/2), y-(h/2), w, h)
      context.fill()

      # draw input
      r = 10.0
      context.move_to(self.input_x + r, self.input_y)
      context.set_source_rgb(0.0, 1.0, 0.0)
      context.arc(self.input_x, self.input_y, r, 0, math.pi * 2.0)
      context.fill()
      
    # draw lightweight bodies
    count = 0
    for body in self._ode_bodies:
      # check for out of bound particles
      fudge = 60.0 # for reactor outlets
      if self.bounds_check:
        (x,y) = body.position
        if x < self.left-fudge or x > self.right+fudge or y < self.top or y > self.bottom:
          o = body.particle_radius * 2.0
          #print 'out of bounds:', body.position
          if x > 0.0: newx = min(self.right-o, x)
          else:       newx = max(self.left+o, x)
          if y > 0.0: newy = min(self.bottom-o, y)
          else:       newy = max(self.top+o, y)
          body.position = (newx, newy)
          # invert and brake motion vector 
          (vx, vy) = body.velocity
          body.velocity = (-vx/4.0, -vy/4.0)
      
        
      # check particle age
      body_age = now_time - body.create_time        
      # render body
      body.draw(context)
    
    # render rotor
    if self.__rotor is not None:
      self._ode_align_z_axis(self.__rotor) # restrict rotation to 2D      
      rotor = self.__rotor
      x,y,z = rotor.getPosition()
      R = rotor.getRotation()
      
      # convert rotation matrix to euler angle
      attitude = math.asin(R[3]);
      r = math.acos((R[0] + R[4] + R[8] - 1.0) / 2.0)  
      #r = MathLib.matrix_to_euler(R)
      if math.degrees(attitude) < 0:
        r = math.radians((180.0 - math.degrees(r)) + 180.0)
        
      context.save()
      context.translate(x,y)
      context.rotate(r)
      context.set_source_rgb(0.0,0.0,0.0)
      context.rectangle(-rotor.w/2.0, -rotor.h/2.0, rotor.w, rotor.h)
      context.fill()
      context.restore()    
    
    # render walls
    if self.render_walls:
      for wall in self.__ode_walls:
        x,y,z = wall.getPosition()
        context.set_source_rgb(0.0, 1.0, 0.0)
        context.rectangle(x-(wall.w/2.0), y-(wall.h/2.0), wall.w, wall.h)
        context.fill()

    # tank
    #Primitives.rounded_rectangle_bling(context, self.left, self.top, self.width, self.height, r = 10, padding = 0.0)

    # decorations for properties
    if self.mouse_over:      
      if self.mouse_over_property:
        context.set_source_rgb(1.0, 0.0, 0.0)
      else:
        context.set_source_rgb(0.0, 0.0, 0.0)
      context.move_to(0.0 - (self.width/6.0), self.top - self.decorator_size*2.0)
      context.show_text(str(self.num_particles) + ' particles')
      context.set_line_width(4.0)
      context.move_to(0.0 - self.decorator_size, self.top)
      context.arc(0.0, self.top, self.decorator_size, -math.pi, 0.0)
      context.stroke()
Esempio n. 9
0
  def draw(self, context):
    Plato.draw(self, context)
    
    # set up fonts
    context.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
    context.set_font_size(6)
    context.set_source_rgb(0.0, 0.0, 0.0)
    
    # ticks
    num_ticks = 5
    overlap = 3.0
    context.set_line_width(0.5)
    context.set_source_rgb(0.5,0.5,0.5)
    for i in range(-num_ticks, num_ticks, 1):
      inc = (TheWorld.unit_range / num_ticks) * i
      # horizontal
      context.move_to(-TheWorld.unit_range - overlap, inc)
      context.line_to(TheWorld.unit_range, inc)
      context.stroke()
      context.move_to(-TheWorld.unit_range - (overlap * 5.0), inc + 3.0)
      value = abs(i - num_ticks) 
      value = ((self.max/2) / num_ticks) * value
      context.show_text(str(value))
      
      # vertical
      context.move_to((TheWorld.unit_range / num_ticks) + inc, -TheWorld.unit_range)
      context.line_to((TheWorld.unit_range / num_ticks) + inc, TheWorld.unit_range + overlap)
      context.stroke()
      context.move_to((TheWorld.unit_range / num_ticks) + inc - 5.0, TheWorld.unit_range + (overlap * 3.0))
      value = (abs(i + num_ticks) + 1.0) / 2.0 # normalize
      value = (self.numdatapoints / num_ticks) * value # relative to number of samples
      value = value / TheSpaceTime.ticks_per_second # relative to time - TODO NOT ACCURATE!! Measures relative to target ticks not actual
      value = int(value)
      context.show_text(str(value) + "s")
      
    # background  
    #x1 = -TheWorld.unit_range
    #y1 = -TheWorld.unit_range
    #x2 = TheWorld.unit_range
    #y2 = TheWorld.unit_range
    
    #cx1 = -TheWorld.unit_range / 4.0
    #cy1 = -TheWorld.unit_range
    #cx2 = TheWorld.unit_range / 4.0
    #cy2 = TheWorld.unit_range
    
    #context.set_source_rgba(0.9, 0.9, 0.9, 0.5)
    #context.move_to(x1, 0)
    #context.curve_to(cx1, y1, cx2, cy2, TheWorld.unit_range, 0);
    #context.line_to(x2, y1)
    #context.line_to(x1, y1)
    #context.close_path()
    #context.fill()
    
    #context.set_source_rgba(0.9, 0.9, 0.9, 0.7)
    #context.move_to(x1, 0)
    #context.curve_to(cx1, y1, cx2, cy2, TheWorld.unit_range, 0);
    #context.line_to(x2, y2)
    #context.line_to(x1, y2)
    #context.close_path()
    #context.fill()

    context.rectangle(-TheWorld.unit_range, -TheWorld.unit_range, TheWorld.unit_range*2, TheWorld.unit_range*2)
    context.set_source_rgb(0,0,0)    
    context.stroke()      
    
    # axis
    #context.set_source_rgba(0.0, 0.0, 0.0, 0.4)
    #context.move_to(-TheWorld.unit_range, 0.0)
    #context.line_to(TheWorld.unit_range, 0.0)
    #context.stroke()
    
    # plot the data
    for colour in self.datapoints.iterkeys():
      x = -TheWorld.unit_range
      y = 0
      data = self.datapoints[colour]
      if len(data) > 0: 
        y = ((data[0] * TheWorld.unit_range) / (self.max/2)) + TheWorld.unit_range
      y = min(y, TheWorld.unit_range)
      context.move_to(x, y)
      for i in data:
        i *= -TheWorld.unit_range # invert and scale y axis 
        i /= (self.max/2)
        i += TheWorld.unit_range 
        i = max(i, -TheWorld.unit_range)
        context.line_to(x, i)
        x += ((TheWorld.unit_range*2.0) / (self.numdatapoints - 1)) 
      context.set_line_width(0.5)
      context.set_source_rgb(colour[0],colour[1],colour[2])
      context.stroke()
Esempio n. 10
0
 def draw(self, canvas):
   Plato.draw(self, canvas)
   
   canvas.set_line_width(1.0)
   canvas.set_source_rgba(0.7, 1.0, 0.7, 0.5)
   Primitives.circle(canvas, 0.0, 0.0, self.width / 2.0)
Esempio n. 11
0
 def draw(self, canvas):
   Plato.draw(self, canvas)
Esempio n. 12
0
 def draw(self, canvas):
   Button.draw(self, canvas)
   Plato.draw(self, canvas) # for decorations