We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello. New to the forums and processing.js. The title probably doesn't explain well what I'm trying to do, I wasn't sure how to formulate it better. Sorry about that.
I'm drawing books (rectangle, title, star rating), left to right. Each book is an object in an array. Right now, the books are drawing like this:
1 2 3 4 5 6 ...
What I'd like to do is have the code draw 4 books left to right, then move the 5th book down some amount of pixels and to the X position of book 1. Like this.
1 2 3 4
5 6 7 8
9 10, 11
I've tried fiddling with nested loops and split(), to no avail. Any help would be appreciated. Thanks.
Answers
ah, this is processing, not js
adapt it....
;-)
there is a tutorial on 2 dimensional arrays (a grid like a checcboard)
Alrighty. Thanks for the tip.
the core is line 42 and 43
those are row and column number
you can multiply them with distanceCell to have a grid (distance between cells)
you then can add something to have a border to the screen (x: xOffSet and y: 18)
this new version has not a 2D array colors, but a 1D array (a List)
Hence the for-loop is a simple for-loop not a nested for-loop
the line-feed is done by xScreen and yScreen which you just have to give the correct values (see above)
Thanks for all your input. A lot to chew on for a beginner :). Reading up on 2d arrays right now. I'll go over your code shortly.
it's not much
just ask if you need something
;-)
http://forum.Processing.org/two/discussions/tagged/2darray
Success. Ended up using 1D array (2nd example). This is the result
https://www.khanacademy.org/computer-programming/dull-as-rock-bookshelf/5678308290330624
Trying to draw the star rating in the same manner was giving me a headache. I first had to group the stars, then spread them out... and this line
xScreen /*in my project it's starX*/ = xOffSet
was no longer working, so I had to use
starX -= 400
to get the groups of stars to line up at the beginning of the shelf (took me a while).I also had to change
if((x > 0) && (i % 0 == 5))
to
if((x > 0) && (i % 4 === 3))
Not sure why (fyi, KA doesn't accept ==).
Thanks for the help.
Great