LAB 12A - NBODIES

What is a file?

At the start of the semester we asked the question "what is a file?", and we learned that it's just a series of bits (0's and 1's)! How, then, does an MP3 file differ from a PNG file? Format! PNG image files are formatted very differently from MP3 files. The ".mp3" or ".png" extension tell the user (and the operating system) the format the data is in within the file, and that is how the user (or the operating system) knows which program will be able to correctly understand that data. If some user was feeling a little crazy and manually changed the ".mp3" extension in an audio file to ".png", then the data contained within that file is still in 'mp3' format; however, now the operating system would try to open the file with Paint (or whatever the default image viewer is) and would fail to correctly understand the data (series of bits) contained within that file.

In this episode of CSCI261...

For this lab you need to create your own software that can make sense of (i.e., visualize) some data contained within a file. For now, we will provide you with simulation files (which in this case is really just a normal text file) to visualize; however, in Homework 12, you will create your own simulations (i.e., files) that you will then visualize with the software you create in this lab. The final product should look similar to:

Instructions

Your task in this lab is to read a simulation file into a C++ program and visualize its contents. The simulation file you are to read is of a certain format (like mp3), which we will call the 'bs' format (for body simulation people!). As you can see in the example above, the simulation file describes a system of variable-sized bodies that move around on the screen. More specifically, the simulation files are formatted in the following fashion:

Line 1 and Line 2 are sometimes called header lines because these two lines are necessary to help your program understand the rest of the contents in the file. Line 1 tells the program how many bodies are going to be drawn, followed by the X and Y size of the window that you need to create with SFML (SFML template). Line 2 details the relative size of each body (see the example gif for reference). The numbers found on this line will all be between zero and one, and later on you can scale them against some MAXIMUM_BODY_SIZE value in your code; since you need to draw N bodies, line 2 will contain N values. Lines 3 and onward describe the successive states of the simulated system, where line 3 contains all the positions (X and Y) for the first, or initial, state, line 4 contains all the positions for the second state, and so on to the Mth state. Each of these lines must contain an X position AND a Y position for each of the N bodies, and so there are a total of 2N values on each of these lines (each between 0 and the X or Y boundary). Furthermore, all values found on a single line are white-space separated.

To complete this lab, you need to develop a program that will (1) read the file described above and (2) visualize its contents. We provide three different simulation files to test your solution against, and each of these files instructs your program to draw a different number of bodies; in other words, your code must be able to accommodate any number of bodies. You can download these simulation files HERE. In order to accomplish this task we suggest you do the following:

Your solution to this lab will be due with Homework 12. Your submission will be graded on:

  1. Whether your program asks the user to input the name of a simulation file and, if no name entered, provides a default file name for ease of use (such as "bodySim.bs").
  2. Whether your program works for any number of bodies.
  3. Whether your program can draw the bodies with variable sizes.
  4. Whether the positions of your bodies are updated correctly (i.e., the bodies move smoothly).
  5. EXTRA CREDIT (3 pts) possible if the colors of your bodies are adjusted (in a logical way) according to their size.