zoukankan      html  css  js  c++  java
  • Delphi实现RGB色环的代码绘制

    function TColorFrm.CreateColorCircle(const size: integer): TBitmap;
    var
    i,j,x,y: Integer;
    radius: integer;
    perimeter,arc,degree,step: double;
    R,G,B: byte;
    color: TColor;
    begin
    radius := round(size / 2);
    RESULT := TBitmap.Create;
    R:=255;
    G:=0;
    B:=0;
    with RESULT do
    begin
    width := size;
    height:= size;
    pixelFormat := pf24bit;
    Canvas.Brush.Color := RGB(R,G,B);
    x := size + 1;
    y := round(radius) + 1;
    Canvas.FillRect(Rect(size,round(radius),x,y));
    for j := 0 to size do
    begin
    perimeter := (size - j) * PI + 1;
    arc := perimeter / 6;
    step := ( 255 * 6 ) / perimeter ; //颜色渐变步长
    for i := 0 to round(perimeter) - 1 do
    begin
    degree := 360 / perimeter * i;
    x := round(cos(degree * PI / 180) * (size - j + 1) / 2) + radius;//数学公式,最后加上的是圆心点
    y := round(sin(degree * PI / 180) * (size - j + 1) / 2) + radius;

    if (degree > 0) and (degree <= 60) then
    begin
    R := 255;
    G := 0;
    B := round(step * i);
    end;
    if (degree > 60) and (degree <= 120) then
    begin
    if perimeter / 3 / 120 * (degree - 60) > 1.0 then
    R := 255 - round(step * (i - arc))
    else
    R := 255 - round(step * ABS(i - arc));
    G := 0;
    B := 255;
    end;
    if (degree > 120) and (degree <= 180) then
    begin
    R := 0;
    if perimeter / 3 / 120 * (degree - 120) > 1.0 then
    G := round(step * (i - 2 * arc))
    else
    G := round(step * ABS(i - 2 * arc));
    B := 255;
    end;
    if (degree > 180) and (degree <= 240) then
    begin
    R := 0;
    G := 255;
    if perimeter / 3 / 120 * (degree - 120) > 1.0 then
    B := 255 - round(step * (i - perimeter / 2))
    else
    B := 255 - round(step * ABS(i - perimeter / 2));
    end;
    if (degree > 240) and (degree <= 300) then
    begin
    if perimeter / 3 / 120 * (degree - 240) > 1.0 then
    R := round(step * (i - 4 * arc))
    else
    R := round(step * ABS(i - 4 * arc)) ;
    G := 255;
    B := 0;
    end;
    if (degree > 300) and (degree <= 360) then
    begin
    R := 255;
    if perimeter / 3 / 120 * (degree - 300) > 1.0 then
    G := 255 - round(step * (i - 5 * arc))
    else
    G := 255 - round(step * ABS(i - 5 * arc));
    B := 0;
    end;
    color := RGB( ROUND(R + (255 - R)/size * j),ROUND(G + (255 - G) / size * j),ROUND(B + (255 - B) / size * j));
    Canvas.Brush.Color := color;
    //为了绘制出来的圆好看,分成四个部分进行绘制
    if (degree >= 0) and (degree <= 45) then
    Canvas.FillRect(Rect(x,y,x-2,y-1));
    if (degree > 45) and (degree <= 135) then
    Canvas.FillRect(Rect(x,y,x-1,y-2));
    if (degree > 135) and (degree <= 225) then
    Canvas.FillRect(Rect(x,y,x+2,y+1));
    if (degree > 215) and (degree <= 315) then
    Canvas.FillRect(Rect(x,y,x+1,y+2));
    if (degree > 315) and (degree <= 360) then
    Canvas.FillRect(Rect(x,y,x-2,y-1));
    end;
    end;
    end;
    end;

  • 相关阅读:
    Win7 IE11无法打开的可能解决办法
    s​q​l​ ​s​e​r​v​e​r​ ​2​0​0​0​登​录​名​与​数​据​库​用​户​名​的​关​联​问​题
    错误 0xc0202049: 数据流任务 1: 无法在只读列“ID”中插入数据
    清空SQL Server数据库中所有表数据的方法
    01-鼠标点击空白处实现层隐藏
    01-artDialog4.1.7常用整理
    ASP.NET MVC HtmlHelper用法大全
    随机生成十个数 填充数组
    字串加密、解密
    动手动脑、String类函数的使用说明
  • 原文地址:https://www.cnblogs.com/xionda/p/6010539.html
Copyright © 2011-2022 走看看