// Object oriented programming
/*
Winston
- nickname
- age
- x
- y
*/
var Winston = function(nickname, age, x, y) {
this.nickname = nickname;
this.age = age + "yrs old";
this.x = x;
this.y = y;
};
var winstonTeen = new Winston("Winsteen", 15, 20, 50);
var winstonAdult = new Winston("Mr. Winst-a-lot", 30, 229, 50);
var drawWinston = function(winston) {
fill(255, 0, 0);
var img = getImage("creatures/Winston");
image(img, winston.x, winston.y);
var txt = winston.nickname + ", " + winston.age;
text(txt, winston.x+20, winston.y-10);
};
drawWinston(winstonTeen);
drawWinston(winstonAdult);
so this code puts out the enclosed graphic - looking at the 2 lines
var img = getImage("creatures/Winston");
image(img, winston.x, winston.y);
it looks to me like it can be replaced with a single line as follows
image(getImage("creatures/Winston"),winston.x,winston.y);
in a similar vein, looking at the 2 lines -
var txt = winston.nickname + ", " + winston.age;
text(txt, winston.x+20, winston.y-10);
again, it looks like we can replace it with the single line
text(winston.nickname + "," + winston.age, winston.x + 20, winston.y - 10);
so my question is why - if simplicity is the best approach - the lesson was presented the way it was