計算機圖形學(二)輸出圖元_20_章節總結_程式展示_餅圖
餅圖用來給出整體中各部分的分佈比例。使用中點圓演算法子程式來構造一個餅圖。例子中的值用於確定扇形的數量和大小,
該程式的輸出請參見圖。
#include "stdafx.h"
#include "GL/glut.h"
#include "stdlib.h"
#include "math.h"
#include "iostream"
using namespace std;
const GLdouble twoPi = 6.283185;
GLsizei winWidth = 400, winHeight = 300; // Initial display window size.
class screenPt {
public:
screenPt(){
x = y = 0;
}
GLint x, y;
void setCoords(GLint xCoordValue, GLint yCorrdValue){
x = xCoordValue;
y = yCorrdValue;
}
GLint getx() const{
return x;
}
GLint gety() const{
return y;
}
void incrementx(){
x++;
}
void incrementy(){
y--;
}
};
void init( )
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
void setPixel(GLint xCoord, GLint yCoord){
glBegin(GL_POINTS);
glVertex2i(xCoord, yCoord);
glEnd();
}
void circleMidpoint(GLint xc, GLint yc, GLint radius){
screenPt circPt;
GLint p = 1 - radius;//中點引數初值
circPt.setCoords(0, radius);//Set coords for top point of circle
void circlePlotPoints(GLint, GLint, screenPt);
/*Plot the initial point in each circle quadrant*/
circlePlotPoints(xc, yc, circPt);
/*Calculate next point and plot in each octant*/
while (circPt.getx() < circPt.gety()){
circPt.incrementx();
if (p < 0)
p += 2 * circPt.getx() + 1;
else{
circPt.incrementy();
p += 2 * (circPt.getx() - circPt.gety()) + 1;
}
circlePlotPoints(xc, yc, circPt);
}
}
void circlePlotPoints(GLint xc, GLint yc, screenPt circPt)
{
setPixel(xc + circPt.getx(), yc + circPt.gety());
setPixel(xc - circPt.getx(), yc + circPt.gety());
setPixel(xc + circPt.getx(), yc - circPt.gety());
setPixel(xc - circPt.getx(), yc - circPt.gety());
setPixel(xc + circPt.gety(), yc + circPt.getx());
setPixel(xc - circPt.gety(), yc + circPt.getx());
setPixel(xc + circPt.gety(), yc - circPt.getx());
setPixel(xc - circPt.gety(), yc - circPt.getx());
}
void pieChart( )
{
screenPt circCtr, piePt;
GLint radius = winWidth / 4; // Circle radius.
GLdouble sliceAngle, previousSliceAngle = 0.0;
GLint k, nSlices = 12; // Number of slices.
GLfloat dataValues[12] = { 10.0, 7.0, 13.0, 5.0, 13.0, 14.0, 3.0, 16.0, 5.0, 3.0, 17.0, 8.0 };
GLfloat dataSum = 0.0;
circCtr.x = winWidth / 2; // Circle center position.
circCtr.y = winHeight / 2;
circleMidpoint(circCtr.x, circCtr.y, radius); // 呼叫中點畫圓方法
for (k = 0; k < nSlices; k++)
dataSum += dataValues[k];
for (k = 0; k < nSlices; k++){
sliceAngle = twoPi * dataValues[k] / dataSum + previousSliceAngle;
piePt.x = circCtr.x + radius * cos(sliceAngle);
piePt.y = circCtr.y + radius * sin(sliceAngle);
glBegin(GL_LINES);
glVertex2i(circCtr.x, circCtr.y);
glVertex2i(piePt.x, piePt.y);
glEnd();
previousSliceAngle = sliceAngle;
}
}
void displayFcn( )
{
glClear(GL_COLOR_BUFFER_BIT); // Clear display window.
glColor3f(0.0, 0.0, 1.0); // Set circle color to blue.
pieChart();
glFlush();
}
void winReshpeFcn(GLint newWidth, GLint newHeight)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, GLdouble(newWidth), 0.0, GLdouble(newHeight));
glClear(GL_COLOR_BUFFER_BIT);
/* Reset display-window size parameters. */
winWidth = newWidth;
winHeight = newHeight;
}
int _tmain(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100, 100);
glutInitWindowSize(winWidth, winHeight);
glutCreateWindow("Pie Chart");
init();
glutDisplayFunc(displayFcn);
glutReshapeFunc(winReshpeFcn);
glutMainLoop();
}
相關文章
- 計算機圖形學 第四章 圖形變換計算機
- echarts 餅圖巢狀 二級餅圖 子餅圖 複合餅圖Echarts巢狀
- java3D與計算機圖形學期末複習 第二章Java3D計算機
- 計算機圖形學-線性過濾計算機
- 計算機圖形學之矩陣變換計算機矩陣
- 計算機圖形學入門·光柵化計算機
- 4次Bezier曲線--計算機圖形學 opengl計算機
- AUTOCAD——圖形的輸入與輸出
- Tableau——資料前處理、折線圖、餅圖(環形圖)
- 從零開始學Python視覺化(五): 餅圖及環形圖Python視覺化
- 使用 Flutter 繪製圖表(二)餅狀圖?Flutter
- Android 折線圖之hellocharts (餅狀圖)餅圖Android
- Quart2D 畫圖二 (餅狀圖、柱狀圖)
- 【java學習】GUI 圖形程式設計JavaGUI程式設計
- 計算機圖形學:虛擬和現實世界的融合計算機
- Java 在Excel中新增分離型餅圖、環形圖JavaExcel
- 餅圖
- 計算機圖形學原理及實踐——C語言描述pdf計算機C語言
- jmeter學習指南之結果分析-圖形圖表JMeter
- 餅圖0625
- 標準圓形餅圖Python繪製方法Python
- CSS三角形和餅圖CSS
- Flutter 自定義 Widget 之餅形圖實戰Flutter
- Android-EasyChart第二波餅圖Android
- Keras輸出網路結構圖Keras
- 計算機圖形:三維觀察之投影變換計算機
- 【OpenCV】【計算機圖形學】DIBR: Depth Image Based Rendering/ 3D image warping 中的實現細節OpenCV計算機3D
- 柱狀圖、直方圖、散點圖、餅圖講解直方圖
- 用Python生成柱狀圖、折線圖、餅狀圖來統計自己的手機話費Python
- 《計算機基礎與程式設計》第二週學習總結計算機程式設計
- 大學計算機必修課新講--編譯原理+作業系統+圖形學計算機編譯原理作業系統
- 《計算機圖形學原理及實踐》學習筆記之第十一章計算機筆記
- 學廢了系列 - WebGIS vs WebGL圖形程式設計Web程式設計
- 十億節點大規模圖計算降至「分鐘」級,騰訊開源圖計算框架柏拉圖框架
- 原生JS實現輪播圖--第一章圖片展示JS
- python 圖形初學Python
- 一個碼農是如何用遊戲推動計算機圖形學的?遊戲計算機
- 圖計算 on nLive:Nebula 的圖計算實踐
- 32年後,計算機圖形學再獲圖靈獎,皮克斯大佬推動3D動畫發展計算機圖靈3D動畫