Linuxプログラミング

このエントリーをはてなブックマークに追加
10723
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include <SDL.h>
#define HH Sint32
#define GG Uint32
#define EE FF
#define DD ((0xEE))
#define CC ((DD<<8))
#define BB ((CC<<8))
#define AA ((BB<<8))

SDL_Surface *cc(SDL_Surface *sf,GG d){
SDL_Surface *c;
GG *b,p,x,y;
c = SDL_CreateRGBSurface(SDL_SWSURFACE,d,d,32,AA,BB,CC,DD);
if(c==NULL)return c;
b = (GG *)c->pixels;
p = SDL_MapRGB(c->format,0xFF,0,0);
for(x=0;x<d;x++){for(y=0;y<d;y++){
*b=p;if(4*(x*x+y*y)+d*d >=4*(x+y)*d)*b |=DD;b++;
}}
return c;
}

void dw(SDL_Surface *sc,SDL_Surface *c,GG x,GG y,GG d){
SDL_Rect p;p.x = x;p.y = y;p.w = p.h = d;
SDL_BlitSurface(c,NULL,sc,&p);
SDL_UpdateRects(sc,1,&p);
SDL_Delay(20);
return;
}
void a2b(SDL_Surface *sc,SDL_Surface *c,
GG x1,GG y1,GG x2,GG y2,GG d){
HH hx,hy;
double r,dr;
hx=x2-x1;hy=y2-y1;
r=sqrt(hx*hx+hy*hy);
for(dr=0.0;dr<r;dr+=1.0)dw(sc,c,x1+hx*dr/r,y1+hy*dr/r,d);
dw(sc,c,x2,y2,d);
return;
}
10823:01/09/20 02:12 ID:XRjyowPs

void hisanna1(SDL_Surface *sc,SDL_Surface *c,GG d){
GG tako[]={50,100,20,130,50,100,50,300,130,140,
100,280,180,140,225,275,260,140,350,140,350,140,
350,270,260,270,350,270,370,120,390,140,395,95,415,
115,460,125,550,155,460,190,540,214,450,260,550,285};
int i,j,k,l;
for(i=0;i<=44;i+=4){l=1+(k=(j=i+1)+1);
a2b(sc,c,i[tako],j[tako],k[tako],l[tako],d);
}return;
}

int main(){
SDL_Surface *sc,*c;
if(SDL_Init(SDL_INIT_VIDEO)<0)exit(1);atexit(SDL_Quit);
if((sc=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE))==NULL)
exit(1);if((c=cc(sc,20))==NULL)exit(1);
hisanna1(sc,c,20);SDL_Delay(1000);return 0;
}