diff options
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | activity/activity.info | 2 | ||||
-rw-r--r-- | plugins/camera_sensor/camera_sensor.py | 67 | ||||
-rw-r--r-- | samples/urban_landscape.ta | 136 |
4 files changed, 180 insertions, 30 deletions
@@ -1,3 +1,8 @@ +110 + +BUG FIX +* Fixed regression problem with brightness block + 109 ENHANCEMENTS diff --git a/activity/activity.info b/activity/activity.info index 14b5b59..bfbbaf6 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,6 +1,6 @@ [Activity] name = Turtle Art -activity_version = 109 +activity_version = 110 license = MIT bundle_id = org.laptop.TurtleArtActivity exec = sugar-activity TurtleArtActivity.TurtleArtActivity diff --git a/plugins/camera_sensor/camera_sensor.py b/plugins/camera_sensor/camera_sensor.py index a9f8684..3b32be9 100644 --- a/plugins/camera_sensor/camera_sensor.py +++ b/plugins/camera_sensor/camera_sensor.py @@ -56,7 +56,6 @@ class Camera_sensor(Plugin): help_string=_('Palette of sensor blocks')) # set up camera-specific blocks - primitive_dictionary['luminance'] = self.prim_read_camera primitive_dictionary['read_camera'] = self.prim_read_camera media_blocks_dictionary['camera'] = self.prim_take_picture @@ -68,7 +67,7 @@ class Camera_sensor(Plugin): value_block=True, prim_name='luminance') self._parent.lc.def_prim('luminance', 0, - lambda self: primitive_dictionary['luminance']( + lambda self: primitive_dictionary['read_camera']( luminance_only=True)) # Depreciated block @@ -79,7 +78,7 @@ class Camera_sensor(Plugin): help_string=_('Average RGB color from camera \ is pushed to the stack'), value_block=True, - prim_name='luminance') + prim_name='read_camera') self._parent.lc.def_prim('read_camera', 0, lambda self: primitive_dictionary['read_camera']()) @@ -96,9 +95,9 @@ is pushed to the stack'), label=_('brightness'), help_string=_('light level detected by camera'), value_block=True, - prim_name='luminance') + prim_name='read_camera') self._parent.lc.def_prim('luminance', 0, - lambda self: primitive_dictionary['luminance']( + lambda self: primitive_dictionary['read_camera']( luminance_only=True)) # Depreciated block @@ -109,7 +108,7 @@ is pushed to the stack'), help_string=_('Average RGB color from camera \ is pushed to the stack'), value_block=True, - prim_name='luminance') + prim_name='read_camera') self._parent.lc.def_prim('read_camera', 0, lambda self: primitive_dictionary['read_camera']()) @@ -134,7 +133,8 @@ is pushed to the stack'), self._camera.stop_camera_input() def _status_report(self): - debug_output('Reporting camera status: %s' % (str(self._status))) + debug_output('Reporting camera status: %s' % (str(self._status)), + self._parent.running_sugar) return self._status # Block primitives used in talogo @@ -162,39 +162,25 @@ is pushed to the stack'), pixbuf = None array = None - w = 4 - h = 3 + if self._status: try: self._video_capture_device = open('/dev/video0', 'rw') except: self._video_capture_device = None - debug_output('video capture device not available') - - if self._video_capture_device is not None: - self._ag_control = v4l2_control(V4L2_CID_AUTOGAIN) - try: - ioctl(self._video_capture_device, VIDIOC_G_CTRL, - self._ag_control) - self._ag_control.value = 0 # disable AUTOGAIN - ioctl(self._video_capture_device, VIDIOC_S_CTRL, - self._ag_control) - except: - # debug_output('AUTOGAIN control not available') - pass - - if self._video_capture_device is not None: - self._video_capture_device.close() + debug_output('video capture device not available', + self._parent.running_sugar) - self._camera.save_camera_input_to_file() - self._camera.stop_camera_input() - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(self._imagepath, - w, h) + self._set_autogain(0) # disable AUTOGAIN + + pixbuf = self._get_pixbuf_from_camera() try: array = pixbuf.get_pixels() except: array = None + self._set_autogain(1) # reenable AUTOGAIN + if array is not None: length = len(array) / 3 r, g, b, i = 0, 0, 0, 0 @@ -220,3 +206,26 @@ is pushed to the stack'), self._parent.lc.heap.append(-1) self._parent.lc.heap.append(-1) self._parent.lc.heap.append(-1) + + def _set_autogain(self, state): + ''' 0 is off; 1 is on ''' + if self._video_capture_device is not None: + self._ag_control = v4l2_control(V4L2_CID_AUTOGAIN) + try: + ioctl(self._video_capture_device, VIDIOC_G_CTRL, + self._ag_control) + self._ag_control.value = state + ioctl(self._video_capture_device, VIDIOC_S_CTRL, + self._ag_control) + except: + pass + + def _get_pixbuf_from_camera(self): + ''' Regardless of how we get it, we want to return a pixbuf ''' + if self._video_capture_device is not None: + self._video_capture_device.close() + self._camera.save_camera_input_to_file() + self._camera.stop_camera_input() + return gtk.gdk.pixbuf_new_from_file(self._imagepath) + else: + return None diff --git a/samples/urban_landscape.ta b/samples/urban_landscape.ta new file mode 100644 index 0000000..f988e25 --- /dev/null +++ b/samples/urban_landscape.ta @@ -0,0 +1,136 @@ +[[0, ["start", 2.0], 579, 84, [null, 74]], +[1, "forward", 1189, 800, [5, 4, 2]], +[2, "right", 1189, 842, [1, 3, null]], +[3, ["number", 90], 1247, 842, [2, null]], +[4, "box1", 1261, 800, [1, null]], +[5, "repeat", 1127, 740, [8, 6, 1, 9]], +[6, ["number", 4], 1175, 740, [5, null]], +[7, ["vspace", 0], 1127, 860, [9, 18]], +[8, "startfill", 1127, 698, [22, 5]], +[9, "stopfill", 1127, 818, [5, 7]], +[10, "repeat", 1127, 986, [12, 11, 13, 48]], +[11, ["number", 4], 1175, 986, [10, null]], +[12, ["vspace", 0], 1127, 944, [18, 10]], +[13, "forward", 1189, 1046, [10, 16, 14]], +[14, "right", 1189, 1088, [13, 15, null]], +[15, ["number", 90], 1247, 1088, [14, null]], +[16, "box1", 1261, 1046, [13, null]], +[17, "storeinbox1", 579, 252, [92, 94, 119]], +[18, "setshade", 1127, 902, [7, 21, 12]], +[19, ["number", 50.0], 1267, 944, [21, null]], +[20, "shade", 1267, 902, [21, null]], +[21, ["plus2", 0], 1213, 902, [18, 20, 19]], +[22, "seth", 1127, 656, [25, 23, 8]], +[23, ["number", 45.0], 1185, 656, [22, null]], +[24, "hat1", 76, 572, [null, 26]], +[25, "hat2", 1127, 614, [null, 22]], +[26, "seth", 76, 614, [24, 27, 77]], +[27, ["number", 180.0], 134, 614, [26, null]], +[28, "ycor", 249, 656, [30, null]], +[29, "bottompos", 273, 698, [30, null]], +[30, ["minus2", 0], 195, 656, [77, 28, 29]], +[31, "forward", 138, 800, [37, 78, 40]], +[32, "forward", 138, 884, [40, 76, 36]], +[33, ["number", 2.0], 318, 926, [34, null]], +[34, "sqrt", 264, 926, [76, 33]], +[35, "box1", 264, 884, [76, null]], +[36, ["vspace", 0], 138, 926, [32, 42]], +[37, "repeat", 76, 740, [49, 38, 31, 50]], +[38, ["number", 2.0], 124, 740, [37, null]], +[39, ["vspace", 80], 76, 860, [50, 63]], +[40, "left", 138, 842, [31, 41, 32]], +[41, ["number", 90], 196, 842, [40, null]], +[42, "left", 138, 968, [36, 43, null]], +[43, ["number", 90], 196, 968, [42, null]], +[44, "setshade", 1127, 1356, [91, 47, null]], +[45, ["number", 50.0], 1291, 1398, [47, null]], +[46, "shade", 1267, 1356, [47, null]], +[47, ["minus2", 0], 1213, 1356, [44, 46, 45]], +[48, ["vspace", 20], 1127, 1064, [10, 81]], +[49, "startfill", 76, 698, [77, 37]], +[50, "stopfill", 76, 818, [37, 39]], +[51, "repeat", 76, 1146, [70, 52, 53, 71]], +[52, ["number", 2], 124, 1146, [51, null]], +[53, "forward", 138, 1206, [51, 79, 54]], +[54, "left", 138, 1248, [53, 55, 56]], +[55, ["number", 90], 196, 1248, [54, null]], +[56, "forward", 138, 1290, [54, 80, 60]], +[57, "box1", 264, 1290, [80, null]], +[58, "sqrt", 264, 1332, [80, 59]], +[59, ["number", 2], 318, 1332, [58, null]], +[60, ["vspace", 0], 138, 1332, [56, 61]], +[61, "left", 138, 1374, [60, 62, null]], +[62, ["number", 90], 196, 1374, [61, null]], +[63, "setshade", 76, 1062, [39, 69, 70]], +[64, ["number", 50.0], 216, 1104, [69, null]], +[65, "shade", 216, 1062, [69, null]], +[66, "setshade", 76, 1466, [71, 75, null]], +[67, ["number", 50.0], 240, 1508, [75, null]], +[68, "shade", 216, 1466, [75, null]], +[69, ["plus2", 0], 162, 1062, [63, 65, 64]], +[70, ["vspace", 0], 76, 1104, [63, 51]], +[71, ["vspace", 100], 76, 1224, [51, 66]], +[72, "stack1", 641, 938, [105, 73]], +[73, "stack2", 641, 980, [72, 113]], +[74, "clean", 579, 126, [0, 92]], +[75, ["minus2", 0], 162, 1466, [66, 68, 67]], +[76, ["product2", 0], 210, 884, [32, 35, 34]], +[77, "storeinbox2", 76, 656, [26, 30, 49]], +[78, "box2", 210, 800, [31, null]], +[79, "box2", 210, 1206, [53, null]], +[80, ["product2", 0], 210, 1290, [56, 57, 58]], +[81, "seth", 1127, 1146, [48, 82, 83]], +[82, ["number", 135.0], 1185, 1146, [81, null]], +[83, "forward", 1127, 1188, [81, 84, 85]], +[84, "box1", 1199, 1188, [83, null]], +[85, "seth", 1127, 1230, [83, 86, 90]], +[86, ["number", 180.0], 1185, 1230, [85, null]], +[87, "ycor", 1253, 1272, [88, null]], +[88, ["minus2", 0], 1199, 1272, [90, 87, 89]], +[89, "bottompos", 1277, 1314, [88, null]], +[90, "forward", 1127, 1272, [85, 88, 91]], +[91, ["vspace", 0], 1127, 1314, [90, 44]], +[92, ["fillscreen", 0], 579, 168, [74, 93, 133, 17]], +[93, ["number", 60], 665, 168, [92, null]], +[94, ["random", 0], 698, 252, [17, 95, 96, null]], +[95, ["number", 75.0], 786, 252, [94, null]], +[96, ["number", 125.0], 786, 294, [94, null]], +[97, "repeat", 579, 462, [112, 98, 131, null]], +[98, ["number", 100.0], 627, 462, [97, null]], +[99, ["setxy2", 40], 641, 732, [104, 100, 110, 105]], +[100, ["random", 20], 699, 732, [99, 134, 102, null]], +[101, "leftpos", 841, 732, [134, null]], +[102, "rightpos", 787, 814, [100, null]], +[103, "toppos", 702, 378, [109, null]], +[104, "penup", 641, 690, [127, 99]], +[105, "pendown", 641, 896, [99, 72]], +[106, ["storein", 0], 579, 336, [119, 107, 109, 112]], +[107, ["string", "top"], 648, 336, [106, null]], +[108, ["number", 100.0], 726, 420, [109, null]], +[109, ["minus2", 0], 648, 378, [106, 103, 108]], +[110, "box", 699, 854, [99, 111, null]], +[111, ["string", "top"], 754, 854, [110, null]], +[112, ["vspace", 0], 579, 420, [106, 97]], +[113, ["storein", 0], 641, 1022, [73, 114, 118, null]], +[114, ["string", "top"], 710, 1022, [113, null]], +[115, ["number", 3.0], 788, 1106, [118, null]], +[116, "box", 764, 1064, [118, 117, null]], +[117, ["string", "top"], 819, 1064, [116, null]], +[118, ["minus2", 0], 710, 1064, [113, 116, 115]], +[119, ["vspace", 0], 579, 294, [17, 106]], +[120, "setshade", 641, 606, [132, 126, 127]], +[121, ["number", 8.0], 805, 688, [126, null]], +[122, "box", 859, 648, [125, 123, null]], +[123, ["string", "top"], 914, 648, [122, null]], +[124, "toppos", 835, 606, [125, null]], +[125, ["minus2", 0], 781, 606, [126, 124, 122]], +[126, ["division2", 20], 727, 606, [120, 125, 121]], +[127, ["vspace", 0], 641, 648, [120, 104]], +[128, ["random", 0], 719, 522, [131, 129, 130, null]], +[129, ["number", 0], 807, 522, [128, null]], +[130, ["number", 10.0], 807, 564, [128, null]], +[131, "setcolor", 641, 522, [97, 128, 132]], +[132, ["vspace", 0], 641, 564, [131, 120]], +[133, ["number", 0.0], 665, 210, [92, null]], +[134, ["minus2", 0], 787, 732, [100, 101, 135]], +[135, ["number", 50.0], 865, 774, [134, null]]] |