I'm working on a coding assignment in Pathway2Code's Music Composer world. I'm having trouble positioning the music notes with consistent spacing and creating a second row when the first row is full. What changes should I make to the note positions or loop structure?
2 Answers
Look for the part of the program that controls each note’s position. Instead of using fixed coordinates, store the starting x and y values and update them after drawing each note. If the assignment allows outside tools, LilyPond is another option for laying out musical notation, but the main fix in your project is likely adjusting the coordinate and loop logic.
Keep track of the horizontal position with an x-coordinate or spacing value. Each new note can increase x by the same amount. When the row reaches its limit, reset x to the starting position and increase the y-coordinate to move down to the next row. A row counter or nested loop can make this easier to manage.

The second row will usually need a different y value while keeping the same x-spacing logic. You can also calculate the row and column from the note number if you’re placing them in a grid.