c++编程绘图作业.docx
- 文档编号:8016156
- 上传时间:2023-01-28
- 格式:DOCX
- 页数:14
- 大小:247.79KB
c++编程绘图作业.docx
《c++编程绘图作业.docx》由会员分享,可在线阅读,更多相关《c++编程绘图作业.docx(14页珍藏版)》请在冰豆网上搜索。
c++编程绘图作业
计算机编程绘图作业
例题2-1
CRectrc;
GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(2,-2);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
intpa[5][2]={0,0,0,120,-240,0,240,0,0,120};
POINTpb[9]={-160,0,-160,40,-80,0,-80,80,0,0,80,80,80,0,160,40,160,0};
CPenpen(0,2,RGB(0,0,0));
pDC->SelectObject(pen);
pDC->MoveTo(pa[0][0],pa[0][1]);
for(inti=1;i<=4;i++)
pDC->LineTo(pa[i][0],pa[i][1]);
pDC->Polyline(pb,9);
例题2-2
CRectrc;
GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(1,-1);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
CPen*p01,*p02;
pDC->SelectStockObject(NULL_BRUSH);
for(inti=1;i<=15;i++)
{p01=newCPen(0,2,RGB(10*i,0,5*i));
p02=pDC->SelectObject(p01);
pDC->Ellipse(300-10*i,100,300+10*i,100-20*i);
pDC->SelectObject(p02);
deletep01;}
例题2-3
#include"math.h"
CRectrc;
GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(2,-2);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
CPenpen(0,2,RGB(0,0,0));pDC->SelectObject(pen);
doublepp[12][2],r1=100,r2=38.2;
for(inti=1;i<=11;i=i+2)
{pp[i][0]=r1*cos(1.571+(i-1)/2*2*3.1415926/5);
pp[i][1]=r1*sin(1.571+(i-1)/2*2*3.1415926/5);}
for(i=2;i<=10;i=i+2)
{pp[i][0]=r2*cos(1.571+0.62831852+(i-2)/2*2*3.1415926/5);
pp[i][1]=r2*sin(1.571+0.62831852+(i-2)/2*2*3.1415926/5);}
pDC->MoveTo(pp[1][0],pp[1][1]);
for(i=2;i<=11;i++)
pDC->LineTo(pp[i][0],pp[i][1]);
for(intj=1,k=6;j<=5;j++,k++)
{pDC->MoveTo(pp[j][0],pp[j][1]);
pDC->LineTo(pp[k][0],pp[k][1]);}
例题2-4
CRectrc;
GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(2,-2);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
pDC->MoveTo(-5,0);
pDC->LineTo(-5,100);
pDC->LineTo(5,100);
pDC->LineTo(5,0);
pDC->MoveTo(-85,0);
pDC->LineTo(85,0);
pDC->MoveTo(-15,10);
pDC->ArcTo(-85,10,-65,-10,-75,10,-85,0);
pDC->MoveTo(-15,10);
pDC->SetArcDirection(AD_CLOCKWISE);
pDC->ArcTo(-15,80,5,60,-15,70,-5,80);
pDC->MoveTo(15,10);
pDC->ArcTo(65,10,85,-10,75,10,85,0);
pDC->MoveTo(15,10);
pDC->SetArcDirection(AD_COUNTERCLOCKWISE);
pDC->ArcTo(-5,80,15,60,15,70,5,80);
例题2-5
CRectrc;
GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(1,-1);
pDC->SetViewportOrg(rc.right/2,2*rc.bottom/3);
CPenp01(0,2,RGB(0,0,0));
CPenp02(3,0,RGB(255,0,0));
POINTpp[6]={(int)-82.91562,225,-280,225,-280,0,280,0,280,225,(int)82.91562,225};
pDC->SelectObject(p01);
pDC->Polyline(pp,6);
pDC->MoveTo(60,0);pDC->LineTo(60,20);
pDC->MoveTo(-60,0);pDC->LineTo(-60,20);
pDC->AngleArc(0,100,100,(int)126.869898,(int)286.260205);
pDC->MoveTo((int)-82.91562,225);
pDC->AngleArc(0,100,150,(int)236.44269,(int)67.114620);
pDC->SelectObject(p02);
pDC->MoveTo(-110,100);pDC->LineTo(110,100);
pDC->MoveTo(0,-10);pDC->LineTo(0,260);
例题2-6
#include"math.h"
#defineX(t)140*cos(t)
#defineY(t)50*sin(t)
CRectrc;
GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(2,-2);
pDC->SetViewportOrg(rc.right/2,2*rc.bottom/3);
CPenp01(0,2,RGB(0,0,0));
CPenp02(5,2,RGB(0,0,0));
pDC->SelectObject(p01);
pDC->MoveTo(-70,0);
pDC->AngleArc(0,0,70,180,180);
doublex,y;
for(doublet=0;t<=2*3.1415926;t+=0.0001)
{x=X(t);y=Y(t);
if(t==0)pDC->MoveTo(x,y);
else
if(y>0&&sqrt(x*x+y*y)<70)
pDC->SelectObject(p02);
else
pDC->SelectObject(p01);
pDC->LineTo(x,y);}
例题2-7
#include"math.h"
CRectrc;
GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(1,-1);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
doublepp[13][2]={0,0,0,-200,-sqrt(200*200-400/3*400/3),-400/3,
-sqrt(200*200-200/3*200/3),-200/3,-200,0,-sqrt(200*200-200/3*200/3),
200/3,-sqrt(200*200-400/3*400/3),400/3,0,200,sqrt(200*200-400/3*400/3),
-400/3,sqrt(200*200-200/3*200/3),-200/3,200,0,sqrt(200*200-200/3*200/3),
200/3,sqrt(200*200-400/3*400/3),400/3};
for(inti=1,j=7;i<=6;i++,j++)
{pDC->MoveTo(pp[i][0],pp[i][1]);
pDC->LineTo(pp[j][0],pp[j][1]);}
doublepe[3][4]={-100,200,100,-200,-100*sqrt(3),200,100*sqrt(3),-200,
-200,200,200,-200};
pDC->SelectStockObject(NULL_BRUSH);
for(i=0;i<=2;i++)
pDC->Ellipse(pe[i][0],pe[i][1],pe[i][2],pe[i][3]);
例题2-8
#include"math.h"
#defineX(t)120*cos(t)*cos(1.5*t)
#defineY(t)120*sin(t)*cos(1.5*t)
CRectrc;
GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(1,-1);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
for(doublet=0;t<=20*3.1415926;t+=0.0001)
{pDC->MoveTo(0,0);
pDC->LineTo(X(t),Y(t));}
例题2-9
#include"math.h"
CRectrc;GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(1,-1);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
doublex1[27],y1[27];inti,j;
for(i=1;i<=13;i++)
{x1[i]=-sqrt(140*140-(-140+20*i)*(-140+20*i));
y1[i]=-140+20*i;}
for(i=14;i<=26;i++)
{x1[i]=sqrt(140*140-(-400+20*i)*(-400+20*i));
y1[i]=-400+20*i;}
for(i=1,j=14;i<=13;i++,j++)
{pDC->MoveTo(x1[i]*cos(0.785398)-y1[i]*sin(0.785398),
x1[i]*sin(0.785398)+y1[i]*cos(0.785398));
pDC->LineTo(x1[j]*cos(0.785398)-y1[j]*sin(0.785398),
x1[j]*sin(0.785398)+y1[j]*cos(0.785398));}
pDC->SelectStockObject(NULL_BRUSH);
pDC->Ellipse(-145,145,145,-145);pDC->Ellipse(-140,140,140,-140);
例题2-10
CRectrc;
GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(2,-2);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
doublex1[27]={0,-100,-100,-100,-80,-60,-40,-20,0,20,40,60,80,100,
100,100,-100,-80,-60,-40,-20,0,20,40,60,80,100};
doubley1[27]={0,0,65,-20,0,-20,0,-20,0,-20,0,-20,0,-20,0,65,65,65,
65,65,65,65,65,65,65,65,65};
for(inti=1,j=14;i<=13;i++,j++)
{pDC->MoveTo(x1[i],y1[i]+x1[i]*0.4);
pDC->LineTo(x1[j],y1[j]+x1[j]*0.4);}
例题2-11
#include"math.h"
#defineX(t)100*cos(t)*cos((i-1)*3.1415926/8)-40*sin(t)*sin((i-1)*3.14159/8)
#defineY(t)100*cos(t)*sin((i-1)*3.1415926/8)+40*sin(t)*cos((i-1)*3.14159/8)
CRectrc;
GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(2,-2);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
for(inti=1;i<=8;i++)
{for(doublet=0;t<=2*3.1415926;t+=0.0001)
{if(t==0)
pDC->MoveTo(X(t),Y(t));
else
pDC->LineTo(X(t),Y(t));}}
例题2-12
CRectrc;
GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowExt(1,1);
pDC->SetViewportExt(1,-1);
pDC->SetViewportOrg(rc.right/2,2*rc.bottom/3);
doublex[29]={0,0,215,215,215,165,215,155,225,155,155,235,255,275,295,315,315,315,315,165,215,155,225,225,225,235,255,275,295};
doubley[29]={0,0,5,140,145,0,0,200,200,200,210,5,5,5,5,0,5,140,145,200,200,210,210,200,210,140,140,140,140};
for(inti=1,j=15;i<=14;i++,j++)
{pDC->MoveTo((int)x[i],(int)y[i]);
pDC->LineTo((int)x[j],(int)y[j]);}
for(i=1,j=15;i<=14;i++,j++)
{pDC->MoveTo((int)-x[i],(int)y[i]);
pDC->LineTo((int)-x[j],(int)y[j]);}
for(doublet=0;t<=3.1415926;t+=0.0001)
{if(t==0)
pDC->MoveTo((int)25*cos(t)+190,(int)25*sin(t)+210);
else
pDC->LineTo((int)25*cos(t)+190,(int)25*sin(t)+210);}
for(t=0;t<=3.1415926;t+=0.0001)
{if(t==0)
pDC->MoveTo((int)-25*cos(t)-190,(int)25*sin(t)+210);
else
pDC->LineTo((int)-25*cos(t)-190,(int)25*sin(t)+210);}
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c+ 编程 绘图 作业