Project 1: Brush (Algo)

You can find the handout for this project here. Please skim the handout before your Algo Section!

You may look through the questions below before your section, but we will work through each question together, so make sure to attend section and participate to get full credit!

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 work through the following as a group:

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? Spend some time working independently, and then discuss how you arrived at your answer. Can you express the answer in terms of width, height, row, and col?

Index -> Row, Col

What is the row and column of the pixel at index 12345 in the vector? As a group, try and find expressions for the row and column in terms of width, height, and index.

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. Your answer should be in terms of .

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 .

Before you start, draw a 5x5 mask grid on the whiteboard with your group. Recall how you can use the distance from the center of the brush to find opacity.

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 .

Start by picking a single pixel in your grid from the previous question and working through the math. Then, work together to generalize your answer.

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

Algo Sections are graded on attendance and participation, so make sure the TAs know you're there!