[gcompris: 83/111] added colors of light too in color_mix



commit ce923783f64a86a7201ec9fa02eef6dac3b16983
Author: serah <serah4291 gmail com>
Date:   Mon Aug 20 03:33:07 2012 +0530

    added colors of light too in color_mix

 src/color_mix-activity/color_mix.py                |  120 +++++++++++++++----
 src/color_mix-activity/color_mix.xml.in            |    8 +-
 .../resources/color_mix/Makefile.am                |    3 +
 .../resources/color_mix/torch_blue.png             |  Bin 0 -> 25788 bytes
 .../resources/color_mix/torch_green.png            |  Bin 0 -> 28830 bytes
 .../resources/color_mix/torch_red.png              |  Bin 0 -> 31292 bytes
 6 files changed, 104 insertions(+), 27 deletions(-)
---
diff --git a/src/color_mix-activity/color_mix.py b/src/color_mix-activity/color_mix.py
index 3dc7fd2..4177876 100644
--- a/src/color_mix-activity/color_mix.py
+++ b/src/color_mix-activity/color_mix.py
@@ -36,6 +36,7 @@ class Gcompris_color_mix:
   def __init__(self, gcomprisBoard):
     self.gcomprisBoard = gcomprisBoard
     self.game_complete = False
+    self.mode = 1
 
     # Needed to get key_press
     gcomprisBoard.disable_im_context = True
@@ -70,15 +71,56 @@ class Gcompris_color_mix:
     m_points = goocanvas.Points( [(390, 352), (390, 470)] )
     y_points = goocanvas.Points( [(548, 208), (665, 175)] )
 
-    colors = Colors(self, self.rootitem)
+    colors = Colors(self, self.rootitem, self.mode)
+
+    if self.mode == 1:
+      text_mode = _('Switch to light')
+      # Pass the points of the buttons and slider for the color tubes
+      cyan_tube = Color_tubes(self.rootitem, colors, 'cyan_tube.png',
+                              1, 80, 120, c_points, 242, 210, 130, 175, self.mode)
+      magenta_tube = Color_tubes(self.rootitem, colors, 'magenta_tube.png',
+                                 2, 350, 290, m_points, 390, 352, 390, 470, self.mode)
+      yellow_tube = Color_tubes(self.rootitem, colors, 'yellow_tube.png',
+                                3, 460, 120, y_points, 548, 208, 665, 175, self.mode)
+    else:
+      r_points = goocanvas.Points( [(242, 212), (130, 177)] )
+      b_points = goocanvas.Points( [(548, 213), (665, 177)] )
+      m_points = goocanvas.Points( [(390, 372), (390, 490)] )
+      text_mode = _('Switch to paint')
+      # Pass the points of the buttons and slider for the color tubes
+      red_tube = Color_tubes(self.rootitem, colors, 'torch_red.png',
+                              1, 90, 115, r_points, 232, 210, 120, 175, self.mode)
+      green_tube = Color_tubes(self.rootitem, colors, 'torch_green.png',
+                                 2, 265, 265, m_points, 390, 372, 390, 490, self.mode)
+      blue_tube = Color_tubes(self.rootitem, colors, 'torch_blue.png',
+                                3, 462, 115, b_points, 554, 210, 672, 175, self.mode)
+
+    # Switch button
+    text = goocanvas.Text(
+      parent = self.rootitem,
+      x = 200,
+      y = 403,
+      fill_color = "black",
+      anchor = gtk.ANCHOR_CENTER,
+      alignment = pango.ALIGN_CENTER,
+      text = text_mode )
+    text.connect('button_press_event', self.switch, self.mode, False)
+    bounds = text.get_bounds()
+    gap = 20
 
-    # Pass the points of the buttons and slider for the color tubes
-    cyan_tube = Color_tubes(self.rootitem, colors, 'cyan_tube.png',
-                            1, 80, 120, c_points, 242, 210, 130, 175)
-    magenta_tube = Color_tubes(self.rootitem, colors, 'magenta_tube.png',
-                               2, 350, 290, m_points, 390, 352, 390, 470)
-    yellow_tube = Color_tubes(self.rootitem, colors, 'yellow_tube.png',
-                              3, 460, 120, y_points, 548, 208, 665, 175)
+    text_back = goocanvas.Rect(
+      parent = self.rootitem,
+      radius_x = 6,
+      radius_y = 6,
+      x = bounds.x1 - gap,
+      y = bounds.y1 - gap,
+      width = bounds.x2 - bounds.x1 + gap * 2,
+      height = bounds.y2 - bounds.y1 + gap * 2,
+      stroke_color_rgba = 0xFFFFFFFFL,
+      fill_color_rgba = 0xCCCCCC44L)
+    gcompris.utils.item_focus_init(text_back, None)
+    gcompris.utils.item_focus_init(text, text_back)
+    text_back.connect('button_press_event', self.switch, self.mode)
 
   def game_over(self, result):
     self.game_complete = True
