当前位置:首页 » 编程语言 » c语言图形编辑组成矩形
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言图形编辑组成矩形

发布时间: 2022-05-14 01:24:52

Ⅰ 如何用c语言画一个矩形

rectangle() 画矩形函数

功能: 函数rectangle() 用当前绘图色、线型及线宽,画一个给定左上角与右下角的矩形(正方形或长方形)。

用法: 此函数调用方式为void rectangle(int left,int top,int right,int bottom);

说明: 参数left,top是左上角点坐标,right,bottom是右下角点坐标。如果有一个以上角点不在当前图形视口内,且裁剪标志clip设置的是真(1),那么调用该函数后,只有在图形视口内的矩形部分才被画出。

这个函数对应的头文件为graphics.h

返回值: 无

例: 下面的程序画一些矩形实例:
#include<graphics.h>
void main()
{
int driver,mode;
driver=DETECT;
mode=0;
initgrpah(&driver,&mode,"");
rectangle(80,80,220,200);
rectangle(140,99,180,300);
rectangle(6,6,88,88);
rectangle(168,72,260,360);
getch();
restorecrtmode();
}

Ⅱ 如何利用c语言程序设计绘制一个形状(圆,椭圆,矩形都可以),用线条动态地填充其内部

你的c 编译器需带 绘图函数库 才行。
c++ API 程序 可以绘图。只要得到窗口句柄,就可在该窗画图。画直线,多边形,圆,椭圆,扇形 等 都是基本函数。
下面程序在桌面窗口画线:
#include <Afxwin.h>
#include <Windows.h>
#pragma comment (lib, "User32.lib")
int main(void){
HWND hWnd = ::GetDesktopWindow();
HDC hdc = ::GetDC(hWnd);
// HDC hdc = ::GetDC(NULL);
RECT rect;
::GetWindowRect(hWnd, &rect);
::MoveToEx(hdc, 0, 0, NULL);
::LineTo(hdc, rect.right, rect.bottom);
::MoveToEx(hdc, rect.right, 0, NULL);
::LineTo(hdc, 0, rect.bottom);
::ReleaseDC(hWnd, hdc);
system("PAUSE");
return 0;
}
===
用“刷子”画填充的封闭图形 (参数是 花纹,颜色)
HBRUSH Brush[5];
case WM_PAINT:
Brush[0] = CreateHatchBrush(HS_BDIAGONAL, RGB(0, 0, 255));
Brush[1] = CreateHatchBrush(HS_CROSS, RGB(200, 0, 0));
Brush[2] = CreateHatchBrush(HS_DIAGCROSS, RGB(0, 128, 0));
Brush[3] = CreateHatchBrush(HS_FDIAGONAL, RGB(0, 128, 192));
Brush[4] = CreateHatchBrush(HS_DIAGCROSS, RGB(255, 128, 0));
----
编译器 MS VC++ 6.0.
API 程序罗嗦,这里就不列出来了。

Ⅲ 求助,C语言中画矩形的函数是哪个

用lineto函数画矩形

#include<graphics.h>
main()
{int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc");
cleardevice();
moveto(160,120);
lineto(480,120);
lineto(160,360);
lineto(160120);
getch();
closegraph();
}
图形和图像函数包含在graphics.h里面
rectangle() 画矩形函数
功能: 函数rectangle() 用当前绘图色、线型及线宽,画一个给定左上角与右下角的矩形(正方形或长方形)。
用法: 此函数调用方式为void rectangle(int left,int top,int right,int bottom);
说明: 参数left,top是左上角点坐标,right,bottom是右下角点坐标。如果有一个以上角点不在当前图形视口内,且裁剪标志clip设置的是真(1),那么调用该函数后,只有在图形视口内的矩形部分才被画出。
这个函数对应的头文件为graphics.h
返回值: 无
例: 下面的程序画一些矩形实例:
#i nclude<graphics.h>
void main()
{
int driver,mode;
driver=DETECT;
mode=0;
initgrpah(&driver,&mode,"");
rectangle(80,80,220,200);
rectangle(140,99,180,300);
rectangle(6,6,88,88);
rectangle(168,72,260,360);
getch();
restorecrtmode();
}

Ⅳ c语言编程 打印图形,菜单包括:矩形,平行四边形,输入图形的行数、列数并输入打印的字符,打印出图形

#include<stdio.h>
#define true 1
void print(char cType, int iRow, int iColumn, char cMark)
{
int i,j;

if(cType == 'A')
{
for(i = 0; i < iRow; i++)
{
for(j = 0; j < iColumn; j++)
{
printf("%c ", cMark);
}
printf("\n");
}
}
else if(cType == 'B')
{
for(i = 0; i < iRow; i++)
{
for(j = iRow; j > i; j--)
{
printf(" ");
}
for(j = 0; j < iColumn; j++)
{
printf("%c ", cMark);
}
printf("\n");
}
}
else
{
printf("Error\n");
}
}

int main()
{
int iRow;
int iColumn;
char cType;
char cMark;

while(true)
{
printf("Please select the graph you want to print \nA. Rectangle B. Parallelogram Q. Quit\n");
scanf("%c", &cType);
getchar();
if(cType != 'A' && cType != 'B' && cType != 'Q')
{
printf("\nInput illegal\n\n");
continue;
}
if(cType == 'Q')
{
return 0;
}

printf("Please input the number of rows: ");
scanf("%d", &iRow);
printf("Please input the number of columns: ");
scanf("%d", &iColumn);

printf("Please input the charactor you want to print : ");

getchar();
scanf("%c", &cMark);
getchar();

print(cType, iRow, iColumn, cMark);

}

return 0;
}

