Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Procedures [11/13]

This program demonstrates the user-defined function-procedure boxGradient, which draws a gradient between two given colors.

The gradient is produced in a manner similar to the previous example: many horizontal lines are drawn, but in this case the lines are close together. First, the underlying line is drawn with a color c1. Then, a semi-transparent line is drawn above the first line with a color over. A color over is derived from color c2 by modifying the opacity parameter (.a). The opacity is set to increase downwards.

Unfortunately, the colors are not as vivid as expected and the entire box is semi-transparent. This is due to arrangement of the coordinate system and pixel grid. In this arrangement, a line with whole-pixel coordinates necessarily spans exactly in between two pixel rows. Drawing such a line changes both rows by half the required intensity.

Loading...