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 in the mask's 1D vector? Your answer should be in terms of and . Recall that the opacity value of the brush mask at the center point, 2D coordinates , is .

Finding Relative Coordinates

Suppose you click on a pixel at coordinates . Near there is another pixel , which falls within the brush's mask.

What is the index of pixel in the mask vector? Your answer should be in terms of , , , , and .

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 on the canvas, given the original color intensity of the canvas , the opacity of the mask at that point , the current brush's color intensity , and the current "alpha" value ?

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.