Project 1: Brush (Algo)
You can find the handout for this project here. Please read the handout before working on this algo assignment!
Indexing Into Your Canvas
In Lab 2: Pencils, you learned that canvas data can be stored as a vector of RGBA
structs in row-major order. For such a canvas with width = 512
and height = 256
, please answer the following:
Row, Col -> Index
Given that the first pixel (index 0
) is at row 0
, column 0
, what is the index of the pixel at row 43
and column 242
?
Index -> Row, Col
What is the row and column of the pixel at index 12345
in the vector?
Mask Coverage
All of your brushes in Project 1: Brush
should be implemented using masks (see the Brush handout) which store a brush's opacity at certain point. As always, you should use a 1D vector to represent this 2D array of values.
This means that you will need to figure out what area of the canvas overlaps with the brush mask to iterate over in your drawing loop.
Answer the following questions for a linear brush with a brush radius
Mask Size
What is the size of your mask vector in pixels? Consider the 2D space you need to cover and how many pixels that is in total.
Calculating Mask Opacity
What is the opacity value of the mask at index
Finding Relative Coordinates
Suppose you click on a pixel at coordinates
What is the index of pixel
Color Blending
In Project 1: Brush
, you will blend the color of a brush with the color of canvas using the brush's mask. In that project, the canvas will be filled using our 4-channel RGBA struct, but for this exercise, assume that your image is grayscale and has only one channel, which we'll call intensity. Each pixel's intensity will be represented by a floating point value ranging from 0 (black) to 1 (white).
What is the value of the final intensity
As a sanity check, remember to consider the case when
Submission
Submit your answers to these questions to the "Project 1: Brush (Algo)" assignment on Gradescope.