@@ -117,16 +159,30 @@ class Gcompris_color_mix:
   def set_level(self, level):
     pass
 
+  def switch(self, widget, target, event, mode):
+    # Switch between paint and light
+    if mode == 1:
+      self.mode = 2
+    elif mode == 2:
+      self.mode = 1
+    self.end()
+    self.start()
+
 class Color_tubes:
   """ Class containing the three primary color tubes"""
 
 
   def __init__(self, rootitem, color_instance, image, primary_color,
-               x, y, points, incr_x, incr_y, decr_x, decr_y):
+               x, y, points, incr_x, incr_y, decr_x, decr_y, mode):
     self.rootitem = rootitem
     self.primary_color = primary_color
     self.color_instance = color_instance
 
+    if mode == 1:
+      self.alter = -1
+    else:
+      self.alter = 1
+
     # Load the tube image
     image = 'color_mix/' + image
     pixbuf = gcompris.utils.load_pixmap(image)
@@ -205,21 +261,31 @@ class Color_tubes:
 
   def set_color(self, change):
     if self.primary_color == 1:
-      self.color_instance.cyan += int(change * -1)
+      self.color_instance.color1 += int(change * self.alter)
       self.color_instance.resultant_color(1)
     elif self.primary_color == 2:
-      self.color_instance.magenta += int(change * -1)
+      self.color_instance.color2 += int(change * self.alter)
       self.color_instance.resultant_color(2)
     if self.primary_color == 3:
-      self.color_instance.yellow += int(change * -1)
+      self.color_instance.color3 += int(change * self.alter)
       self.color_instance.resultant_color(3)
 
 class Colors:
   """ Class containing all the colors"""
 
 
-  def __init__(self, game, rootitem):
+  def __init__(self, game, rootitem, mode):
     self.game = game
+    self.mode = mode
+
+    if mode == 1:
+      initial_color = 0xFFFFFFFFL
+      self.color_rgb = [255, 255, 255]
+      self.color1 = self.color2 = self.color3 = 255
+    else:
+      initial_color = 0x000000FFL
+      self.color_rgb = [0, 0, 0]
+      self.color1 = self.color2 = self.color3 = 0
 
     self.color_image = goocanvas.Ellipse(
       parent = rootitem,
@@ -227,8 +293,8 @@ class Colors:
       center_y = 230,
       radius_y = 60,
       radius_x = 75,
-      stroke_color_rgba = 0xFFFFFFFFL,
-      fill_color_rgba = 0xFFFFFFFFL,
+      stroke_color_rgba = initial_color,
+      fill_color_rgba = initial_color,
       line_width = 0.5)
 
     # Random color to be matched
@@ -248,7 +314,7 @@ class Colors:
       fill_color_rgba = long(code, 16))
 
 
