| CPSC 120 | Principles of Computer Science | Fall 2025 |
Topics showcase applications of the core concepts, in this case arrays.
Successfully completing this topic means that you are able to:
Hand in a hardcopy (paper) of your worksheet in class or under my office door (Lansing 302).
To hand in your sketches:
Make sure that your name and a short description of the sketch are included in a comment at the beginning of each sketch.
Make sure that you've auto-formatted each sketch.
Copy the entire plume and clouds directories from your sketchbook (~/cs120/sketchbook) to your handin directory (found inside /classes/cs120/handin).
Like labs, topics are individual assignments — what you hand in must be your own work, your own ideas, your own effort. You may get help in office hours and from Teaching Fellows, but you may not work together with a partner or in a group with others to create solutions or write code.
The policies on late work and extensions, academic integrity, and the use of AI for topics are the same as for lab 2. Review the policies there. One extension token is needed for revise-and-resubmit without an initial handin.
Also review assignments and evaluation on the Policies page for how topics factor into the final grade. The short version: topics are optional for a passing grade (C-), but achieving proficiency for at least some topics is required for a higher grade.
Review the slides from 11/10 for more about particle systems and the slides, examples, and in-class exercises from 11/3 and 11/7 for arrays and array-ifying sketches.
Do the exercises in order. Note: following the patterns discussed in class (array-iyfing) is required for credit — achieving the end result by some other means will not count.
Read through all of each exercise before you start on it. In particular, note that the "to do this" steps are what you should actually do to complete the exercise — don't just read the first sentence of the problem, look at the example, and try to write the sketch from there. Follow the steps!
Put your name and a description of the sketch in comments at the beginning of each sketch. Also don't forget to Auto Format your code before handing it in.
Be sure to save your sketch frequently (ctrl-S). (Every time you run your sketch is good.) The editor does not auto-save!
In this exercise you'll use particle systems to create an animated plume of sparks that changes color as it moves across the screen. The starting point is a sketch which sets up the particle system but only contains a single spark.
The picture shown below is just a snapshot of the animation — click on it to see the running sketch.
To create this sketch:
Create a new sketch, add your name and a description of the sketch in comments at the beginning, paste in the contents of the provided starter_plume sketch, and save it as plume.
Complete the Exercise 1 section of the the particle systems worksheet.
Based on your answers from the worksheet, array-ify the sketch so that there are 30000 sparks. (Reduce the number of sparks if the sketch runs too slowly.)
In this exercise you'll use a two-level particle system to create an animation of clouds growing and dissipating. The starting point is a sketch which sets up the particle system but only contains a single particle and a single child emitter.
The picture shown below is just a snapshot of the animation — click on it to see the running sketch.
To create this sketch:
Create a new sketch, add your name and a description of the sketch in comments at the beginning, paste in the contents of the provided starter_clouds sketch, and save it as clouds.
Complete the Exercise 2a section of the the particle systems worksheet.
Based on your answers from the worksheet, array-ify the sketch so that there are 30000 particles. (But still only one child emitter.) Reduce the number of sparks if the sketch runs too slowly.
Complete the Exercise 2b section of the the particle systems worksheet.
Based on your answers from the worksheet, array-ify the sketch so that there are 10 child emitters. You will also need one addition beyond simply array-ifying: a new particle's properties are initialized based on its emitter. Choose a random emitter for the particle: make a local variable emit as shown below and use that to index into the emitter arrays:
int emit = int(random(0,emitX.length));
The int(...) is doing a typecast — random returns a float value but an int value is required for an array index. The int(...) syntax turns the float into an int (by dropping anything after the decimal point).
For extra credit, save a copy of your plume sketch with the name plume_ec and modify the copy so that the emitter moves in an interesting way. The pictures below show snapshots of two variations on a spiral motion as examples of the kind of thing you might do, but feel free to try other things. You may also want to modify aspects of the sparks' initialization; that was done in the second case, in fact, the emitter is animated the same way in both sketches and the differences are due to how the sparks are initialized.
![]() |
![]() |