画圈vhdl

时间:2012-11-21 14:13:05

标签: vhdl fpga

如何在VHDL中绘制圆圈? 有my BDF design

播种,我需要绘制红色圆圈~100像素半径。我想我应该使用一些矢量,但是怎么样?

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;

2 个答案:

答案 0 :(得分:2)

一种方法是X**2 + Y**2 = R**2;的一些变体 例如Y = Sqrt(R**2 - X**2)

高效实现的技巧是避免像sqrt这样的昂贵操作,并最小化(略微)昂贵的乘法。

您可以猜测Y,(从某个地方开始,你知道Y会为0),将它平方并与每个新X的R * 2 - X * 2进行比较,修改你的猜测什么时候太错了。 马丁的搜索条件在这里会有所帮助。

坐标变换以设置屏幕上正确位置的原点(0,0)相对容易。

答案 1 :(得分:2)

您可以通过将157696更改为(160000 - r ^ 2)

来设置任意半径

480和640是圆心乘以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;