148.绘制蓝天图案

简介: 148.绘制蓝天图案
#include <stdio.h>
#include <dos.h>
#include <math.h>
long Addr[768];
int Mode;
Set_Mode (int mode) /*设置显示的模式,参数为INT 10H的子功能号*/
{
    union REGS r;
    r.h.ah=0;
    r.h.al=mode;
    int86 (0x10,&r,&r);
}
Set_Graphics_Mode (unsigned x,unsigned y) /*设置图形模式的分辨率*/
{
    long i;
    if ((x<321)&&(y<201))  {
        Set_Mode (0x13);
        Mode=0x13;
        for (i=0;i<200;i++)  Addr[i]=320*i;
    }
    else if ((x<641)&&(y<401))  {
        Set_Mode (0x5c);
        Mode=0x5c;
        for (i=0;i<400;i++)  Addr[i]=640*i;
    }
    else if ((x<641)&&(y<481))  {
        Set_Mode (0x5d);
        Mode=0x5d;
        for (i=0;i<480;i++)  Addr[i]=640*i;
    }
    else if ((x<801)&&(y<601))  {
        Set_Mode (0x5e);
        Mode=0x5e;
        for (i=0;i<600;i++)  Addr[i]=800*i;
    }
    else if ((x<1025)&&(y<769))  {
        Set_Mode (0x62);
        Mode=0x62;
        for (i=0;i<768;i++)  Addr[i]=1024*i;
    }
    else  {
        Set_Mode (3);
        printf ("Not support this mode .\n");
        getch ();
    }
}
set_pattern () /*设置调色版*/
{
    int i;
    unsigned char pat[256][3];
    struct SREGS inreg;
    union REGS reg;
    pat[0][0]=0;pat[0][1]=0;pat[0][2]=0;
    for (i=1;i<=255;i++)  { /*设置调色版的颜色*/
        pat[i][0]=(unsigned char)((float)(abs(i-127)*63)/127.0+0.5);
        pat[i][1]=(unsigned char)((float)(abs(i-127)*63)/127.0+0.5);
        pat[i][2]=63;
    } 
    reg.x.ax=0x1012; /*设置VIDEO调色版的颜色块*/
    reg.x.bx=0;
    reg.x.cx=256;
    reg.x.dx=FP_OFF(pat);
    inreg.es=FP_SEG(pat);
    int86x (0x10,&reg,&reg,&inreg);
}
plot (int x,int y,unsigned char color) /*使用指定的颜色画点*/
{
    long offset;
    char Page;
    unsigned char far *address;
    switch (Mode)  {
        case 0x13:
            offset=Addr[y]+x;
            address=(unsigned char far *)(0xa0000000L+offset);
            *address=color;
            break;
        case 0x5c:
        case 0x5d:
        case 0x5e:
            offset=Addr[y]+x;
            Page=(offset>>16);
            outportb (0x3c4,0xe);
            outportb (0x3c5,Page^0x02);
            offset=offset&65535;
            address=(unsigned char far *)(0xa0000000L+offset);
            *address=color;
            break;
        case 0x62:
            offset=Addr[y]+x;
            Page=y>>6;
            outportb (0x3c4,0xe);
            outportb (0x3c5,Page^0x02);
            offset=offset&65535;
            address=(unsigned char far *)(0xa0000000L+offset);
            *address=color;
            break;
        default:
            break;
    }
}
get_pixel (int x,int y) /*获得点颜色*/
{
    long offset;
    char Page;
    unsigned char far *address;
    unsigned char color;
    switch (Mode)  {
        case 0x13:
            offset=Addr[y]+x;
            address=(unsigned char far *)(0xa0000000+offset);
            color=*address;
            break;
        case 0x5c:
        case 0x5d:
        case 0x5e:
            offset=Addr[y]+x;
            Page=(offset>>16);
            outportb (0x3c4,0xe);
            outportb (0x3c5,Page^0x02);
            offset=offset&65535;
            address=(unsigned char far *)(0xa0000000L+offset);
            color=*address;
            break;
        case 0x62:
            offset=Addr[y]+x;
            Page=y>>6;
            outportb (0x3c4,0xe);
            outportb (0x3c5,Page^0x02);
            offset=offset&65535;
            address=(unsigned char far *)(0xa0000000L+offset);
            color=*address;
            break;
        default:
            break;
    }
    return (color);
}
randint (unsigned int range) /*生成随机数*/
{
    float sigma=423.1966;
    static double OldRand=0.4231967;
    double temp;
    temp=sigma*OldRand;
    OldRand=temp-(int)temp;
    return (int)(OldRand*(float)range);
} 
void New_Col (int xa,int ya,int x,int y,int xb,int yb) /*生成新的颜色*/
{
    unsigned int color;
    color=abs(xa-xb)+abs(ya-yb);
    color=randint(color<<1)-color;
    color=color+(get_pixel(xa,ya)+get_pixel(xb,yb)+1)>>1;
    if (color<1)  color=1;
    else if (color>255) color=255;
    if ((get_pixel(x,y)==0)) plot (x,y,color);
}
void Sub_Divide (int x1,int y1,int x2,int y2) /*递归填充一块区域*/
{
    int x,y;
    unsigned char color;
    if (!((x2-x1<2)&&(y2-y1<2)))  {
        x=(x1+x2)>>1;
        y=(y1+y2)>>1;
        New_Col (x1,y1,x,y1,x2,y1);
        New_Col (x2,y1,x2,y,x2,y2);
        New_Col (x1,y2,x,y2,x2,y2);
        New_Col (x1,y1,x1,y,x1,y2);
        color=(get_pixel(x1,y1)+get_pixel(x2,y1)+get_pixel(x2,y2)+get_pixel (x1,y2)+2)>>2;
        plot (x,y,color);
        Sub_Divide (x1,y1,x,y);
        Sub_Divide (x,y1,x2,y);
        Sub_Divide (x,y,x2,y2);
        Sub_Divide (x1,y,x,y2);
    }
}
main ()
{
    int x,y;
    x=320;y=200;
    Set_Graphics_Mode (x,y);
    set_pattern ();
    plot (0,0,randint(254)+1);
    plot (x-1,0,randint(254)+1);
    plot (x-1,y-1,randint(254)+1);
    plot (0,y-1,randint(254)+1);
    Sub_Divide (0,0,x-1,y-1);
    getch();
    Set_Mode (0x03);
}
相关文章
|
5月前
|
机器学习/深度学习 存储 Kubernetes
【重磅发布】AllData数据中台核心功能:机器学习算法平台
杭州奥零数据科技有限公司成立于2023年,专注于数据中台业务,维护开源项目AllData并提供商业版解决方案。AllData提供数据集成、存储、开发、治理及BI展示等一站式服务,支持AI大模型应用,助力企业高效利用数据价值。
|
JavaScript 前端开发 索引
JS - includes 方法和 map 方法使用方式
这篇文章介绍了JavaScript中数组的`includes`方法和`map`方法的用法,包括它们的语法、参数说明和具体的示例代码。`includes`方法用于判断数组是否包含特定元素,而`map`方法用于对数组中的每个元素执行操作并返回新数组。
384 1
|
存储 SQL 数据库
Python 金融编程第二版(GPT 重译)(四)(4)
Python 金融编程第二版(GPT 重译)(四)
137 3
|
10月前
|
NoSQL Redis Docker
【赵渝强老师】使用Docker Compose管理容器
Docker Compose 通过 YAML 文件管理多个容器,简化复杂系统的部署和管理。本文介绍了 Docker Compose 的基本概念,并通过一个包含 Redis DB 和 Python Web 模块的示例,展示了如何使用 Docker Compose 部署和管理多容器应用。手动部署和 Docker Compose 部署的对比突显了 Docker Compose 在系统复杂度增加时的优势。
144 0
|
10月前
|
运维 监控 安全
2024除了宝塔面板还有哪些好用的服务器管理软件
2024年,服务器管理软件市场百花齐放,本文介绍Websoft9、cPanel和Orion-Ops三款软件,分别在开源应用部署、Web主机管理和自动化运维方面表现出色,为用户提供更多选择。
|
监控 NoSQL 测试技术
python使用Flask,Redis和Celery的异步任务
python使用Flask,Redis和Celery的异步任务
|
机器学习/深度学习 计算机视觉 Python
output
【9月更文挑战第14天】
204 2
|
Oracle 关系型数据库 Linux
oracle学习82-VMware出现配置文件 .vmx 是由VMware产品创建,但该产品与此版 VMware workstation 不兼容,因此无法使用(VMware版本不兼容问题)
oracle学习82-VMware出现配置文件 .vmx 是由VMware产品创建,但该产品与此版 VMware workstation 不兼容,因此无法使用(VMware版本不兼容问题)
937 0
oracle学习82-VMware出现配置文件 .vmx 是由VMware产品创建,但该产品与此版 VMware workstation 不兼容,因此无法使用(VMware版本不兼容问题)
|
JavaScript 测试技术 iOS开发
vue element plus Icon 图标
vue element plus Icon 图标
6493 0