Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2012-11-12 22:35:34 (GMT)
committer Walter Bender <walter.bender@gmail.com>2012-11-12 22:35:34 (GMT)
commit3b05750cd6ce0a3bc8cb7f02a8e96a9ce3d8ef00 (patch)
tree54d9deba1fa8bf75f263f39659fdcc822a5c6192
parent168c347ff5d25a11c8428465dc3d099d3fa37d26 (diff)
added color paint
-rw-r--r--ReflectionActivity.py19
-rw-r--r--game.py36
-rw-r--r--icons/my-colors.svg8
-rw-r--r--toolbar_utils.py4
4 files changed, 54 insertions, 13 deletions
diff --git a/ReflectionActivity.py b/ReflectionActivity.py
index 4a25ea7..318413f 100644
--- a/ReflectionActivity.py
+++ b/ReflectionActivity.py
@@ -24,7 +24,8 @@ if _have_toolbox:
from sugar.activity.widgets import ActivityToolbarButton
from sugar.activity.widgets import StopButton
-from toolbar_utils import button_factory, label_factory, separator_factory
+from toolbar_utils import button_factory, label_factory, separator_factory, \
+ radio_factory
from utils import json_load, json_dump
import telepathy
@@ -110,6 +111,12 @@ class ReflectionActivity(activity.Activity):
toolbox.set_current_toolbar(1)
self.toolbar = games_toolbar
+ my_colors = radio_factory(
+ 'my-colors', self.toolbar, self._my_colors_cb, group=None)
+
+ radio_factory('toolbar-colors', self.toolbar,
+ self._roygbiv_colors_cb, group=my_colors)
+
self._new_game_button_h = button_factory(
'new-game-horizontal', self.toolbar, self._new_game_cb,
cb_arg='horizontal',
@@ -143,6 +150,16 @@ class ReflectionActivity(activity.Activity):
toolbox.toolbar.insert(stop_button, -1)
stop_button.show()
+ def _my_colors_cb(self, button=None):
+ if hasattr(self, '_game'):
+ self._game.roygbiv = False
+ self._game.new_game()
+
+ def _roygbiv_colors_cb(self, button=None):
+ if hasattr(self, '_game'):
+ self._game.roygbiv = True
+ self._game.new_game()
+
def _new_game_cb(self, button=None, orientation='horizontal'):
''' Start a new game. '''
self._game.new_game(orientation)
diff --git a/game.py b/game.py
index c46f2c7..acf0419 100644
--- a/game.py
+++ b/game.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-#Copyright (c) 2011 Walter Bender
+#Copyright (c) 2011-12 Walter Bender
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -41,10 +41,17 @@ class Game():
def __init__(self, canvas, parent=None, colors=['#A0FFA0', '#FF8080']):
self._activity = parent
- self._colors = ['#FFFFFF']
- self._colors.append(colors[0])
+ self._colors = [colors[0]]
self._colors.append(colors[1])
+ self._colors.append('#FFFFFF')
self._colors.append('#000000')
+ self._colors.append('#FF0000')
+ self._colors.append('#FF8000')
+ self._colors.append('#FFFF00')
+ self._colors.append('#00FF00')
+ self._colors.append('#00FFFF')
+ self._colors.append('#0000FF')
+ self._colors.append('#FF00FF')
self._canvas = canvas
if parent is not None:
@@ -70,6 +77,7 @@ class Game():
self._press = False
self.last_spr = None
self._timer = None
+ self.roygbiv = False
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
@@ -82,8 +90,8 @@ class Game():
Sprite(self._sprites,
xoffset + x * (self._dot_size + self._space),
y * (self._dot_size + self._space),
- self._new_dot(self._colors[0])))
- self._dots[-1].type = 0 # not set
+ self._new_dot(self._colors[2])))
+ self._dots[-1].type = 2 # not set
self._dots[-1].set_label_attributes(40)
self.vline = Sprite(self._sprites,
@@ -102,9 +110,8 @@ class Game():
def _all_clear(self):
''' Things to reinitialize when starting up a new game. '''
for dot in self._dots:
- if dot.type > 0:
- dot.type = 0
- dot.set_shape(self._new_dot(self._colors[0]))
+ dot.type = 2
+ dot.set_shape(self._new_dot(self._colors[2]))
dot.set_label('')
self._set_orientation()
@@ -121,6 +128,7 @@ class Game():
self.hline.set_layer(1000)
self.vline.set_layer(1000)
+ '''
if self._orientation == 'horizontal':
self._set_label(
_('Click on the dots to make a horizontal reflection.'))
@@ -130,6 +138,7 @@ class Game():
else:
self._set_label(
_('Click on the dots to make a bilateral reflection.'))
+ '''
def _initiating(self):
return self._activity.initiating
@@ -143,7 +152,10 @@ class Game():
# Fill in a few dots to start
for i in range(int(TEN * SIX / 2)):
n = int(uniform(0, TEN * SIX))
- self._dots[n].type = int(uniform(0, 4))
+ if self.roygbiv:
+ self._dots[n].type = int(uniform(2, len(self._colors)))
+ else:
+ self._dots[n].type = int(uniform(0, 4))
self._dots[n].set_shape(self._new_dot(
self._colors[self._dots[n].type]))
@@ -195,7 +207,11 @@ class Game():
def _increment_dot(self, spr):
spr.type += 1
- spr.type %= 4
+ if self.roygbiv:
+ if spr.type >= len(self._colors):
+ spr.type = 2
+ else:
+ spr.type %= 4
spr.set_shape(self._new_dot(self._colors[spr.type]))
if self.playing_with_robot:
diff --git a/icons/my-colors.svg b/icons/my-colors.svg
new file mode 100644
index 0000000..ff589f2
--- /dev/null
+++ b/icons/my-colors.svg
@@ -0,0 +1,8 @@
+<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"><g display="block" id="toolbar_x5F_colors">
+ <g>
+ <circle cx="15.63" cy="39.5" fill="#FFFFFF" r="10" stroke="#FFFFFF" stroke-width="2.25"/>
+ <circle cx="39.834" cy="39.5" fill="#808080" r="10" stroke="#FFFFFF" stroke-width="2.25"/>
+ <circle cx="15.167" cy="15.5" fill="#000000" r="10" stroke="#FFFFFF" stroke-width="2.25"/>
+ <circle cx="39.666" cy="15.5" r="10" stroke="#A0A0A0" stroke-width="2.25"/>
+ </g>
+</g></svg>
diff --git a/toolbar_utils.py b/toolbar_utils.py
index 94e6883..d17f959 100644
--- a/toolbar_utils.py
+++ b/toolbar_utils.py
@@ -83,11 +83,11 @@ def button_factory(icon_name, toolbar, callback, cb_arg=None, tooltip=None,
return button
-def radio_factory(name, toolbar, callback, cb_arg=None, tooltip=None,
+def radio_factory(icon_name, toolbar, callback, cb_arg=None, tooltip=None,
group=None):
''' Add a radio button to a toolbar '''
button = RadioToolButton(group=group)
- button.set_named_icon(name)
+ button.set_named_icon(icon_name)
if callback is not None:
if cb_arg is None:
button.connect('clicked', callback)