以下の「sample.c」を基本に作らなければならないので、いくつかサイトをググって参考にしてみようと思ったのですが、いかんせん、このプログラムは古くさいみたいでなかなか参考になるものがなかったのでここで質問させてください。
//sample.c
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
float xi, yi;
float alphai=0.0;
Display *d;
Window w;
GC gc;
unsigned long MyColor(Display *,char *);
void move(float), setp(float,float), setangle(float), turn(float);
int koch(float);
int main(int argc, char *argv[])
{
unsigned long green, red;
XSetWindowAttributes att;
d = XOpenDisplay(NULL);
w = XCreateSimpleWindow(d, RootWindow(d, 0), 150, 150, 900, 900, 2, BlackPixel(d, 0), WhitePixel(d, 0));
red = MyColor(d, "red");
green = MyColor(d, "green");
att.override_redirect = 1;
XChangeWindowAttributes(d, w, CWOverrideRedirect, &att);
XMapWindow(d, w);
gc = XCreateGC(d, w, 0, 0);
XSetForeground(d, gc, red);
fractal(argc, argv);
XFlush(d);
getchar();
XCloseDisplay(d);
return 0;
}
unsigned long MyColor(Display *display, char *color)
{
Colormap cmap;
XColor c0, c1;
cmap = DefaultColormap(display, 0);
XAllocNamedColor(display, cmap, color, &c1, &c0);
return(c1.pixel);
}
void turn(float alpha)
{
alphai += alpha;
}
void setangle(float alpha)
{
alphai = alpha;
}
void setp(float x, float y)
{
xi = x;
yi = y;
}
void move(float l)
{
float x,y;
x = cos(alphai * 3.1415926) / 180;
y = yi + l * sin(alphai);
XDrawLine(d, w, gc, (int)xi, (int)yi, (int)x, (int)y);
xi = x; yi = y;
}
int koch(float leng){
if(leng <= 20) move(leng);
else{
leng /= 3;
koch(leng);
turn(90.0);
koch(leng);
turn(-45.0);
koch(leng);
turn(-90.0);
koch(leng);
turn(-45.0);
koch(leng);
turn(90.0);
koch(leng);
}
return 0;
}
int fractal(int argc,char *argv[])
{
int x, y, leng, i;
if(argc == 4){
x=atoi(argv[1]);
y=atoi(argv[2]);
leng=atoi(argv[3]);
} else {
x=350;y=500;leng=250;
}
setp((float)x,(float)y);
setangle(0.0);
for(i=0;i<3;i++){
koch((float)leng);
turn(-120.0);
}
return 0;
}
このプログラムを利用してコッホ雪片を描くプログラムを教えてください。
よろしくお願いします。