新明解だいがく生かつ辞典 -反省堂- 風の谷の13番目の大学生 -349ページ目

C言語の入門(初心者)12art.c 061220 組み込み関数

#include <stdio.h>
#include <stdlib.h>
#define MS 200
void rect(unsigned char *, int, int, int, int, int, int, int); // 四角形の作成
void circle(unsigned char *, int, int, int, int, int, int); // 円の作成
void ellipse(unsigned char *, int, int, int, int, int, int, int);//楕円の作成
void triangle(unsigned char *, int, int, int, int, int);//三角形の作成
int save(unsigned char *); // 画像の保存

main()
{
unsigned char *bmp;
bmp=(unsigned char *)malloc(MS*MS*3);


rect (bmp,0,0, MS, MS,0,0,0); //背景

triangle (bmp,60,35,255,0,80);//三角 大
triangle (bmp,40,20,255,255,255);//三角 中
triangle (bmp,20,10,255,0,40);//三角 小

rect (bmp,67,70,66,9,255,0,95);//四角 上
rect (bmp,60,59,80,10,255,0,120);//上
rect (bmp,54,44,92,14,255,0,140);//
rect (bmp,46,27,108,16,255,0,170);//
rect (bmp,36,7,128,18,255,0,210);//
rect (bmp,17,0,166,4,255,0,250);//下

circle(bmp,50,69,15,0,78,200);//大円 上
circle(bmp,36,59,15,0,78,200);//円 L上
circle(bmp,66,59,15,0,78,200);//円 R上
circle(bmp,36,41,15,0,78,200);//円 L上
circle(bmp,66,41,15,0,78,200);//円 R上
circle(bmp,50,32,15,0,78,200);//円 下

circle(bmp,46,58,9,0,195,255);//小円 L上
circle(bmp,41,50,9,0,195,255);//円 L中
circle(bmp,46,41,9,0,195,255);//円 L下
circle(bmp,56,58,9,0,195,255);//円 R上
circle(bmp,60,50,9,0,195,255);//円 R中
circle(bmp,56,41,9,0,195,255);//円 R下

circle(bmp,50,50,9,0,255,255);//円 中心

ellipse(bmp,-50,70,10,20,78,0,200);//大楕円 上
ellipse(bmp,-70,50,20,10,78,0,200);//楕円 L
ellipse(bmp,-30,50,20,10,78,0,200);//楕円 R
ellipse(bmp,-50,30,10,20,78,0,200);//楕円 下

ellipse(bmp,-50,60,5,10,195,0,255);//小楕円 上
ellipse(bmp,-60,50,10,5,195,0,255);//楕円 L
ellipse(bmp,-40,50,10,5,195,0,255);//楕円 R
ellipse(bmp,-50,40,5,10,195,0,255);//楕円 下
circle(bmp,-50,50,4,255,0,255);//円 中心

if ( save( bmp ) ) exit(1); // 画像の保存
}

void rect(unsigned char *bmp, int x0, int y0, int w, int h, int r, int g, int b)
{
int i, j;
for ( i =y0 ; i < y0+h ; i++)
{
for ( j =x0 ; j < x0+w ; j++ )
{
bmp[(i*MS+j)*3+0]=b; // (画素に青色bを代入)
bmp[(i*MS+j)*3+1]=g; // (画素に緑色gを代入)
bmp[(i*MS+j)*3+2]=r; // (画素に赤色rを代入)
}
}
}

