#include <GL/glut.h> /喊宏/ 设置头文件
#include <stdlib.h>
#include <math.h>
/*void setPixel ( int x, int y)
{
glBegin ( GL_POINTS)
glVertex2i (x, y)
glEnd ()
}
inline int round (const float a ) { return int (a + 0.5)}
void lineDDA (int x0, int y0, int xEnd, int yEnd)
{
int dx = xEnd - x0, dy = yEnd - y0, steps, k
float xIncrement, yIncrement, x = x0, y = y0
if (fabs (dx) >fabs (dy))
steps = fabs (dx)
else
steps = fabs (dy)
xIncrement = float (dx) / float (steps)
yIncrement = float (dy) /郑慧册 float (steps)
setPixel (round (x), round (y))
for (k = 0k <stepsk++) {
x += xIncrement
y += yIncrement
setPixel (round (x), round (y))
}
} */
class screenPt
{
private:
GLint x,y
public:
screenPt()
{
x=y=0
}
void setCoords (GLint xCoordValue,GLint yCoordValue)
{
x=xCoordValue
y=yCoordValue
}
GLint getx() const{
return x
}
GLint gety() const{
return y
}
void incrementx()
{
x++
}
void decrementy()
{
y--
}
}
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)
void circlePlotPoints (GLint ,GLint,screenPt)
circlePlotPoints(xc,yc,circPt)
while(circPt.getx()<circPt.gety())
{
circPt.incrementx()
if(p<0)
p += 2*circPt.getx() + 1
else
{
circPt.decrementy()
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 init (void) // 初始化函数
{
glClearColor (1.0, 1.0, 1.0, 0.0)// 设置清屏的颜色(Red,green,blue),但不能让该颜色在显示窗上
// 出现
glMatrixMode (GL_PROJECTION) // 设置投影矩阵
glLoadIdentity ()// 单位化上述投影矩阵
gluOrtho2D (0.0, 800.0, 0.0, 600.0) // 设置具体投影 矩阵为平面正交投影 4/3
}
void lineSegment (void) //绘图函数
{
glClear (GL_COLOR_BUFFER_BIT)// 按glClearColor (1.0, 1.0, 1.0, 0.0)指定的颜色刷新颜色
glColor3f (1.0, 0.0, 0.0)//设置前景色,即画图的颜色
circleMidpoint(400,300,200)
glFlush ( ) // 在每一画面或场景的结尾处调用,强制前面发出的OpenGL 命令开始执行
}
void main (int argc, char** argv) // OpenGL 绘图主函数
{
glutInit (&argc, argv) // 初始化GLUT 库
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB) // 设置 显示模式
glutInitWindowPosition (50, 100) // 窗口左上角像素坐标
glutInitWindowSize (800, 600)// 设置设备显示窗口大小 4/3
glutCreateWindow ("An Example OpenGL Program")//创建一个窗口,参数为窗口的标题
init ( ) // 函数调用.
glutDisplayFunc (lineSegment)// 绘制当前窗口
glutMainLoop ( )//通常用于程序的结尾,表示开始运行程序.显示出所有创建的窗口
}
#include "stdio.h"
int main()
{
int i, j, n, k = 2, m = 1
printf("请输入一个奇则森做数:")
scanf("%d", &n)
if (n % 2 == 孙衡0)
n++
for (i = 0 i < n i++)
{
for (j = 0 j < 春败m j++)
printf("*")
printf("\n")
if (m >= n)
k = -k
m += k
}
return 0
}
1
#include <stdio.h>int main()
{
int i, j
for (i = 0 i < 4 ++i)
{
for (j = 0 雹森碰j < i ++j)
putchar(' ')
for (j = 0 j < 8 ++j)
putchar('*')
源谈 putchar('\n')
}
return 0
}
2
#include <stdio.h>int main()
{
int i, j
for (i = 0 i < 4 ++i)
{
for (j = 3 - i j > 0 --j)
putchar(' ')
for (j = 0 j < 8 ++j)
putchar('*')
春启 putchar('\n')
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)