| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 911 人关注过本帖
标题:调色板的练习
只看楼主 加入收藏
hoodlum1980
Rank: 2
来 自:浙江大学
等 级:论坛游民
威 望:2
帖 子:289
专家分:23
注 册:2008-2-24
收藏
 问题点数:0 回复次数:0 
调色板的练习
刚开始学习一些,属于我自己做试验,范例级别的代码,不蕴含什么含量,所以不当之处在所难免,刚来,总要发些帖子才好。。
它的效果是画一个金刚石图形,然后通过设置调色板颜色,使图像的颜色发生变化,按照photoshop中调整色相的方式。但是会略有闪烁,暂时还没想到如何尽量避免这种现象。tc的路径需要设置为tc的安装路径。代码如下:

#include <graphics.h>
#include <dos.h>
#include <math.h>
#include <alloc.h>

/* draw a diamond of N point ,a0: startangle*/
void DrawDiamond(int N,int cx,int cy,int R,double a0)
{
    int *x=(int*)malloc(N*2);
    double angle=M_PI*2/N;
    int i,j;
    if(x==NULL)
        return;
    for(i=0;i<N;i++)
    {
        x[i*2]=(int)(cx+R*cos(angle*i+a0)+0.5);
        x[i*2+1]=(int)(cy+R*sin(angle*i+a0)+0.5);
    }
    for(i=0;i<(N-1);i++)
    {
        for(j=i;j<N;j++)
        {
            line(x[2*i],x[2*i+1],x[2*j],x[2*j+1]);
        }
    }
    line(x[2*N-2],x[2*N-1],x[0],x[1]);
    free(x);
}

void main()
{
    int graphdriver=DETECT,graphmode;
    struct palettetype palette;
    int i,flag,doing=1,index;/* ++ or -- flag */
    int RGB[3]={255,0,0};
    int order[3]={1,0,2};
    initgraph(&graphdriver,&graphmode,"c:\\tc\\");
    getpalette(&palette);
    setcolor(1);
    DrawDiamond(14,150,150,80,0);
    i=0;
    flag=1;

    for(i=0;i<3*5 && doing;i++,flag*=-1)
    {
        index=order[i%3];
        for(;RGB[index]>=0 && RGB[index]<=255;)
        {
            delay(10000);
            if(kbhit())
            {
                doing=0;
                break;
            }
            RGB[index]+=flag;
            setrgbpalette(1,RGB[0],RGB[1],RGB[2]);
            delay(5000);
        }
        /* invalid range */
        if(RGB[index]<0)
            RGB[index]=0;
        else if(RGB[index]>255)
            RGB[index]=255;
        delay(20000);
    }
    printf("Press any key to exit~\n");
    getch();
    setallpalette(&palette);
    closegraph();
}

[[it] 本帖最后由 hoodlum1980 于 2008-2-25 03:26 编辑 [/it]]
收到的鲜花
  • 永夜的极光2008-02-25 07:53 送鲜花  8朵   附言:我很赞同
  • sunkaidong2008-02-25 09:51 送鲜花  5朵  
  • xianshizhe1112008-02-25 15:20 送鲜花  6朵   附言:楼主强人 赞了
搜索更多相关主题的帖子: 练习 调色板 
2008-02-25 03:22
快速回复:调色板的练习
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014424 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved