So I have come along with this project quite nicely and at the moment, the enclosed code gives me the following -
the final task is to get the 4 stars into the other 2 books. Previously, I did get the stars in all 3 books using a function and then calling that function 3 times but apparently it takes less lines of code and is neater to do with a nested loop. I tried doing that with my c variable in a for loop at the bottom of my code and it does place the stars in the first book. The challenge remains as to how to get it in the other 2 books. There is a gap of 30 between the books and I just can’t figure out how to get this space into my code -
fill(173, 117, 33); //draws bookshelf
rect(0, 140, width, 10);
var library = [ //array of 3 objects
{
title:"I Know Why The Caged Bird Sings",
author:"R. Michener",
stars:4,
color:color(10,10,10)
},
{
title:"Alaric the Goth",
author:"Boin",
stars:4,
color: color(10,250,140)
},
{
title:"Caesar Invades Gaul",
author:"Goldsworthy",
stars:4,
color:color(250,250,140)
}
];
for(var i = 0; i < library.length; i++)
{fill(255 - 100*i,200 - 50*i,50 + 150*i);
rect(20 + 120*i,20,90,120); // 3 books (90 x 120)
textSize(15);
fill(library[i].color);
text(library[i].title,20 + 120*i,30,90,60); // 3 titles(90 x 60)
text(library[i].author,20 + 120*i,90,90,30); // 3 authorsfor(var c = 0; c < 4; c++)
for(var c = 0; c < 4; c++) {
image(getImage("space/star"), 22 + 22.5*c,110,18.5,28);
}
}