X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fkumppa.c;fp=hacks%2Fkumppa.c;h=0000000000000000000000000000000000000000;hb=41fae2ad67bc37e31c4d967bae81e4f3f50fa55a;hp=7e8839265c602c46ed0ffe957c49f8ed30b13c27;hpb=278c59e14c53fd412b734e699bd4f314f766f804;p=xscreensaver diff --git a/hacks/kumppa.c b/hacks/kumppa.c deleted file mode 100644 index 7e883926..00000000 --- a/hacks/kumppa.c +++ /dev/null @@ -1,482 +0,0 @@ -/* - -Copyright (C) Teemu Suutari (temisu@utu.fi) Feb 1998 - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from the X Consortium. - -*/ - - - - -/* - -*** This is contest-version. Don't look any further, code is *very* ugly. - -*/ - - -#include -#include "screenhack.h" - -#ifdef HAVE_DOUBLE_BUFFER_EXTENSION -# include "xdbe.h" -#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ - -char *progclass="Kumppa"; - -char *defaults [] ={ - ".background: black", - "*speed: 0.1", - "*delay: 0", -#ifdef HAVE_DOUBLE_BUFFER_EXTENSION - /* leave this off by default, since it slows things down. -- jwz. */ - "*useDBE: False", -#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ - 0 -}; - -XrmOptionDescRec options [] = { - {"-delay",".delay",XrmoptionSepArg,0}, - {"-speed",".speed",XrmoptionSepArg,0}, - {"-random",".random",XrmoptionIsArg,0}, -#ifdef HAVE_DOUBLE_BUFFER_EXTENSION - {"-dbuf",".dbuf",XrmoptionIsArg,0}, -#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ - {0,0,0,0} -}; - -const char colors[96]= - {0,0,255, 0,51,255, 0,102,255, 0,153,255, 0,204,255, - 0,255,255,0,255,204, 0,255,153, 0,255,102, 0,255,51, - 0,255,0, 51,255,0, 102,255,0, 153,255,0, 204,255,0, - 255,255,0, 255,204,0, 255,153,0, 255,102,0, 255,51,0, - 255,0,0, 255,0,51, 255,0,102, 255,0,153, 255,0,204, - 255,0,255, 219,0,255, 182,0,255, 146,0,255, 109,0,255, - 73,0,255, 37,0,255}; -const float cosinus[8][6]={{-0.07,0.12,-0.06,32,25,37},{0.08,-0.03,0.05,51,46,32},{0.12,0.07,-0.13,27,45,36}, - {0.05,-0.04,-0.07,36,27,39},{-0.02,-0.07,0.1,21,43,42},{-0.11,0.06,0.02,51,25,34},{0.04,-0.15,0.02,42,32,25}, - {-0.02,-0.04,-0.13,34,20,15}}; - -static float acosinus[8][3]={{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}; -static int coords[8]; -static int ocoords[8]={0,0,0,0,0,0,0,0}; - -static Display *dpy; -static Window win[2]; -static GC fgc[33]; -static GC cgc; -static int sizx,sizy; -static int midx,midy; -static unsigned long delay; -static Bool cosilines=True; -#ifdef HAVE_DOUBLE_BUFFER_EXTENSION -static Bool usedouble=False; -#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ - -static int *Xrotations; -static int *Yrotations; -static int *Xrottable; -static int *Yrottable; - -static int *rotateX; -static int *rotateY; - -static int rotsizeX,rotsizeY; -static int stateX,stateY; - -static int rx,ry; - - -int Satnum(int maxi) -{ -return (int)(maxi*frand(1)); -} - - -void palaRotate(int x,int y) -{ -int ax,ay,bx,by,cx,cy; - -ax=rotateX[x]; -ay=rotateY[y]; -bx=rotateX[x+1]+2; -by=rotateY[y+1]+2; -cx=rotateX[x]-(y-ry)+x-rx; -cy=rotateY[y]+(x-rx)+y-ry; -if (cx<0) - { - ax-=cx; - cx=0; - } -if (cy<0) - { - ay-=cy; - cy=0; - } -if (cx+bx-ax>sizx) bx=ax-cx+sizx; -if (cy+by-ay>sizy) by=ay-cy+sizy; -if (axry)?rx:ry; -for (dy=0;dy<(x+1)<<1;dy++) - for (dx=0;dx<(x+1)<<1;dx++) - { - y=(rx>ry)?ry-rx:0; - if (dy+y>=0 && dy<(ry+1)<<1 && dx<(rx+1)<<1) - if (dy+y+dx<=ry+rx && dy+y-dx<=ry-rx) - { - palaRotate((rx<<1)+1-dx,dy+y); - palaRotate(dx,(ry<<1)+1-dy-y); - } - y=(ry>rx)?rx-ry:0; - if (dy+y>=0 && dx<(ry+1)<<1 && dy<(rx+1)<<1) - if (dy+y+dx<=ry+rx && dx-dy-y>=ry-rx) - { - palaRotate(dy+y,dx); - palaRotate((rx<<1)+1-dy-y,(ry<<1)+1-dx); - } - } -stateX++; -if (stateX==rotsizeX) stateX=0; -stateY++; -if (stateY==rotsizeY) stateY=0; -} - - - -Bool make_rots(double xspeed,double yspeed) -{ -int a,b,c,f,g,j,k=0,l; -double m,om,ok; -double d,ix,iy; -int maxi; - -Bool *chks; - -rotsizeX=(int)(2/xspeed+1); -ix=(double)(midx+1)/(double)(rotsizeX); -rotsizeY=(int)(2/yspeed+1); -iy=(double)(midy+1)/(double)(rotsizeY); - -Xrotations=malloc((midx+2)*sizeof(unsigned int)); -Xrottable=malloc((rotsizeX+1)*sizeof(unsigned int)); -Yrotations=malloc((midy+2)*sizeof(unsigned int)); -Yrottable=malloc((rotsizeY+1)*sizeof(unsigned int)); -chks=malloc(((midx>midy)?midx:midy)*sizeof(Bool)); -if (!Xrottable || !Yrottable || !Xrotations || !Yrotations || !chks) return False; - - -maxi=0; -c=0; -d=0; -g=0; -for (a=0;amidx) - { - f-=g-midx; - g=midx; - } - for (b=0;bm) - { - if (j-l>=0) if (chks[j-l]) om+=ok; - else; else if (chks[l-j]) om+=ok; - if (chks[j+l]) om+=ok; - ok/=1.5; - l++; - } - if (om>=m) - { - k=j; - m=om; - } - } - } - chks[k]=False; - l=c; - while (l>=Xrottable[a]) - { - if (l!=Xrottable[a]) Xrotations[l]=Xrotations[l-1]; - if (k>Xrotations[l] || l==Xrottable[a]) - { - Xrotations[l]=k; - c++; - l=Xrottable[a]; - } - l--; - } - } - d+=ix; - if (maximidy) - { - f-=g-midy; - g=midy; - } - for (b=0;bm) - { - if (j-l>=0) if (chks[j-l]) om+=ok; - else; else if (chks[l-j]) om+=ok; - if (chks[j+l]) om+=ok; - ok/=1.5; - l++; - } - if (om>=m) - { - k=j; - m=om; - } - } - } - chks[k]=False; - l=c; - while (l>=Yrottable[a]) - { - if (l!=Yrottable[a]) Yrotations[l]=Yrotations[l-1]; - if (k>Yrotations[l] || l==Yrottable[a]) - { - Yrotations[l]=k; - c++; - l=Yrottable[a]; - } - l--; - } - - } - d+=iy; - if (maxi0.2) - { - fprintf(stderr,"Speed not in valid range! (0.0001 - 0.2), using 0.1 \n"); - rspeed=0.1; - } - -sizx=xgwa.width; -sizy=xgwa.height; -midx=sizx>>1; -midy=sizy>>1; -stateX=0; -stateY=0; - -if (!make_rots(rspeed,rspeed)) - { - fprintf(stderr,"Not enough memory for tables!\n"); - return False; - } -return True; -} - - -void screenhack(Display *d, Window w) -{ -#ifdef HAVE_DOUBLE_BUFFER_EXTENSION -XdbeSwapInfo xdswp; -#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ -int a,b,c=0,e; -float f; - -dpy=d; -win[0]=w; -if (!InitializeAll()) return; - -#ifdef HAVE_DOUBLE_BUFFER_EXTENSION -if (usedouble) - { - xdswp.swap_action=XdbeUndefined; - xdswp.swap_window=win[0]; - } - else -#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ - win[1]=win[0]; - -while (0==0) - { - if (cosilines) - { - c++; - for (a=0;a<8;a++) - { - f=0; - for (b=0;b<3;b++) - { - acosinus[a][b]+=cosinus[a][b]; - f+=cosinus[a][b+3]*sin((double)acosinus[a][b]); - } - coords[a]=(int)f; - } - for (a=0;a<4;a++) - { - XDrawLine(dpy,win[0],(mono_p)?fgc[1]:fgc[((a<<2)+c)&31],midx+ocoords[a<<1],midy+ocoords[(a<<1)+1] - ,midx+coords[a<<1],midy+coords[(a<<1)+1]); - ocoords[a<<1]=coords[a<<1]; - ocoords[(a<<1)+1]=coords[(a<<1)+1]; - } - - } else { - for (e=0;e<8;e++) - { - a=Satnum(50); - if (a>=32) a=32; - b=Satnum(32)-16+midx; - c=Satnum(32)-16+midy; - XFillRectangle(dpy,win[0],fgc[a],b,c,2,2); - } - } - XFillRectangle(dpy,win[0],fgc[32],midx-2,midy-2,4,4); - rotate(); -#ifdef HAVE_DOUBLE_BUFFER_EXTENSION - if (usedouble) XdbeSwapBuffers(dpy,&xdswp,1); -#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ - XSync(dpy, False); - screenhack_handle_events (dpy); - if (delay) usleep (delay); - } -}