CPSC 203, 2026 W1
September 24, 2026
POTW 2 and 3…
Registration for examlet 1.
Make the poppies pop!
PC: https://www.epicgardening.com/spring-wildflowers-from-seed/
Examine each pixel. If its red color channel is high (over 200, say), then leave it as is. Otherwise, change the pixel to grey by setting all 3 color channels to the average of their original values.
If necessary, go back and review the slides on colour representation from previous lecture.
Open the List Activity on PrairieLearn and choose the Make the Poppies Grow question.
Examples of programming idiom:
Experiment with the code! Try one or more of these:
red = 255 - redSo far we have focused on
int, str or library types np.uint8.list or tuple.But we often want to store a fixed number of pieces of information which naturally belong together.
For that, we use compound data types.
What data describes a bead?
What data describes a bracelet?
In CPSC 103, we used NamedTuple to create a compound type:
In CPSC 110, we used define-struct to create a compound type:
A dataclass bundles related data together into a custom type.
This creates a new type called Bead with two attributes.
int is a type for storing integers.42 is an instance of the type int.What would these print?
A dataclass can also have methods.
Add a draw method: