代碼下載地址:
2015.8.11更新:
2015.8.13更新:
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <graphics.h>
#include <time.h>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
//初始化一個200*200的圖像區域
initgraph(200, 200);
//設置繪圖顏色
setcolor(WHITE);
//畫空心圓
circle(100, 100, 3);
//設置填充顏色
setfillcolor(WHITE);
//填充圓
floodfill(100, 100,WHITE);
//等待按任意鍵
getch();
//關閉圖像
closegraph();
return 0;
}
效果圖:
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <graphics.h>
#include <time.h>
#include <cstdio>
#include <cmath>
using namespace std;
#pragma warning(disable:4996)//無視掉freopen的警告
const int gsize = 600;
int main() {
//打開圖像
initgraph(gsize, gsize);
//繪圖
for (float x = 0, y = 0 ; y < gsize ; x+=0.001, y = x*x/500) {
putpixel(int(x+0.5), int(y+0.5), WHITE);//畫像素
}
//關閉圖像
getch();
closegraph();
return 0;
}
方程y=x^2/500
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <graphics.h>
#include <time.h>
#include <cstdio>
#include <cmath>
using namespace std;
#pragma warning(disable:4996)//無視掉freopen的警告
void mainloop()//主循環
{
//將線條和填充顏色設爲白色
setcolor(WHITE);
setfillcolor(WHITE);
float x = 0, y = 0;
for (; is_run(); delay_fps(60))//每秒60幀
{
//cleardevice();//清屏
y = x*x / 500.0;
fillellipsef(x, y, 3, 3);//畫以(x,y)爲中心,長短軸均爲3的橢圓
x += 1.0;//更新x
}
}
int main(void)
{
//設置初始化圖形,差不多就是默認
setinitmode(INIT_DEFAULT | INIT_NOFORCEEXIT);
//初始化窗口
initgraph(600, 600);
//初始化隨機種子
randomize();
//設置更新窗口模式,爲手動模式
setrendermode(RENDER_MANUAL);
//主循環
mainloop();
//關閉窗口
closegraph();
return 0;
}
這是動態繪製上述拋物線的程序。