| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦   
共有 370 人关注过本帖
标题:关于一个图形编程
收藏  订阅  推荐  打印
huangch
Rank: 2
来自:肇庆学院网络工程系
等级:注册会员
帖子:42
积分:532
注册:2008-7-21
关于一个图形编程

莱鸟学图形编程!
以上想运行下面的程序:
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>
#include <bios.h>
#include <ctype.h>
#include <process.h>
#include <conio.h>
#include <system.h>

#define COLOR    WHITE
#define F1       59
#define F2       60
#define UP       72
#define DOWN     80
#define LEFT     75
#define RIGHT    77
#define HOME     71
#define END      79
#define PAGEUP   73
#define PAGEDOWN 81

void menu(void);
void save(void);
void load(void);
void xhaira(int a,int b);

struct k
{
  char c[2];
  int i;
};
typedef struct k KEY;
KEY key;

struct dot
{
  int x;
  int y;
};
typedef struct dot DOT;
DOT dis;

main()
{
  int inc = 1, k, j, m, r;
  int driver, mode;
  DOT firstdot, secdot;

  dis.x = 200;
  dis.y = 200;

  driver = DETECT;
  mode = VGAHI;
  initgraph(&driver, &mode, "C:\\TC\\BGI");

  setbkcolor(BLUE);
  cleardevice();
  setcolor(YELLOW);
  xhairs(dis.x, dis.y);

  while( key.c[0] != 'q')
  {
    menu();

    key.i = bioskey(0);
    xhairs(dis.x, dis.y);

    if(!key.c[0])
    {
      switch( key.c[1] )
      {
    case LEFT:  dis.x -= inc;
            break;
    case RIGHT: dis.x += inc;
            break;
    case UP:    dis.y -= inc;
            break;
    case DOWN:  dis.y += inc;
            break;
    case HOME:  dis.x -= inc;
                dis.y -= inc;
            break;
    case PAGEUP:dis.x += inc;
                dis.y -= inc;
            break;
    case END:   dis.x -= inc;
                dis.y += inc;
            break;
    case PAGEDOWN: dis.x += inc;
                   dis.y += inc;
            break;
    case F1:    inc = 1;
            break;
    case F2:    inc = 5;
            break;
    }
      }
      else
      {
    switch(tolower(key.c[0]))
    {
    case 'a':  putpixel (dis.x,dis.y,COLOR);
               firstdot.x = dis.x;
               firstdot.y = dis.y;
           break;
    case 'b':  putpixel (dis.x,dis.y,COLOR);
               secdot.x = dis.x;
               secdot.y = dis.y;
           break;
    case 'l':  line(firstdot.x,firstdot.y,
               secdot.x,secdot.y);
           break;
    case 'o':  r = sqrt(fabs((secdot.x - firstdot.x)*(
                              secdot.x - firstdot.x)+(
                              secdot.y - firstdot.y)*(
                              secdot.y - firstdot.y)));
           circle(firstdot.x,firstdot.y,r);
           break;
    case 'h':  rectangle(firstdot.x,firstdot.y,
               secdot.x,secdot.y);
           break;
    case 'c':  cleardevice();
           break;
    case 'w':  save();
           break;
    case 'r':  load();
           break;
    }
    xhairs(dis.x,dis.y);
      }
    }
  closegraph();
}

void xhairs(int a,int b)
{
  int i;

  for(i = a-5; i <= a+5; i++)
      putpixel(i,b,15 ^ getpixel(i,b));
  for(i = b-5; i <= b+5; i++)
      putpiexl(a,i,15 ^ getpixel(a,i));
}

void menu(void)
{
  #define STARTX   10
  #define STARTY   22
  #define DISTANCE 30

  int i;
  char *menu_name[] = { "a:start point.", "b:end point.",
            "l:draw line.","o:draw circle.",
            "h:draw box.","c:clear screen.",
            "F1:step = 1.","F2:step = 5",
            " Home pageUP"," End PageDown.",
            "w:save graph","r:load graph",
            "q:quit" };
  setcolor( WHITE );
  rectangle(5,5,150,470);
  rectangle(155,5,635,470);
  setcolor( LIGHTBLUE );
  settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
  outtextxy(36,STARTY,"menu");
  setcolor( YELLOW );
  settextstyle(DEFAULT_FONT,HORIZ_DIR,1);

  for(i = 0;i <= 14; i++)
      outtextxy(STARTX, STARTY+(i+1)*DISTANCE,menu_name[i]);
}

void save(void)
{
  int i, j;
  FILE *fp;

  if((fp = fopen("graph.dat","w+")) == NULL)
  {
    printf("cannot open this file!");
    exit(0);
  }

  for(i = 5; i <= 470; i++)
  {
    for(j = 155; j <= 635; j++)
    {
      fputc( getpiel (j,i), fp );
    }
  }
  fclose(fp);
  outtextxy(260,471,"save over!");
}

void load(void)
{
  int i, j;
  FILE *fp;

  if((fp = fopen("greph.dat","r+")) == NULL)
  {
    printf("cannot open this file!");
    exit(0);
  }

  outtextxy(280,471,"loading... ...");

  for(i = 5; i <= 470; i++)
  {
    for(j = 155; j <= 635; j++)
    putpixel( j,i,fgetc(fp) );
  }
  fclose(fp);
  outtextxy(368,471,"over");
}
但结果tc编译器指出:
Undefined symbol '_getpiel' in module 2.c;与
Undefined symbol '_putpiexl' in module 2.c!
这俩个问题,于是上网找到是却了一个头文件:system.h!
但tc目录include中并没有此文件!
这里想问问对图形编程有经验的高手,有没有遇到此类问题!
应该怎样解决呢?



2008-8-3 02:46
huangch
Rank: 2
来自:肇庆学院网络工程系
等级:注册会员
帖子:42
积分:532
注册:2008-7-21

没人?????
2008-8-3 12:05
huangch
Rank: 2
来自:肇庆学院网络工程系
等级:注册会员
帖子:42
积分:532
注册:2008-7-21

其实问题是:程序用到#include"system.h" 而Tc系统又找不到该文件。我该怎么办?
2008-8-3 12:20
huangch
Rank: 2
来自:肇庆学院网络工程系
等级:注册会员
帖子:42
积分:532
注册:2008-7-21

我在问!
2008-8-3 12:51
huangch
Rank: 2
来自:肇庆学院网络工程系
等级:注册会员
帖子:42
积分:532
注册:2008-7-21

看来没人会!
或者看到程序那么长久放弃看问题了

嘻嘻!
2008-8-3 14:46
huangch
Rank: 2
来自:肇庆学院网络工程系
等级:注册会员
帖子:42
积分:532
注册:2008-7-21

拜托!
2008-8-3 15:47
chengli
Rank: 1
等级:新手上路
帖子:25
积分:436
注册:2008-7-3
函数写错了而已

getpiel() 是getpixel()
putpiexl() shi putpixel()
2008-8-3 18:54
huangch
Rank: 2
来自:肇庆学院网络工程系
等级:注册会员
帖子:42
积分:532
注册:2008-7-21

引用:
chengli 在 2008-8-3 18:54 的发言:

getpiel() 是getpixel()
putpiexl() shi putpixel()
谢谢!!
2008-8-3 20:32
共有 369 人关注过本帖
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.067074 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved