Showing posts with label MassWriting. Show all posts
Showing posts with label MassWriting. Show all posts

Friday, November 07, 2008

OU (MW): Working from back to front

Having decided upon a content layout I have started to think about the various bits of code of will need for each area.  After sometime contemplating how all these bits of code should fit together to form the final program I decided that perhaps a better approach would be to create the final program first and then I can use elements of this code with my core text to demonstrate certain aspects, for example the default constructor.  My program is now complete and it demonstrates a default constructor, constructors with arguments and the 2 ways of using the this keyword, by producing multiple instances of my Frog class.  Now to get on with the text.

The code:

void setup() {
size(640, 480);
background(255, 248, 220);
smooth();
noLoop();
}

void draw() {
Frog freddo;

for (int i = 0; i < 75; i++) {
switch (int(random(0, 6)+1)) {
case 1:
freddo = new Frog();
break;
case 2:
freddo = new Frog(int(random(52, 588)+1),
int(random(37, 442)+1));
break;
case 3:
freddo = new Frog(int(random(0, 254)+1),
int(random(0, 254)+1),
int(random(0, 254)+1));
break;
default:
freddo = new Frog(int(random(52, 588)+1),
int(random(37, 442)+1),
int(random(0, 254)+1),
int(random(0, 254)+1),
int(random(0, 254)+1));
break;
}
freddo.display();
}
}

class Frog {
// properties
int xPos;
int yPos;
int redColBody;
int grnColBody;
int bluColBody;

// constructors
// default constructor
Frog() {
this(320, 240, 0, 128, 0);
}

// constructor (position)
Frog(int xPos, int yPos) {
this(xPos, yPos, 244, 164, 96);
}

// constructor (coloured body)
Frog(int redColBody, int grnColBody, int bluColBody) {
this(320, 240,redColBody, grnColBody, bluColBody);
}

// constructor (position & coloured body)
Frog(int xPos, int yPos, int redColBody, int grnColBody,
int bluColBody) {
this.xPos = xPos;
this.yPos = yPos;
this.redColBody = redColBody;
this.grnColBody = grnColBody;
this.bluColBody = bluColBody;
}

// methods
void display() {
stroke(0);
strokeWeight(1);
// body
fill(redColBody, grnColBody, bluColBody);
ellipse(xPos, yPos, 90, 45);
// feet
fill(107, 142, 35);
ellipse(xPos - 30, yPos + 15, 45, 23);
ellipse(xPos + 30, yPos + 15, 45, 23);
// eyes
fill(255, 255, 255);
ellipse(xPos - 15, yPos - 23, 23, 30);
ellipse(xPos + 15, yPos - 23, 23, 30);
fill(0, 0, 0);
ellipse(xPos - 15, yPos - 23, 8, 8);
ellipse(xPos + 15, yPos - 23, 8, 8);
// mouth
noFill();
strokeWeight(2);
arc(xPos, yPos - 2, 30, 5, 0, PI);
}
}


The output:

image

Thursday, November 06, 2008

OU (MW): Welcome back old friend

Part of the criteria for my chunk (like a majority of all the chunks) is to develop a progam to demonstrate what I have written about and to try and get it to do something graphical.  Thus I have been musing over the last couple of days as to what graphically I can do to demonstrate the use of constructors.  I do not want to do anything that is too complicated as I don't want it to detract from the main point of the code, but I do want to make it interesting and perhaps fun.

Well last night I decide to welcome back on old friend from the time I studied M206.  For this course we were taught all about OOP's via the use of frogs.  These weren't just normal frogs, there was also HooverFrogs, DietingFrogs, frogs that could barn dance and toads.  So let me introduce Freddo (for those who remember the chocolate bar).

image         
     My Freddo                    The real Freddo

I will now be able to demonstrate different constructors, creating Freddo's in different places on the screen and in different colours

OU (MW): Content layout

Prof. Ince has confirmed that I can do chunk 62 "Constructors", so I have been working on what content to include and how to lay it out.  This is what I have decided on:

  • Introduction
    - What has been covered so far
    - What are constructors?
  • Default Constructors
    - Hidden
    - User specified
  • Overloading Constructors
    - Arguments and setting instance properties
    - the this keyword (part 1) - setting instance properties
  • Advanced Constructors
    - Argument checking
    - The this keyword (part 2) - invoking a constructor
  • Summary
  • Program putting all the ideas togeather

