Java

TOPIC 25 – LOOP APPLICATION: GRAPHICS

 

LESSON WORK

 

 

QUESTION 1
Create a gradient similar to the one shown in the image below. The colour on the far left is black (0,0,0) and the colour on the far right is red (255,0,0).  While it may not seem like it, this gradient is really just a sequence of lines that are side by side and slowly increase the red component of the rgb colour.

 

 

HINTS

  • This gradient is really a series of vertical lines that are side by side.  You should start by doing these lines and not worrying about colour.  To keep it simple, create lines for x = 0 up to 255.

  • For colour, the colour is to be set to (c, 0, 0) where c ranges from 0 to 255.  Because we have 255 colours and 255 lines, we simply make each line one different colour.

  • It would probably be useful to create a loop table that includes columns titles iteration number, x1, y1, x2, y2, r, g, b and fill it in for the first few iterations (or lines).

QUESTION 2 (OPTIONAL BONUS)

 

Try to do the following:

 

 

 

HINT:

 

  • There are six separate gradients here – so six different for loops.


Got it done?  Show Mr.Campeau for a bonus mark.