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

c语言编程序画矩形

发布时间: 2022-06-03 21:40:08

‘壹’ 求助,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语言程序 矩形画图:

我不会,但我是用VC++6.0的,你可以去下载一个库(画图的),然后安装,添加头文件#include<grapgics.h>,就可以用头文件的函数rectangle(int sx,int sy,int ex,int ey),画图了,库的名字是EasyX,

‘叁’ 用C语言编写程序 在屏幕上画一个矩形

#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <graphics.h>

void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle);

int main()
{
int GraphDriver;
int GraphMode;
float arg = 45, argd;
int a;
int direction;
int r;
int n = 4;
FILE *fp;
char szfilename[255] = {"c:\\cube.txt"};
GraphDriver = DETECT;
printf("Input size of cube: ");
scanf("%d", &r);
printf("Input direction(0-1): ");
scanf("%d", &direction);
if (direction == 0)
{
argd = 45;
}
else
{
argd = -45;
}

initgraph(&GraphDriver, &GraphMode, "");
polygon(n, 300, 200, r, 12, arg, 0);
while(1)
{
while(kbhit())
{
a = getch();
if (a == 27)
{
if ((fp = fopen(szfilename, "wt")) != NULL)
{
fprintf(fp, "%d\n%d\n", r, direction);
fclose(fp);
}
closegraph();
return 0;
}
if (a == 0)
{
getch();
polygon(n, 300, 200, r, 0, arg, 0);
arg += argd;
polygon(n, 300, 200, r, 12, arg, 0);
}
else
{
polygon(n, 300, 200, r, 0, arg, 0);
arg += argd;
polygon(n, 300, 200, r, 12, arg, 0);
}
}
}
}

void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle)
{
double pi;
int i;
float x1[10], y1[10];
setcolor(color);
pi = atan(1) * 4;
arg = atan(1) / 45 * arg;
x1[1] = x + r * cos(2 * pi / n + arg);
y1[1] = y + r * sin(2 * pi / n + arg);
moveto(x1[1], y1[1]);
for (i = 2; i <= n; i++)
{
x1[i] = x + r * cos(2 * pi * i / n + arg);
y1[i] = y + r * sin(2 * pi * i / n + arg);
lineto(x1[i], y1[i]);
}
lineto(x1[1], y1[1]);
if (fillstyle != 0)
{
setfillstyle(SOLID_FILL, color);
floodfill(x, y, color);
}
}

‘肆’ 如何利用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语言基础"如何用星号画出一个矩形"

#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列
}

‘柒’ 用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语言画一个矩形

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

‘玖’ 如何用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();
}