Search code examples
vhdlfpga

Draw circle vhdl


How I can draw circle in VHDL? There is my BDF design

Sow, I need to draw red circle ~ 100 px radius. I think I should use some vector, but how?

entity VGAFrameTest is
port(   yrow, xcolumn : in unsigned(9 downto 0); -- row and  column number of VGA video
        VGA_CLK : in std_logic;                -- pixel clock
        VGA_R, VGA_G, VGA_B: out std_logic_vector(9 downto 0)); --  color information
end;

architecture rtl of VGAFrameTest is
constant COLOR_ON : std_logic_vector(9 downto 0) := (others=>'1'); 
constant COLOR_OFF : std_logic_vector(9 downto 0) := (others=>'0');
constant ROW_HEIGHT : integer := 480; -- number of visible rows
-- A test of visible range is recommended
-- VGA 640x480@60Hz resolution is not natural for LCD monitors
-- They support it but some monitors do not display all columns
-- 1 or 2 last columns can be missing
constant COLUMN_WIDTH : integer := 640 -1 ; -- number of visible columns - correction

begin
  frame:process(VGA_CLK)
  begin
  if rising_edge(VGA_CLK) then
        VGA_R<=COLOR_ON;VGA_G<=COLOR_ON;VGA_B<=COLOR_ON; --initilize  color to white  
        if (yrow = 240 and xcolumn = 320) then
          VGA_B<=COLOR_OFF; VGA_G<=COLOR_OFF; 
        elsif yrow = 1 or yrow = ROW_HEIGHT-2 or xcolumn=1 or xcolumn = COLUMN_WIDTH-2 then
          VGA_R<=COLOR_OFF; VGA_G<=COLOR_OFF; VGA_B<=COLOR_OFF; -- black frame
        elsif yrow = ROW_HEIGHT-1 then        
          VGA_B<=COLOR_OFF; VGA_G<=COLOR_OFF; --last  column is red
        end if;  
 end if;    
 end process;

end;

Solution

  • You can set any radius by changing 157696 to (160000 - r^2)

    480 and 640 is center of circle multiplied by 2

      begin
          frame:process(VGA_CLK)
          begin
          if rising_edge(VGA_CLK) then 
          VGA_R<=COLOR_OFF;VGA_G<=COLOR_OFF;VGA_B<=COLOR_OFF;
                if yrow>159 and yrow <320 and xcolumn < 440  and xcolumn > 199  then 
                  VGA_B<=COLOR_ON; VGA_G<=COLOR_ON;VGA_R<=COLOR_ON;   
    
                   if  (480*yrow-yrow*yrow+640*xcolumn-xcolumn*xcolumn )> 157696   then
                  VGA_B<="0001001100"; VGA_G<=COLOR_OFF; VGA_R <= "1011111000";  
                 end if;
                end if;  
    
    
     end if;    
     end process;