Пример #1
0
 def draw_on(self, canvas, top_left):
     x, y = top_left
     dx = (CONNECTOR_SPACING - CONNECTOR_SIZE) / 2
     # state for color bands
     color_indices = resistance_from_string(str(self.r))
     size = 2 * CONNECTOR_SIZE + 3 * CONNECTOR_SPACING
     color_size = 5
     color_spacing = 3
     colors_size = 3 * color_size + 2 * color_spacing
     colors_offset = CONNECTOR_SIZE + (size - colors_size) / 2
     if self.vertical:
         # inner rectangle, i.e. the thin one that is partially covered
         canvas.create_rectangle(x,
                                 y,
                                 x + CONNECTOR_SIZE,
                                 y + 4 * CONNECTOR_SIZE +
                                 3 * CONNECTOR_SPACING,
                                 fill=RESISTOR_INNER_COLOR)
         # outer rectangle, i.e. the fat, short one on top
         canvas.create_rectangle(x - dx,
                                 y + CONNECTOR_SIZE,
                                 x + CONNECTOR_SIZE + dx,
                                 y + 3 * CONNECTOR_SIZE +
                                 3 * CONNECTOR_SPACING,
                                 fill=RESISTOR_OUTER_COLOR)
         for i in xrange(3):
             canvas.create_rectangle(x - dx,
                                     y + colors_offset,
                                     x + CONNECTOR_SIZE + dx,
                                     y + colors_offset + color_size,
                                     fill=RESISTOR_COLORS[color_indices[i]])
             colors_offset += color_size + color_spacing
     else:  # horizontal
         # inner rectangle, i.e. the thin one that is partially covered
         canvas.create_rectangle(x,
                                 y,
                                 x + 4 * CONNECTOR_SIZE +
                                 3 * CONNECTOR_SPACING,
                                 y + CONNECTOR_SIZE,
                                 fill=RESISTOR_INNER_COLOR)
         # outer rectangle, i.e. the fat, short one on top
         canvas.create_rectangle(x + CONNECTOR_SIZE,
                                 y - dx,
                                 x + 3 * CONNECTOR_SIZE +
                                 3 * CONNECTOR_SPACING,
                                 y + CONNECTOR_SIZE + dx,
                                 fill=RESISTOR_OUTER_COLOR)
         for i in xrange(3):
             canvas.create_rectangle(x + colors_offset,
                                     y - dx,
                                     x + colors_offset + color_size,
                                     y + CONNECTOR_SIZE + dx,
                                     fill=RESISTOR_COLORS[color_indices[i]])
             colors_offset += color_size + color_spacing
Пример #2
0
 def draw_on(self, canvas, top_left):
   x, y = top_left
   dx = (CONNECTOR_SPACING - CONNECTOR_SIZE) / 2
   # state for color bands
   color_indices = resistance_from_string(str(self.r))
   size = 2 * CONNECTOR_SIZE + 3 * CONNECTOR_SPACING
   color_size = 5
   color_spacing = 3
   colors_size = 3 * color_size + 2 * color_spacing
   colors_offset = CONNECTOR_SIZE + (size - colors_size) / 2
   if self.vertical:
     # inner rectangle, i.e. the thin one that is partially covered
     canvas.create_rectangle(x, y, x + CONNECTOR_SIZE, y + 4 *
         CONNECTOR_SIZE + 3 * CONNECTOR_SPACING, fill=RESISTOR_INNER_COLOR)
     # outer rectangle, i.e. the fat, short one on top
     canvas.create_rectangle(x - dx, y + CONNECTOR_SIZE, x + CONNECTOR_SIZE +
         dx, y + 3 * CONNECTOR_SIZE + 3 * CONNECTOR_SPACING,
         fill=RESISTOR_OUTER_COLOR)
     for i in xrange(3):
       canvas.create_rectangle(x - dx, y + colors_offset, x + CONNECTOR_SIZE +
           dx, y + colors_offset + color_size, fill=RESISTOR_COLORS[
           color_indices[i]])
       colors_offset += color_size + color_spacing
   else: # horizontal
     # inner rectangle, i.e. the thin one that is partially covered
     canvas.create_rectangle(x, y, x + 4 * CONNECTOR_SIZE + 3 *
         CONNECTOR_SPACING, y + CONNECTOR_SIZE, fill=RESISTOR_INNER_COLOR)
     # outer rectangle, i.e. the fat, short one on top
     canvas.create_rectangle(x + CONNECTOR_SIZE, y - dx, x + 3 *
         CONNECTOR_SIZE + 3 * CONNECTOR_SPACING, y + CONNECTOR_SIZE + dx,
         fill=RESISTOR_OUTER_COLOR)
     for i in xrange(3):
       canvas.create_rectangle(x + colors_offset, y - dx, x + colors_offset +
           color_size, y + CONNECTOR_SIZE + dx, fill=RESISTOR_COLORS[
           color_indices[i]])
       colors_offset += color_size + color_spacing
Пример #3
0
 def to_cmax_str(self):
   self._assert_top_left_loc_set()
   c, r = loc_to_cmax_rep(self.top_left_loc)
   i1, i2, i3 = resistance_from_string(str(self.r))
   return 'resistor(%d,%d,%d): (%d,%d)--(%d,%d)' % (i1, i2, i3, c, r, c, r + 3)
Пример #4
0
 def cmaxify(self, parts, k):
   i1, i2, i3 = resistance_from_string(str(self.r))
   parts.append(('resistor(%d,%d,%d): (%d,%d)--(%d,%d)' % (i1, i2, i3, k, 0, k,
       1), (((k, 0), self.n1), ((k, 1), self.n2))))
   return k + 1
Пример #5
0
 def to_cmax_str(self):
     self._assert_top_left_loc_set()
     c, r = loc_to_cmax_rep(self.top_left_loc)
     i1, i2, i3 = resistance_from_string(str(self.r))
     return 'resistor(%d,%d,%d): (%d,%d)--(%d,%d)' % (i1, i2, i3, c, r, c,
                                                      r + 3)