Two snippets of the code are of interest:
-Multi-Color Output
-Colored Ball Movement
The code used in this project comes directly from the Create VGA With VHDL tutorial. The tiny modications made are seen below, one for the multi-color display project and the second for the color changing ball.
Multi-Color Output Changes
------------« Begin Code »------------
--COLOR BEGIN
--Generate Rainbow Screen
IF (v_cnt >= 0) AND (v_cnt < 31) THEN
red_signal <= "111";
green_signal <= v_cnt(4 downto 2);
blue_signal <= "000";
ELSIF (v_cnt >= 32) AND (v_cnt < 63) THEN
red_signal <= v_cnt(4 downto 2)
XOR "111";
green_signal <= "111";
blue_signal <= "000";
ELSIF (v_cnt >= 64) AND (v_cnt < 95) THEN
red_signal <= "000";
green_signal <= "111";
blue_signal <= v_cnt(4 downto 2);
..
...
..
ELSIF (v_cnt >= 416) AND (v_cnt < 447) THEN
red_signal <= "000";
green_signal <= "111";
blue_signal <= v_cnt(4 downto 2);
ELSIF (v_cnt >= 448) AND (v_cnt < 479) THEN
red_signal <= "000";
green_signal <= v_cnt(4 downto 2)
XOR "111";
blue_signal <= "111";
END IF;
--COLOR END
------------« End Code »------------
The code seen above displays all possible colors that can be generated using the 9 resistor VGA DAC. The 3 output signals for Red, Green and Blue control which pins are +5v and which are +0v, thus controlling the intensity of each color yielding 512 unique colors. The VGA standard for 256 colors uses only 3 bits for Red/Green and 2 bits for Blue. If you prefer to stick to the standard this is easily done as well, just omit the least significant bit of the Blue signal.
Colored Ball Movement
------------« Begin Code »------------
...
....
...
BEGIN
video_en <= horizontal_en AND vertical_en AND ball_en;
PROCESS
...
....
...
--Ball Horizontal and Vertical Limits
IF(ball_row = 0) THEN
direction_vert <= '1';
ELSIF(ball_row = 17) THEN
direction_vert <= '0';
END IF;
IF(ball_col = 0) THEN
direction_horz <= '1';
ELSIF(ball_col = 12) THEN
direction_horz <= '0';
END IF;
--Ball Movement Control
IF(cnt = 1000000) THEN
IF(direction_vert > '0') THEN
ball_row <= ball_row + 1;
ELSE
ball_row <= ball_row - 1;
END IF;
IF(direction_horz > '0') THEN
ball_col <= ball_col + 1;
ELSE
ball_col <= ball_col - 1;
END IF;
END IF;
--Ball Display
IF(v_cnt(9 downto 5) > ball_col AND
v_cnt(9 downto 5) < 2+ball_col AND
h_cnt(9 downto 5) > ball_row AND
h_cnt(9 downto 5) < 2+ball_row) THEN
ball_en <= '1';
ELSE
ball_en <= '0';
END IF;
...
....
...
------------« End Code »------------
As a simple pleasantry I added in some code for a simple colored ball that bounces around the screen, while also changing colors. It changes colors in a rainbow pattern from red to violet and starts over again. The ball is actually an illusion in that color output pattern is the same as the first VHDL software, the ball is just an extra enable on the video output so that only a small block of video is actually displayed. There is no real use for this other than the 'cool' factor to be had from it. The source code is above, so download, inspect and use it at your leisure.