Tuesday, November 04, 2008

OU (MW): Committed

Having read chapters 1 & 3 of Processing: Creative Coding and Computational Art I decided upon committing to chunk 15 "Functions 2".  I e-mail'd Prof. Ince with my decision and then started to think about a layout for the chunk.

Purely by chance I discovered that someone else has already committed to chunk 15, so I have had to revisit my list of candidate chunks and upon deciding a replacement I e-mail'd Prof. Ince with my new choice.

My chunk of choice is now chunk 62 "Constructors".  Tonight I will read through pages 309 -311 of the book, and also dig out the corresponding section(s) from the course text for M254 - Java Everywhere that I took back in 2005 as it might prove useful.

OU (MW): To do list

A simple to do list so I know what is outstanding.

  • Decide to participate of not. Done
  • Read the introduction to Processing. Done
  • Read the wiki entry on "Blog".  Not required
  • Send email giving details about myself and willingness to participate. Done
  • Set up a blog. Done
  • Decide on what chunk to write. Done (04.11.08)
  • Email details of the chunk I want to write. Done (04.11.08)
  • Download and install the Processing IDE. Done (28.10.08)
  • Order the Processing book. Done (28.10.08)
  • Read chapters 1 and 3 of the book. Done (04.11.08)
  • Write the chunk.
  • Email the finished chunk.

Notes:

  • The book to order:
    Processing: Creative Coding and Computational Art (Foundation)
    Ira Greenberg
    ISBN: 9781590596173
    at Waterstones

Monday, November 03, 2008

OU (MW): Book and Chunks

This morning I received my copy of Processing: Creative Coding and Computational Art (ordered via Amazon), so now to start reading.  I will start with chapters 1 & 3, as recommended by Prof. Ince, and then move onto the sections in the book corresponding to the candidate chunks that I have identified whilst trying to decide for which one I should write.

I went through the complete list of chunks, last week, and from each block of ten chunks identifying at least one that is of particular interest. I ended up with a list of eight candidate chunks and from there I eliminated half of them.  The plan now, after reading the corresponding sections from the book, is to prioritise the remaining 4 candidates and e-mail Prof. Ince with my choice.

Note:  Someone else has already chosen one of the chunks that I have in my candidate list, thus I am now down to three candidates.

Note:  Having done a brief skim through the book, I am intrigued as to why we don't have to read chapter 2.  Might have to e-mail Prof. Ince to enquire as to why.

Wednesday, October 29, 2008

OU (MW): Processing - A Bug!

Yesterday I downloaded and installed Processing.  I then started going through the "Getting Started" page of the processing.org web site and everything seemed to be going ok.  That is until I went to save same code.  It just would not save.  Every time I tried, the IDE kept responding with the message "Save Canceled".

image

I had a look around the web site and found that this is a known bug and was reported on the 27.Oct.08.

This morning I discovered the exact nature of the bug.  If when saving a new sketch you accept the default supplied filename (i.e. sketch_081029a) the save will be cancelled.  The work around is to overwrite the filename given in the "File name:" field, of the "Save sketch folder as..." dialogue box, with a filename of your choice.

Monday, October 27, 2008

OU (MW): Up the garden path

Simon K. left an interesting comment on my previous posting "OU: Mass Writing", and after re-reading the posting I realised that I might have mislead people with what I have written.  Prof. Ince in his blog gives a better description of what the book is about.

The book writing project involves OU students, and anyone else who wants to volunteer, writing a book about the Java-based computer-art system known as Processing.

Once completed the book might be considered for use within a course, and if accepted for publication by a conventional publisher...

the royalties will go to the student hardship fund or any other charitable fund in the Open University

Thursday, October 23, 2008

OU: Mass Writing

Received an e-mail this morning from a Professor Ince, the Head of Computing dept. at the OU, asking if I would like to collaborate on a book about Computer Art.  Sounds grander than it probably is.  The department actually is looking for 85 volunteers, with each volunteer completing a section comprising of 2,500 words and a computer program.  I have decided to volunteer as it looks as though it could be fun.

For further details take a look at page 5 of the Autumn issue of Sesame.