Extending GP with Blocks to manipulate Pixels
Posted: Sep 15th, '15, 18:05
In our Media Computation approach to teaching intro CS (see http://www.mediacomputation.org), we write Python code that looks like this:
I wanted to be able to do similar things in GP, and with help from the team (and lots of rooting around in the code), I can now.
Here is my extension (attached). Enter developer mode, then "load source file" from the Stage menu. Load in the PixelExtension. You'll get a new set of blocks that will let you get all the pixels in an image, and get/set individual red, green, and blue channels on those pixels. The block to "copy costume" prevents you from messing with the image in the project. (Leave it out, and you can change the images attached to the project.) With these blocks, I can write code like this:
I'm attaching an example project using these blocks.
The PixelExtension file is just plain text. I'll be happy to answer questions about it.
Code: Select all
def decreaseRed(picture):
for pixel in getPixels(picture):
r = getRed(pixel)
setRed(pixel, r * 0.5)
Here is my extension (attached). Enter developer mode, then "load source file" from the Stage menu. Load in the PixelExtension. You'll get a new set of blocks that will let you get all the pixels in an image, and get/set individual red, green, and blue channels on those pixels. The block to "copy costume" prevents you from messing with the image in the project. (Leave it out, and you can change the images attached to the project.) With these blocks, I can write code like this:
I'm attaching an example project using these blocks.
The PixelExtension file is just plain text. I'll be happy to answer questions about it.