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;

  • 相关阅读:
    【计蒜客】贝壳找房户外拓展(中等)扫描线+线段树
    【CodeForces】925 C.Big Secret 异或
    【LibreOJ】#6392. 「THUPC2018」密码学第三次小作业 / Rsa 扩展欧几里得算法
    【LibreOJ】#6395. 「THUPC2018」城市地铁规划 / City 背包DP+Prufer序
    【BZOJ】1095: [ZJOI2007]Hide 捉迷藏 括号序列+线段树
    【BZOJ】2111: [ZJOI2010]Perm 排列计数 计数DP+排列组合+lucas
    【计蒜客】百度科学家(困难)
    【BZOJ】2115: [Wc2011] Xor
    【GDOI2018】所有题目和解题报告
    【BZOJ】2434: [Noi2011]阿狸的打字机 AC自动机+树状数组+DFS序
  • 原文地址:https://www.cnblogs.com/xionda/p/6010539.html
Copyright © 2011-2022 走看看