-    # OK Buttonp
+    # OK Button
     ok = goocanvas.Svg(parent = rootitem,
                        svg_handle = gcompris.skin.svg_get(),
                        svg_id = "#OK"
@@ -258,10 +324,6 @@ class Colors:
     ok.connect("button_press_event", self.ok_event)
     gcompris.utils.item_focus_init(ok, None)
 
-    # initialise variables
-    self.color_rgb = [255, 255, 255]
-    self.cyan = self.magenta = self.yellow = 255
-
   def ok_event(self, widget, target, event):
     if self.color_rgb[0] - 30 < self.r_random < self.color_rgb[0] + 30 and \
        self.color_rgb[1] - 30 < self.g_random < self.color_rgb[1] + 30 and \
@@ -271,9 +333,9 @@ class Colors:
       self.game.game_over(2)
 
   def resultant_color(self, change):
-    cyan_cmy  = (255 - self.cyan, 0, 0)
-    magenta_cmy  = (0, 255 - self.magenta, 0)
-    yellow_cmy  = (0, 0, 255 - self.yellow)
+    cyan_cmy  = (255 - self.color1, 0, 0)
+    magenta_cmy  = (0, 255 - self.color2, 0)
+    yellow_cmy  = (0, 0, 255 - self.color3)
 
     color_cmy = [255 - self.color_rgb[0], 255 - self.color_rgb[1],
                  255 - self.color_rgb[2]]
@@ -285,9 +347,15 @@ class Colors:
     elif change == 3:
       color_cmy[2] = (color_cmy[2] + yellow_cmy[2]) / 2
 
-    self.color_rgb[0] = 255 - color_cmy[0]
-    self.color_rgb[1] = 255 - color_cmy[1]
-    self.color_rgb[2] = 255 - color_cmy[2]
+    if self.mode == 1:
+      self.color_rgb[0] = 255 - color_cmy[0]
+      self.color_rgb[1] = 255 - color_cmy[1]
+      self.color_rgb[2] = 255 - color_cmy[2]
+
+    else:
+      self.color_rgb[0] = self.color1
+      self.color_rgb[1] = self.color2
+      self.color_rgb[2] = self.color3
 
     color_code = self.hex_code(self.color_rgb[0], self.color_rgb[1],
                                self.color_rgb[2])
diff --git a/src/color_mix-activity/color_mix.xml.in b/src/color_mix-activity/color_mix.xml.in
index 6415c3a..4f5f27f 100644
--- a/src/color_mix-activity/color_mix.xml.in
+++ b/src/color_mix-activity/color_mix.xml.in
@@ -13,7 +13,13 @@
         <_description>To understand color mixing</_description>
         <_goal>Mix the primary colors to match to the given color</_goal>
         <_manual xml:space = 'preserve'>
-The activity deals with mixing colors using paint, inks, or dyes. The inks absorb different colors of light, subtracting it from what you see. The more ink you add, the more light is absorbed, and the darker the combined color gets. Just the opposite of mixing color with lights! Again, we can mix just three primary colors to make many new colors. The primary colors for paint/ink are Cyan (a special shade of blue), Magenta (a special shade of pink), and Yellow.
+The activity deals with mixing primary colors of paint and also primary colors of light.
+
+In case of paints the inks absorb different colors of light falling on it, subtracting it from what you see. The more ink you add, the more light is absorbed, and the darker the combined color gets. We can mix just three primary colors to make many new colors. The primary colors for paint/ink are Cyan (a special shade of blue), Magenta (a special shade of pink), and Yellow.
+
+Whereas in case of light it is just the opposite of mixing color with paints! The more light you add the lighter the resultant color will get. Primary colors of light are red, green and blue.
+
+Switch between paint and light to see how they differ.
         </_manual>
         <_credit>Openclipart.org</_credit>
   </Board>
diff --git a/src/color_mix-activity/resources/color_mix/Makefile.am b/src/color_mix-activity/resources/color_mix/Makefile.am
index 3bae896..1c8c27b 100644
--- a/src/color_mix-activity/resources/color_mix/Makefile.am
+++ b/src/color_mix-activity/resources/color_mix/Makefile.am
@@ -3,6 +3,9 @@ img_DATA = \
 	background.jpg \
 	cyan_tube.png \
 	magenta_tube.png \
+	torch_blue.png \
+	torch_red.png \
+	torch_green.png \
 	yellow_tube.png
 
 EXTRA_DIST = $(img_DATA)
diff --git a/src/color_mix-activity/resources/color_mix/torch_blue.png b/src/color_mix-activity/resources/color_mix/torch_blue.png
new file mode 100644
index 0000000..f2706a6
Binary files /dev/null and b/src/color_mix-activity/resources/color_mix/torch_blue.png differ
diff --git a/src/color_mix-activity/resources/color_mix/torch_green.png b/src/color_mix-activity/resources/color_mix/torch_green.png
new file mode 100644
index 0000000..7cba8a3
Binary files /dev/null and b/src/color_mix-activity/resources/color_mix/torch_green.png differ
diff --git a/src/color_mix-activity/resources/color_mix/torch_red.png b/src/color_mix-activity/resources/color_mix/torch_red.png
new file mode 100644
index 0000000..5ab2005
Binary files /dev/null and b/src/color_mix-activity/resources/color_mix/torch_red.png differ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]