Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2010-12-24 19:35:01 (GMT)
committer Walter Bender <walter@sugarlabs.org>2010-12-24 19:35:01 (GMT)
commit9b9061f8dbbfef4696226a43285109e3a63146b7 (patch)
treebcdbfbbadef00b9235aaf4e3d879e1b72e675d21
parent2e05bede70d995e2affd57c81a8e4453a8986af6 (diff)
adding luminance block; checking for camera before creating palette entries
-rwxr-xr-x[-rw-r--r--]TurtleArt/audiograb.py1
-rwxr-xr-xTurtleArt/taconstants.py8
-rwxr-xr-x[-rw-r--r--]TurtleArt/tagplay.py1
-rwxr-xr-xTurtleArt/talogo.py48
-rwxr-xr-xTurtleArt/tawindow.py9
5 files changed, 46 insertions, 21 deletions
diff --git a/TurtleArt/audiograb.py b/TurtleArt/audiograb.py
index 0335813..3ecdc11 100644..100755
--- a/TurtleArt/audiograb.py
+++ b/TurtleArt/audiograb.py
@@ -22,7 +22,6 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import pygst
-pygst.require("0.10")
import gst
import gst.interfaces
from numpy import fromstring
diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py
index 4f45663..77ebefb 100755
--- a/TurtleArt/taconstants.py
+++ b/TurtleArt/taconstants.py
@@ -136,7 +136,7 @@ PALETTES = [['clean', 'forward', 'back', 'show', 'left', 'right',
'myfunc1arg', 'userdefined',
'cartesian', 'width', 'height', 'polar', 'addturtle', 'reskin',
'sandwichtop_no_label', 'sandwichbottom'],
- ['kbinput', 'keyboard', 'readpixel', 'see', 'readcamera', 'camera',
+ ['kbinput', 'keyboard', 'readpixel', 'see',
'sound', 'volume', 'pitch'],
['journal', 'audio', 'video', 'description', 'hideblocks',
'showblocks', 'fullscreen', 'savepix', 'savesvg', 'mediawait',
@@ -222,7 +222,8 @@ BOX_STYLE = ['number', 'xcor', 'ycor', 'heading', 'pensize', 'color', 'shade',
'toppos', 'rightpos', 'bottompos', 'width', 'height', 'pop', 'keyboard',
'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'white',
'black', 'titlex', 'titley', 'leftx', 'topy', 'rightx', 'bottomy',
- 'sound', 'volume', 'pitch', 'voltage', 'resistance', 'gray', 'see', 'rfid']
+ 'sound', 'volume', 'pitch', 'voltage', 'resistance', 'gray', 'see', 'rfid',
+ 'luminance']
BOX_STYLE_MEDIA = ['description', 'audio', 'journal', 'video', 'camera']
NUMBER_STYLE = ['plus2', 'product2', 'myfunc']
NUMBER_STYLE_VAR_ARG = ['myfunc1arg', 'myfunc2arg', 'myfunc3arg']
@@ -353,6 +354,7 @@ BLOCK_NAMES = {
'leftx': [_('picture left')],
'less2': ['<'],
'list': ['list'],
+ 'luminance': [_('brightness')],
'mediawait': [_('media wait')],
'minus2': ['–'],
'myfunc': [_('Python'), 'f(x)', 'x'],
@@ -518,6 +520,7 @@ PRIMITIVES = {
'leftx': 'leftx',
'less2': 'less?',
'list': 'bulletlist',
+ 'luminance': 'luminance',
'mediawait': 'mediawait',
'minus2': 'minus',
'myfunc': 'myfunction',
@@ -834,6 +837,7 @@ HELP_STRINGS = {
'leftpos': _("xcor of left of screen"),
'left': _("turns turtle counterclockwise (angle in degrees)"),
'less2': _("logical less-than operator"),
+ 'luminance': _("light level detected by camera"),
'mediawait': _("wait for current video or audio to complete"),
'minus2': _("subtracts bottom numeric input from top numeric input"),
'myfunc': _("a programmable block: used to add advanced math equations, e.g., sin(x)"),
diff --git a/TurtleArt/tagplay.py b/TurtleArt/tagplay.py
index 4be7f5c..dbce7ed 100644..100755
--- a/TurtleArt/tagplay.py
+++ b/TurtleArt/tagplay.py
@@ -33,7 +33,6 @@ import gobject
gobject.threads_init()
import pygst
-pygst.require('0.10')
import gst
import gst.interfaces
import gtk
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py
index 2da8685..37809b8 100755
--- a/TurtleArt/talogo.py
+++ b/TurtleArt/talogo.py
@@ -375,6 +375,7 @@ class LogoCode:
'leftx': [0, lambda self: CONSTANTS['leftx']],
'lpos': [0, lambda self: CONSTANTS['leftpos']],
'less?': [2, lambda self, x, y: _less(x, y)],
+ 'luminance': [0, lambda self: self._read_camera(True)],
'mediawait': [0, self._media_wait, True],
'minus': [2, lambda self, x, y: _minus(x, y)],
'mod': [2, lambda self, x, y: _mod(x, y)],
@@ -1322,8 +1323,9 @@ class LogoCode:
self.filepath = None
dsobject = None
if string[6:] == 'CAMERA':
- save_camera_input_to_file(self.imagepath)
- self.filepath = self.imagepath
+ if self.tw.camera:
+ save_camera_input_to_file(self.imagepath)
+ self.filepath = self.imagepath
elif os.path.exists(string[6:]): # is it a path?
self.filepath = string[6:]
elif self.tw.running_sugar: # is it a datastore object?
@@ -1461,23 +1463,25 @@ class LogoCode:
self.heap.append(g)
self.heap.append(r)
- def _read_camera(self):
+ def _read_camera(self, luminance_only=False):
""" Read average pixel from camera and push b, g, r to the stack """
- save_camera_input_to_file(self.imagepath)
pixbuf = None
+ array = None
w = self._w()
h = self._h()
- if w < 1 or h < 1:
- return
- pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(self.imagepath, w, h)
-
- array = pixbuf.get_pixels()
- length = len(array) / 3
- r = 0
- g = 0
- b = 0
- i = 0
+ if w > 0 and h > 0 and self.tw.camera:
+ save_camera_input_to_file(self.imagepath)
+ pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(self.imagepath, w, h)
+ try:
+ array = pixbuf.get_pixels()
+ except:
+ array = None
if array is not None:
+ length = len(array) / 3
+ r = 0
+ g = 0
+ b = 0
+ i = 0
for j in range(length):
r += ord(array[i])
i += 1
@@ -1485,9 +1489,19 @@ class LogoCode:
i += 1
b += ord(array[i])
i += 1
- self.heap.append(int((b / length)))
- self.heap.append(int((g / length)))
- self.heap.append(int((r / length)))
+ if luminance_only:
+ return int((r * 0.3 + g * 0.6 + b * 0.1) / length)
+ else:
+ self.heap.append(int((b / length)))
+ self.heap.append(int((g / length)))
+ self.heap.append(int((r / length)))
+ else:
+ if luminance_only:
+ return -1
+ else:
+ self.heap.append(-1)
+ self.heap.append(-1)
+ self.heap.append(-1)
def _get_volume(self):
""" return mic in value """
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index ceb9a69..45c5282 100755
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -25,6 +25,7 @@ import pygtk
pygtk.require('2.0')
import gtk
import gobject
+import gst
import os
import os.path
import dbus
@@ -262,6 +263,14 @@ class TurtleArtWindow():
PALETTES[PALETTE_NAMES.index('sensor')].append('voltage')
self.audio_started = False
+ self.camera = False
+ v4l2src = gst.element_factory_make('v4l2src')
+ if v4l2src.props.device_name is not None:
+ PALETTES[PALETTE_NAMES.index('sensor')].append('readcamera')
+ PALETTES[PALETTE_NAMES.index('sensor')].append('luminance')
+ PALETTES[PALETTE_NAMES.index('sensor')].append('camera')
+ self.camera = True
+
"""
The following code will initialize a USB RFID reader. Please note that
in order to make this initialization function work, it is necessary to