void circle(unsigned char *bmp, int x0, int y0, int r0, int r, int g, int b)
{
int i, j, x, y;
for ( i = 0 ; i < MS ; i++)
{
y=i-MS/2; // (y座標変換)
for ( j = 0 ; j < MS ; j++ )
{
x=j-MS/2;// (x座標変換)
if ( (x-x0)*(x-x0)+(y-y0)*(y-y0)<=r0*r0 )
{
bmp[(i*MS+j)*3+0]=b;
bmp[(i*MS+j)*3+1]=g;
bmp[(i*MS+j)*3+2]=r;
}
}
}
}
void ellipse(unsigned char *bmp, int x0, int y0, int mi, int ma, int r, int g,int b)
{
int i,j;
double x,y,a,bb;
a=mi;
bb=ma;
for(i=0; i<MS; i++){
y=i-MS/2;
for(j=0; j<MS; j++){
x=j-MS/2;
if(((x-x0)*(x-x0)/(a*a))+((y-y0)*(y-y0)/(bb*bb))<=1.)
{bmp[(i*MS+j)*3+0]=b;
bmp[(i*MS+j)*3+1]=g;
bmp[(i*MS+j)*3+2]=r;
}}}}

void triangle(unsigned char *bmp,int w,int h,int r,int g,int b)
{
int i,j;
for(i=MS/2;i<MS/2+h/2;++i){for(j=MS/2;j<w/2+MS/2;++j)
{if(i<=-2*h/w*(j-MS/2)+h/2+MS/2){
bmp[(i*MS+j)*3+0]=b;
bmp[(i*MS+j)*3+1]=g;
bmp[(i*MS+j)*3+2]=r;
}
}
}

for(i=MS/2;i<MS/2+h/2;++i){for(j=-w/2+MS/2;j<MS/2;++j)
{if(i<=2*h/w*(j-MS/2)+h/2+MS/2){
bmp[(i*MS+j)*3+0]=b;
bmp[(i*MS+j)*3+1]=g;
bmp[(i*MS+j)*3+2]=r;
}
}
}

for(i=-h/2+MS/2;i<MS/2;++i){for(j=-w/2+MS/2;j<MS/2;++j)
{if(i<=2*h/w*(j-MS/2)+h/2+MS/2){
bmp[(i*MS+j)*3+0]=b;
bmp[(i*MS+j)*3+1]=g;
bmp[(i*MS+j)*3+2]=r;
}
}
}

for(i=-h/2+MS/2;i<MS/2;++i){for(j=MS/2;j<w/2+MS/2;++j)
{if(i<=-2*h/w*(j-MS/2)+h/2+MS/2){
bmp[(i*MS+j)*3+0]=b;
bmp[(i*MS+j)*3+1]=g;
bmp[(i*MS+j)*3+2]=r;
}
}
}
}


int save(unsigned char *bmp)
{
char fi[50];
FILE *fp;
unsigned short header[13] = {0x4d42, 54490, 1, 0, 0, 26, 0, 12, 0, 200, 200,1, 24};
{
printf("Input file name:");
scanf("%s",fi);
if((fp=fopen(fi,"wb"))==NULL)
{
fprintf(stderr,"Error:file open[%s].\n",fi);
return 1;
}
else
{
fwrite(header,2,13,fp);
fwrite(bmp,1,MS*MS*3,fp);
fclose(fp);
return 0;
}
}
}




楕円 書き方, 楕円 公式, 楕円 曲線, 楕円 円周, 楕円 方程式, 楕円 焦点, 楕円 面積, 楕円 関数, 楕円 形, 白い楕円, 楕円 周長, 楕円 数式, 楕円 テーブル, 楕円 製図, 楕円 接線, 楕円球, 楕円 式, 楕円 体積, 楕円体, ダイニングテーブル 楕円, ワード 楕円, 楕円 体, 楕円 鏡, 楕円 極座標, 楕円 計算式, 楕円軌道, 楕円 描き方, 楕円 計算, 楕円 作図, 楕円 円周 公式, 楕円曲線暗号, 楕円 曲率半径, java 楕円, 楕円 スピーカ, mathematica 楕円, リネージュ 楕円, 楕円 ラグ, 楕円 幾何学, 数学 楕円 , 楕円 座標, 楕円 回転, 楕円 パイプ, 写真 楕円, 楕円 幼稚園 , こたつ 楕円, 半 楕円, 楕円 定義 , スーパー楕円 , 楕円 図法, c言語 楕円