Sunday 26 October 2008

First stab at a chunk outline

This is my first stab at an outline. It will change! And it already includes unanswered questions. Interestingly, it is just about 500 words, or one fifth of the way there.

===========================
Prerequisites:

Students will have met primitive data types. Declarations. And have seen some simple scripts.

Focus on a large number of very compact examples.



Arrays
-Intro.
--The need to hold a number of similar pieces of data. Discussion examples - eg names, images in a slideshow, coordinates of lines, colours of pixels
--(Learn: purpose & utility of arrays)

-Example 1
--A simple example - create and access an array of names. Slow talk through. Then a program that displays them (no loop - hard code the array indexes).
--(Learn: recognise an array. Declare array. Access one element (get and set). Counting starts from zero)

--(initial example string vars - because simple in concept, don't have to struggle with abstract types. Don't use integers as I don't want any scope for confusion between index and value at this stage. Downside is that extra code is needed to create & load a font before I can display a string. And might end up being too machine dependent - does everyone have Arial?).


-Example 2
--Extend the example. One idea: Add a second array for colour values (for gold, silver & bronze). Mention that the first array of names was olympic medal winners. Step through array, displaying name in medal colour (or with a medal circle?). Second thoughts - just been playing; colours are tricky to get into at this time. I think the example looks too complex. Maybe better to have another of the same complexity as the first.
--(Learn: consolidate on previous)

-Some extras
--finding length of an array. Fixed size. More on counting from zero & implications.
--(learn: array.length, fixed size, obiwan errors)



For statements
-Intro
--The need to step through an array one item at a time. Discussion examples - big arrays where you can't hardcode.

-Example
--Take an earlier example & convert to an enumerated for loop

-Discussion
--Slow talk through the elements in the enumerated for loop

-Example
--Another stepping through array example - eg initialising a large array

-Discussion
--Not just for arrays. A for loop for any countable loop. More on varying the parts of the loop (eg the increment)

-Example
--A nice visual one, eg lines on a screen (different colours giving a gradient? Or splayed from a point, starburst-like?

-Another example
--Stepping through all the pixels in an image (but don't pre-empt chunk 21 too much!)

Deeper into arrays
-Multidimensional arrays
--Maybe review single-dimensional ones first? Stick to 2-dimensional, eg pixels.

-Example
--A nice big 2-dimensional array example, eg process squares in an image

-Array reference
--Array Functions - append() arrayCopy() concat() expand() reverse() shorten() sort() splice() subset()
--At least mention them, even if I don't cover them in detail.

More on For
-I suppose we should cover for..each loops. I have doubts whether this is the best place for them, but can't find them mentioned later in bookfragments. (I couldn't get one to iterate over an array - do for..each loops even exist in Processing?).

Wrap it up
-summary of learning points.
-A more complex (but colourful!) example to get them thinking.

Getting started

OK, so what do I need to do in order to get this chunk written?

First steps, not in any particular order:

* Understand the problem: exactly which concepts and parts of the language am I teaching

* Understand how Processing does all that

* Develop some good metaphors & teaching examples

* Read around - how have other authors tackled the task of teaching these topics for other programming languages? (a trip to the library is called for!)

* Understand the scale of what I've committed to. How much is 2500 words? Answer: a little over twice what I've written so far in this blog (including this entry).

* Read around previous chunks by my co-authors. Eg what screen interaction are they using? None is explicitly taught, but we'll all want to give some feedback that the algorithms & simple programs are doing something. Makes sense to use the same mechanisms unless there's a particular need to teach a different one.

The last point begs a question - how collaborative will this project be? That's worth a separate set of musings...

Oh - and somewhere in that lot, devise a structure for the chunk, and develop prose and code to fill the structure.

Friday 24 October 2008

Chunk 12 - Arrays and for statements

Yes - Darrel's confirmed I'm good for chunk 12!

CHUNK 12

TITLE Arrays and for statements
DESCRIPTION Describe single-dimensional arrays and show how for statements can access such arrays.This is a very tricky topic for the beginning programmer so use lots of examples. Describe a program of similar complexity to Greenberg 90--92. Teach brackets in the context of for statements as well. Students will have met brackets before but assume that they only have a hazy idea.
OUTCOMES
  • Be able to look at a section of code which contains a for statement and array references and describe what it does.
  • Be able to develop simple sections of code that involves a for statement and array references
  • Understand a program of similar complexity to the one you describe in text.
REFERENCE Greenberg 87--92
HINT Please dont make the programs too complicated: loops are a really difficult concept for beginning students.
PROGRAM Develop a program similar in complexity to the one you describe in the text

Previous chunks (so I know what I'm depending on):
1 Intro to Computer Art
2 Introduction to Java
3 Algorithms 1
4 Algorithms 2
5 Algorithms
6 Two simple programs
7 Basic types and naming conventions
8 Big linear program
9 Operators
10 Conditional statements
11 Switch and ternary conditions

First big question for coordination with earlier authors - what output mechanisms will the student have met by now?

Hmmm..... what to write?

Now there's the question - what to write? And can I separate the writing part from the playing-around-with-the-software part?

Early chunks look hard - teaching complex programming constructs from scratch to people with unknown background. But the later parts look hard too - heavy maths & trigonometry. I suppose I could write about Bezier functions if I knew what they were... But the later parts would encourage me to learn, and interact more deeply with the software.

I'm drawn both ways. But I think I'd like to start near the beginning. I'm drawn to the challenges of clear teaching of complex topics. So I've volunteered to write chunk 12 "Arrays and for statements". I rather fancy seeing if I can teach that clearly in 2500 words. Plus, I should be able to make a start without waiting for the book.

Meanwhile, I'm still frittering time away looking at the examples, and also at the Arduino board, and thinking of what applications they open up for me.

Wednesday 22 October 2008

Animated gifs

Just spent a while developing a very simple first app that processes a photograph, and generates an animated gif, where the photo is revealed as a set of scanlines.

Imagine my annoyance when I discover that this blogsite doesn't allow animated gifs in a profile! At least for me, it only displays the first frame, so I've removed it.

One useful thing I discovered - when downloading a new library (in this case gifAnimation), you need to exit & restart the IDE after you've copied the library folder to the right place.

For those who care, here's my code:


import gifAnimation.*; // needs gifAnimation library from http://www.extrapixel.ch/processing/gifAnimation/

PImage a;
int blobwidth;
int blobheight;
int y;
int x;
GifMaker gifExport;

void setup()
{
a = loadImage("pict5124a.jpg"); // name of image to scan
size(a.width,a.height);
noStroke();
background(0); // black background to prevent flashing between loops
smooth();
blobwidth = width;
blobheight = height / 15;
y=0;
x=0;

gifExport = new GifMaker(this, "export.gif");
gifExport.setRepeat(0); // make it an "endless" animation
}

void draw()
{
fill(0, 0, 0, 64); // fade existing lines by overwriting with black. Last parameter = 0 for no fade; 255 for maximum fade)
rect(0,0,width, height); // this is the actual overwrite
PImage blob = a.get(x, y, blobwidth, blobheight); // get blob
image(blob, x, y); // and write to screen
x = x + blobwidth; //scan horizontally
if (x >= width)
{
x = 0;
y = y + blobheight; // scan vertically
if (y >= height)
{
y = 0;
gifExport.finish(); // finalise the gif after one run through
}
}
gifExport.addFrame();
}

And here's me:

animated me

(edited to correct obiwan error)

Initial thoughts on Processing

Well, I wasted far too much time browsing through the Processing web site. What a brilliant language! Java's great in many ways, but I've never got very far with graphics - slow to program & slow to execute. Processing seems to achieve a huge variety of functionality & effects in very few lines of code.

I've downloaded the IDE and played with a few programs. Looked at most of the intersting-looking examples on the web site & plugged a small number into the IDE. Spent a while on pointillism, playing around with the parameters, trying to merge it with bits of the ASCII art video processor. Really trying to come up with a good profile picture that doesn't look too much like me!

I couldn't get Processing to do video capture, though. Reading the site, it seems a minefield. Seems to rely on vdig, which is no longer available. Or on qtjava.dll which doesn't appear to ship with Quicktime any more. Luckily, I don't think the book needs a chapter on video, but it would be nice...

The other really interesting discovery was the Arduino board - "a physical computing platform based on a simple I/O board and a development environment that implements the Processing/Wiring language". This looks to be just what I need to control my central heating. The older control system ran in Clipper under MSDOS 2.11 on a laptop nailed to the wall, but stopped working when a rat gnawed the control wires, shorting a vital component. The Arduino might help me get going on a web-enabled solution...

Tuesday 21 October 2008

The OU Mass Writing Project

See bookfragments

Well, certainly an intriguing project.

I've just sent my details to Darrel & was surprised & pleased to get a personal response. That'll be a big commitment if he manages that for all 85 volunteers plus reserves! I wanted to get my application in early, because I suspect there'll be a lot of interest... at least I hope so.

My initial thoughts on the project - fascinating idea. The Processing environment looks interesting in its own right. I occasionally write, and I teach, but not had a chance to be so involved in creating teaching materials in this way - it should stretch me in interesting ways. But I'm a little scared - will I have the time to do a good job? It sounds like a big commitment - learn the environment, pick a topic, write a chapter, illustrate with two programs, maintain a blog, undoubtedly fritter time away monitoring the blogs of my fellow writers. All in my "spare time", whatever that was.