Ⅳ 怎样用c语言画一个矩形

每行起始和结束字符均是你的第3个参数 矩形第1行和最后一行中间是第3个参数,其他行根据第4个参数决定是空格或者第3个参数 程序可以这样写: ... for ( m=0;m

Ⅵ 用C语言画矩形

/* 旋转的立体椭球 */
#include <graphics.h>
#include <math.h>
#include <conio.h>
#define PI 3.14159
#define T PI/180
#define NN 36
#define DT PI/NN
#define DIST 0.8
#define R 190
static int n=1;
void trans(t,s)
float t[3];
float s[3][3];
{
s[0][0]=cos(t[1])*cos(t[2]); s[0][1]=cos(t[1])*sin(t[2]);
s[0][2]=-sin(t[1]);
s[1][0]=sin(t[0])*sin(t[1])*cos(t[2])-cos(t[0])*sin(t[2]);
s[1][1]=sin(t[0])*sin(t[1])*sin(t[2])+cos(t[0])*cos(t[2]);
s[1][2]=sin(t[0])*cos(t[1]);
s[2][0]=cos(t[0])*sin(t[1])*cos(t[2])+sin(t[0])*sin(t[2]);
s[2][1]=cos(t[0])*sin(t[0])*sin(t[2])-sin(t[0])*cos(t[2]);
s[2][2]=cos(t[0])*cos(t[1]);
}
void draw(m,da,db)
float m[3][3],da,db;
{
float f[3],f0 , x0,y0,x1,y1,x2,y2;
f[0]=R*sin(da)*cos(db); f[1]=R*sin(da)*sin(db);
f[2]=R*cos(da);
f0=f[0]*m[0][2]+f[1]*m[1][2]+f[2]*m[2][2];
if(f0<=0) n=1;
else
{
x0=300.0;y0=165.0;
x2=(m[0][0]*f[0]+m[1][0]*f[1]+m[2][0]*f[2])+x0;
y2=(m[0][1]*f[0]+m[1][1]*f[1]+m[2][1]*f[2])*DIST+y0;
if(n==1) {n=2;x1=x2;y1=y2;}
else
{
line(x1,y1,x2,y2);
x1=x2;y1=y2;
}
}
}
main()
{
float d[3],r[3][3],ta,tb;
char k;
int gdriver=VGA,gmode=VGAMED, i,p=1;
initgraph(&gdriver,&gmode,"c:\\tc");
setbkcolor(BLACK);setcolor(GREEN);
d[1]=30*T; d[2]=10*T;
do{
for(i=0;i<=361;i+=1)
{
k=kbhit();
if(k!=0)break;
setactivepage(p);
d[0]=i*T;
cleardevice();
trans(d,r);
for(tb=0.0;tb<PI;tb+=DT)
{
n=1;
for(ta=0.0;ta<2.1*PI;ta+=DT) draw(r,ta,tb);}
for(ta=0.0;ta<PI;ta+=DT)
{
n=1;
for(tb=0.0;tb<2.1*PI;tb+=DT) draw(r,ta,tb);
}
setvisualpage(p);delay(150);p=1-p;
}
}

while(k==0);
getch();closegraph();
}
这是旋转椭球的

Ⅶ 用c语言编矩形

#include<stdio.h>

intmain(){
intwidth,height,fill;
charchr;
scanf("%d%d%c%d",&height,&width,&chr,&fill);
if(height>10||height<3){
perror("Heightmustbetween3and10!");
return1;
}
if(width>10||width<5){
perror("Widthmustbetween5and10!");
return1;
}
for(inti=0;i<height;i++){
if(i==0||i==height-1||fill){
for(intj=0;j<width;j++){
printf("%c",chr);
}
}else{
printf("%c",chr);
for(intj=0;j<width-2;j++){
printf("");
}
printf("%c",chr);
}
printf(" ");
}
return0;

Ⅷ C语言打印矩形

参考代码如下:

#include<stdio.h>

intmain()
{
intm,n,i,j;
scanf("%d%d",&m,&n);
if(m>80||n>80)
return0;
for(i=1;i<=m;++i){
for(j=1;j<=n;++j)
printf("%c",i%2==1?'c':'d');
printf(" ");
}
return0;
}

Ⅸ c语言基础"如何用星号画出一个矩形"

#include <stdio.h>

#include <stdlib.h>

int main()

{

int a,b;

for(a=1;a<6;a++){

for(b=1;b<7;b++)

if (a==1||a==5||b==1||b==6)

printf("*");

else

printf(" ");

printf(" ");

}

system("pause");

return 0;

}

Ⅹ 用c语言画矩形

每行起始和结束字符均是你的第3个参数
矩形第1行和最后一行中间是第3个参数,其他行根据第4个参数决定是空格或者第3个参数
程序可以这样写:
...
for ( m=0;m<a;m++ )
{
printf("%c",c); //第1列
if ( m==0 || m==a-1 ) //第1行和最后一行
for ( n=1;n<b-1;n++ ) printf("%c",c);
else //中间的行
for ( n=1;n<b-1;n++ ) if ( d==0 ) printf(" "); else printf("%c",c); //空心或否
printf("%c\n",c); //最后1列
}
或者可以写:
for ( m=0;m<a;m++ )
{
printf("%c",c); //第1列
if ( m==0 || m==a-1 || d!=0) for ( n=1;n<b-1;n++ ) printf("%c",c);
else for ( n=1;n<b-1;n++ ) printf(" ");
printf("%c\n",c); //最后1列
}