如何根据一堆坐标点画点图用C语言
最近遇到了一个问题,请教大牛有什么方便快捷的方法实现。
现状:(x,y)的值是从文件中一个个循环读出来的,x为时间,y为一个整数,怎么画出所有的点(x,y)
编译环境:vc++ c Visual?C++ 绘图
[解决办法]
参考http://www.google.com.hk/url?sa=t&rct=j&q=MFC%20%E7%BB%98%E5%88%B6%E5%87%BD%E6%95%B0%E5%9B%BE%E5%BD%A2&source=web&cd=3&ved=0CDgQFjAC&url=http%3a%2f%2fread%2epudn%2ecom%2fdownloads93%2febook%2f363546%2fVC%252B%252B%25E5%25AE%259E%25E7%258E%25B0%25E6%2595%25B0%25E5%25AD%25A6%25E5%2587%25BD%25E6%2595%25B0%25E5%259B%25BE%25E5%25BD%25A2%25E7%25BB%2598%25E5%2588%25B6%2edoc&ei=4Av6UZLOO83PlAW9nIDwDg&usg=AFQjCNGdjzz6RX2qFJ5H28cZ2NfdSVskIg&bvm=bv.50165853,d.dGI&cad=rjt
还有http://www.cnblogs.com/WastonLiang/archive/2013/05/25/3099421.html
[解决办法]
仅供参考:
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
HWND WINAPI GetConsoleWindow();
void HideTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = FALSE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
void ShowTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = TRUE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
int main() {
HWND hwnd;
HDC hdc;
HFONT hfont;
int i,x,y;
srand(time(NULL));
system("color F0");
system("cls");
HideTheCursor();
hwnd = GetConsoleWindow();
hdc = GetDC(hwnd);
hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "华文楷体");
SelectObject(hdc,hfont);
TextOut(hdc,10,10,"地球人都知道!",14);
MoveToEx(hdc,5,5,NULL);
LineTo(hdc,300, 5);
LineTo(hdc,300, 60);
LineTo(hdc, 5, 60);
LineTo(hdc, 5, 5);
for (i=0;i<100;i++) {
x=rand()%400;
y=rand()%300;
SetPixel(hdc,x,y,0);
}
DeleteObject(hfont);
ReleaseDC(hwnd,hdc);
getchar();
system("color 07");
system("cls");
ShowTheCursor();
return 0;
}
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
HWND WINAPI GetConsoleWindow();
void HideTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = FALSE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
void ShowTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = TRUE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
int main() {
HWND hwnd;
HDC hdc;
HFONT hfont;
RECT rect,wsize;
HBRUSH hbrush;
int y,x,d,g;
system("color F0");
system("cls");
HideTheCursor();
hwnd =GetConsoleWindow();
GetClientRect(hwnd,&wsize);
hdc =GetDC(hwnd);
hfont =CreateFont(48,0,0,0,0,0,0,0,0,0,0,0,0,"华文楷体");
hbrush=CreateSolidBrush((COLORREF)0x00FFFFFF);
SelectObject(hdc,hfont);
y=10;x=30;d=4;g=3;
while (1) {
rect.left=x;
rect.top=y;
rect.right=x+300+d+1;
rect.bottom=y+60+d+1;
FillRect(hdc, &rect, hbrush);
TextOut(hdc,x+10,y+10,"地球人都知道!",14);
MoveToEx(hdc,x+5,y+5,NULL);
LineTo(hdc,x+300,y+ 5);
LineTo(hdc,x+300,y+ 60);
LineTo(hdc,x+ 5,y+ 60);
LineTo(hdc,x+ 5,y+ 5);
Sleep(15);
if (_kbhit()) {getch();break;}
switch (g) {
case 0:if (y> d) y-=d; else g=2;if (x> d) x-=d; else g=1;break;// ↖
case 1:if (y> d) y-=d; else g=3;if (x<wsize.right-300-d) x+=d; else g=0;break;// ↗
case 2:if (y<wsize.bottom-60-d) y+=d; else g=0;if (x> d) x-=d; else g=3;break;// ↙
case 3:if (y<wsize.bottom-60-d) y+=d; else g=1;if (x<wsize.right-300-d) x+=d; else g=2;break;// ↘
}
}
DeleteObject(hbrush);
DeleteObject(hfont);
ReleaseDC(hwnd,hdc);
system("color 07");
system("cls");
ShowTheCursor();
return 0;
}