Copyright © Cay S. Horstmann 2008 Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.

Using Greenfoot with Media

Mark Guzdial has pioneered a “media computation” approach for non-majors CS courses in which students manipulate images, sounds, and movies ([1]). A Java based version of such a course is described in [2]. In my own non-majors course, I do a much shorter block spanning 2 - 3 weeks, consisting just of image manipulation. The materials in [2] got me off to a good start, but I had two issues.

In this note, I explain how to use Greenfoot ([5]) to overcome these issues. Greenfoot allows you to place instances of subclasses of Actor into a World. The world displays actors and allows direct manipulation with immediate feedback.

I implemented a class Picture and a utility class Pixel similar to those in [2], except that Picture is a subclass of Greenfoot's Actor, allowing picture objects to be displayed in a world, as shown in this figure:

Students produce subclasses of Picture with certain image manipulation methods. Here is a typical example:

import java.awt.*;

public class MyPicture1 extends Picture
{
    public void stripeRows()
    {
       for (Pixel pix : getPixels())
       {
           if (pix.getY() % 2 == 0)
              pix.setColor(Color.BLACK);
       }
    }
}

The methods implemented by the student are selectable by right-clicking on the image:

The effect becomes immediately visible.

To use this in your own class, simply ask your students to install Greenfoot and to unzip this project. Ask them to make a subclass of Picture for each effect (such as color changes, mirroring, edge detection, etc.).

Comments? Suggestions? Please email to cay@horstmann.com.

References

[1] Guzdial, M. 2003. A media computation course for non-majors. SIGCSE Bull. 35, 3 (Sep. 2003), 104-108. DOI= http://doi.acm.org/10.1145/961290.961542

[2] Guzdial, M. and Ericson, B. 2006.. Introduction to Computing and Programming with Java: A Multimedia Approach, Prentice-Hall, http://coweb.cc.gatech.edu/mediaComp-plan/101

[3] Allen, E., Cartwright, R., and Stoler, B. 2002. DrJava: a lightweight pedagogic environment for Java. In Proceedings of the 33rd SIGCSE Technical Symposium on Computer Science Education (Cincinnati, Kentucky, February 27 - March 03, 2002). SIGCSE '02. ACM, New York, NY, 137-141. DOI= http://doi.acm.org/10.1145/563340.563395

[4] Dann, W., Cooper, S., and Pausch, R. 2000. Making the connection: programming with animated small world. In Proceedings of the 5th Annual SIGCSE/SIGCUE Iticseconference on innovation and Technology in Computer Science Education (Helsinki, Finland, July 11 - 13, 2000). ITiCSE '00. ACM, New York, NY, 41-44. DOI= http://doi.acm.org/10.1145/343048.343070

[5] Henriksen, P. and Kölling, M. 2004. greenfoot: combining object visualisation with interaction. In Companion To the 19th Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages, and Applications (Vancouver, BC, CANADA, October 24 - 28, 2004). OOPSLA '04. ACM, New York, NY, 73-82. DOI= http://doi.acm.org/10.1145/1028664.1028701