|
|
1.1 root 1: #include <jerq.h>
2: Point spot, v, a;
3: int Topx, Topy;
4: int Botx, Boty;
5: Bitmap *ball;
6: int R;
7: long R2;
8: main(argc, argv)
9: char *argv[];
10: {
11: request(KBD);
12: initdisplay(argc, argv);
13: rectf(&display, Drect, F_XOR);
14: Topx=10*Drect.corner.x-320;
15: Topy=10*Drect.corner.y-320;
16: Botx=10*Drect.origin.x+320;
17: Boty=10*Drect.origin.y+320;
18: a.x = 0;
19: a.y = 1;
20: spot.x = (Botx+Topx)/2;
21: spot.y = Boty;
22: R=32;
23: R2=R*(long)R;
24: ball=balloc(Rect(0, 0, 2*R+1, 2*R+1));
25: rectf(ball,ball->rect,F_STORE);
26: sphere();
27: drawball();
28: v.x=5;
29: v.y=0;
30: while(kbdchar()==-1){
31: drawball();
32: v = add(v, a);
33: spot = add(spot, v);
34: if(spot.x >= Topx) {
35: spot.x = 2*Topx - spot.x;
36: v.x = -v.x;
37: }
38: else if(spot.x <= Botx) {
39: spot.x = 2*Botx - spot.x;
40: v.x = -v.x;
41: }
42: if(spot.y >= Topy) {
43: spot.y = 2*Topy - spot.y;
44: v.y = -v.y;
45: }
46: else if(spot.y <= Boty) {
47: spot.y = 2*Boty - spot.y;
48: v.y = -v.y;
49: }
50: drawball();
51: sleep(4);
52: }
53: bfree(ball);
54: exit();
55: }
56: drawball()
57: { Point p;
58: p = sub(div(spot, 10), Pt(R, R));
59: bitblt(ball, ball->rect, &display, p, F_XOR);
60: }
61: int illum[3]={5, 4, 3}; /* |illum|=7 (pretty close) */
62: int view[3]={1, 0, 0};
63: #define DITHSIZE 8
64: #define DITHMASK (DITHSIZE-1)
65: int dith[DITHSIZE][DITHSIZE]={
66: 0, 32, 8, 40, 2, 34, 10, 42,
67: 48, 16, 56, 24, 50, 18, 58, 26,
68: 12, 44, 4, 36, 14, 46, 6, 38,
69: 60, 28, 52, 20, 62, 30, 54, 22,
70: 3, 35, 11, 43, 1, 33, 9, 41,
71: 51, 19, 59, 27, 49, 17, 57, 25,
72: 15, 47, 7, 39, 13, 45, 5, 37,
73: 63, 31, 55, 23, 61, 29, 53, 21,
74: };
75: sphere(){
76: register x, y, z;
77: register d;
78: register I;
79: rectf(ball, ball->rect, F_XOR);
80: for(y= -R; y<=R; y++) /* y across, pos to right */
81: for(z= -R; z<=R; z++){ /* z pos up */
82: if(z*z+y*y>R2)
83: continue;
84: x=sqrtryz(R, y, z);
85: /* I=(illum.r)(view.r) */
86: I=muldiv(x, /* view.r */
87: (x*5+y*4+z*3), /* illum.r */
88: 87); /* a scale factor: ~RLV */
89: if(I<=0) /* unilluminated crescent */
90: continue;
91: if(I>dith[y&DITHMASK][z&DITHMASK])
92: point(ball, Pt(y+R, -z+R), F_XOR);
93: }
94: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.