❶ 用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语言画一个长方形,但是我的那么多FOR语句为什么只执行第一条啊.源代码如下
第一次循环之后L_B的值已经大于等于R_B了,导致后面几个for循环判断出了问题,重新初始化一下L_B
❸ C语言怎样画正方体
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include<math.h>
main()
{
int r,q,w,color;
int gdriver=DETECT,gmode; /*设置图形驱动*/
int Bresenham_Ciecle(); /*定义子函数*/
printf("please input the centre of a circle x0,y0\n");
scanf("%d,%d",&q,&w);
if(q>=320||q<=-320||w<=-250||w>=250)
{printf("please input the centre of a circle again x0,y0\n");
scanf("%d,%d",&q,&w);} /*输入圆心位置越界输出信息*/
printf("please input the numble of radius r=");
scanf("%d",&r);
if(r<=0||r>=500)
{
printf("r is error,r>0,please input the numble of r=");
scanf("%d",&r);
}/*输入半径*/
printf("please input the numble of color=");
scanf("%d",&color);
initgraph(&gdriver,&gmode,"D:\\TC");
setcolor(color);/*设置图形颜色*/
Bresenham_Ciecle(q,w,r,color); /*绘图*/
getch();
}
Bresenham_Ciecle(int q,int w,int r,int color)
{
int x,y,t,v,delta,delta1,delta2,direction;
char buffera[20];
char bufferb[20];
t=getmaxx()/2;
v=getmaxy()/2; /*选定圆心*/
sprintf(buffera, "(%d,%d)", q,w); /*打印圆心坐标*/
sprintf(bufferb, "(0,0) R=%d",r); /*打印原点坐标及半径*/
moveto(t,v+4);
outtext(bufferb); /*圆点坐标定位输出*/
q=q+t;w=v-w;
moveto(q,w);
outtext(buffera);/*原点坐标定位输出*/
line(1,v,2*t,v);
line(t,2*v,t,1);/*画坐标*/
x=q; y=r+w;
line(q, w, x, y); /*画半径*/
delta=2*(1-r);
while(y-w>=0)
{
putpixel(x,y,color); /*右下方1/4个圆*/
putpixel(2*q-x,y,color);/*右上方1/4个圆(从右下方1/4个圆对称复制)*/
putpixel(x,2*w-y,color);/*左下方1/4个圆(从右下方1/4个圆对称复制)*/
putpixel(2*q-x,2*w-y,color);/*左上方1/4个圆(从右下方1/4个圆对称复制)*/
if(delta<0)
{
delta1=2*(delta+y-w)-1;
if(delta1<=0) direction=1;
else direction=2;
}
else if(delta>0)
{
delta2=2*(delta-x+q)-1;
if(delta2<=0) direction=2;
else direction=3;
}
else
direction=2;
switch(direction)
{
case 1: x++;
delta+=2*(x-q)+1;
break;
case 2: x++;
y--;
delta+=2*(1+x-y-q+w);
break;
case 3: y--;
delta+=-2*(y-w)+1;
break;
}
}
}
❹ c语言中,line()画在bar()上,为什么会有阴影
我曾经用鼠标驱动在DOS下写过类似PAINT的软件,你可以尝试一下。
❺ 如何用c语言编程用虚线画一个长方形然后长方形内部有一个由"*"组成的三角形
最笨的方法 按照最长的那行定义每行的长度 然后其他行用空格填充
❻ C语言如何画图
framebuffer(帧缓冲)。
帧的最低数量为24(人肉眼可见)(低于24则感觉到画面不流畅)。
显卡与帧的关系:由cpu调节其数据传输速率来输出其三基色的配比。
三基色:RGB(红绿蓝)。
在没有桌面和图形文件的系统界面,可以通过C语言的编程来实现在黑色背景上画图!
用下面的代码,在需要的地方(有注释)适当修改,就能画出自己喜欢的图形!
PS:同样要编译运行后才能出效果。
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stdlib.h>
#define RGB888(r,g,b) ((r & 0xff) <<16 | (g & 0xff) << 8 | (b & 0xff))
#define RGB565(r,g,b) ((r & 0x1f) <<11 | (g & 0x3f) << 5 | (b & 0x1f))
int main()
{
int fd = open("/dev/fb0", O_RDWR);
if(fd < 0){
perror("open err. ");
exit(EXIT_FAILURE);
printf("xres: %d ", info.xres);
printf("yres: %d ", info.yres);
printf("bits_per_pixel: %d ", info.bits_per_pixel);
size_t len = info.xres*info.yres*info.bits_per_pixel >> 3;
unsigned long* addr = NULL;
addr = mmap(NULL, len, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
if(addr == (void*)-1){
perror("mmap err. ");
❼ 用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语言中line函数内的参数的含义
line(x1,y1,x2,y2);其中两个数为一个坐标,表示从(x1,y1)画线到(x2,y2)
❾ 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>
#include"graphics.h" /*画图需要的*/
void main()
{
int graphdriver=0;
int graphmode=0;
initgraph(&graphdriver,&graphmode,"");
cleardevice(); /*以上是图形驱动*/
setbkcolor(1); /*设置背景颜色*/
setcolor(RED); /*设置前景颜色*/
setfillstyle(1,3); /*设置颜色填充模式和颜色*/
bar3d(100,200,400,350,100,1); /*画立方体和填充正面*/
floodfill(450,300,WHITE);
floodfill(250,150,WHITE);
getch();
closegraph();
}
以上是一个简单的长方体,立方体是一个道理,根据你自己要求改嘛
可以参考C语言的高级编程