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

M450: Cinders is not going to the ball

This morning I received an e-mail concerning my application for one of the two places at the Computer Science 2008 conference.  Unfortunately due to the number of applicants and the "high quality of all the projects" I was not selected, though the feedback was positive and I am now really intrigued as to what final grade I am going to achieve for my project.

However, the selection panel agreed that your project was highly commendable and you will be receiving a letter of commendation in recognition of this from the M450 course chair.

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): Google Reader

Apart from keeping an eye on everyone's blogs by using Feedreader, I have clumped them altogether within Google Reader (see here: MassWriting) and added them to my blog as a widget.

M450: Gobsmacked!!!

I received an e-mail last week from a lecturer in the Department of Computing at the OU asking if I was interested in applying for one of the two places, in the form of bursaries, at the Computer Science 2008 conference in December.  This all sounded very interesting and I replied saying that I would be interested in attending.  Yet the part of the e-mail that really surprised me was...

...your name was put forward as a potential candidate by the M450 course team who were very impressed with quality of your undergraduate project work.

Considering how I felt about the project and what I had produced, I was really gobsmacked when reading the above comment.  Still I must not get me hopes up to high with regards to my final result for M450.  Only 39 more days until the results are supposed to be available.

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.