3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <cybergraphx/cybergraphics.h>
6 #include <proto/exec.h>
8 #include <proto/graphics.h>
9 #include <proto/cybergraphics.h>
10 #include <proto/intuition.h>
19 /***********************************************************************************/
21 struct IntuitionBase
*IntuitionBase
;
22 struct GfxBase
*GfxBase
;
23 struct Library
*CyberGfxBase
;
27 ULONG cgfx_coltab
[256];
28 UBYTE remaptable
[256];
31 WORD winx
= -1, winy
= -1;
32 BOOL forcescreen
, forcewindow
;
33 BOOL mustremap
, truecolor
, remapped
, wbscreen
= TRUE
;
35 static void cleanup(char *msg
);
37 /***********************************************************************************/
52 #define W 256 // Full width
53 #define hW 128 // Half width
54 #define qW 64 // Quarter width
55 #define eW 32 // 1/8 width
56 #define H 256 // Full height
57 #define hH 128 // Half height
58 #define qH 64 // Quarter height
59 #define eH 32 // 1/8 height
61 static UBYTE chunkybuffer
[W
* H
];
62 static UBYTE chunkybuffer_remapped
[W
* H
];
64 /***********************************************************************************/
66 static void refresh(void)
70 WriteLUTPixelArray(chunkybuffer
,
85 UBYTE
*src
= chunkybuffer
;
86 UBYTE
*dest
= chunkybuffer_remapped
;
88 for(i
= 0; i
< W
* H
; i
++)
90 *dest
++ = remaptable
[*src
++];
95 win
->BorderLeft
+ W
- 1,
96 win
->BorderTop
+ H
- 1,
97 chunkybuffer_remapped
,
103 WriteChunkyPixels(rp
,
106 win
->BorderLeft
+ W
- 1,
107 win
->BorderTop
+ H
- 1,
113 /***********************************************************************************/
115 #define SQR(x) ((x) * (x))
116 #define pi 3.14159265
119 static void Calc_Ball(WORD hohe
, WORD breite
, APTR po
)
124 for(y
= 0; y
< hohe
; y
++)
126 for(x
= 0; x
< breite
; x
++)
128 e
= sqrt(SQR(x
-(breite
+1)/2) + 1.5*SQR(y
-(breite
+1)/2));
130 col
= 128 + 128*cos(radius
*e
*(1+(1.2*W
-e
)/(W
))*deg
);
132 if (col
> 255) col
=255;
133 ((UBYTE
*)po
)[breite
* y
+ x
] = col
;
140 /***********************************************************************************/
142 static void Do_Ball(UWORD x
, UWORD y
, WORD h
, WORD b
, APTR po
)
145 ULONG destoffset
= 0; // (y * W) + x;
148 UWORD dx
= 0, dy
= 0;
151 UWORD sx
= x
+W
, sy
= y
+H
;
156 #define src ((UBYTE *)po)
158 for(loopy
= y
; loopy
< sy
; loopy
++)
161 for(loopx
= x
; loopx
< sx
; loopx
++)
163 destoffset
= (W
*dy
) + dx
;
164 srcoffset
= (bW
*loopy
) + loopx
;
166 col
= src
[srcoffset
];
167 col2
= chunkybuffer
[destoffset
];
169 //if(col2>col) col = col2; // eggplant
171 //col += col2; // metaball
173 col
= (col
+col2
)>>1; // Glassy
175 //col+=ctr; // colorcycle (add ctr++ below);
177 //col = col & 0xff; // Xor-effect
178 //if (col > 255) col = 255; // metaball max color
179 chunkybuffer
[destoffset
] = col
;
189 /***********************************************************************************/
191 static void initpalette(void)
195 for(palindex
= 0; palindex
< 128; palindex
++)
199 ULONG bl
= palindex
*2;
200 cgfx_coltab
[palindex
] = (re
<< 16) + (gr
<< 8) + bl
;
205 cgfx_coltab
[palindex
+128] = (re
<< 16) + (gr
<< 8) + bl
;
212 for(i
= 0; i
< 256; i
++)
214 ULONG r
= (cgfx_coltab
[i
] >> 16) & 0xFF;
215 ULONG g
= (cgfx_coltab
[i
] >> 8) & 0xFF;
216 ULONG b
= cgfx_coltab
[i
] & 0xFF;
220 ULONG red
= r
* 0x01010101;
221 ULONG green
= g
* 0x01010101;
222 ULONG blue
= b
* 0x01010101;
224 remaptable
[i
] = ObtainBestPen(scr
->ViewPort
.ColorMap
,
228 OBP_Precision
, PRECISION_IMAGE
,
229 OBP_FailIfBad
, FALSE
,
236 ULONG red
= r
* 0x01010101;
237 ULONG green
= g
* 0x01010101;
238 ULONG blue
= b
* 0x01010101;
240 SetRGB32(&scr
->ViewPort
, i
, red
, green
, blue
);
246 /***********************************************************************************/
248 static void initstuff(void)
250 for(i
= 1; i
<= balls
; i
++)
252 ball
[i
- 1].dia
= 2*W
;
253 ball
[i
- 1].rand
= (BYTE
)(20.0+20.0*sin(i
*pi
/balls
*13));
254 ball
[i
- 1].p
= malloc(SQR(ball
[i
- 1].dia
));
255 if (ball
[i
].p
) cleanup("out of memory!");
256 Calc_Ball(ball
[i
-1].dia
, ball
[i
-1].dia
, ball
[i
-1].p
);
260 /***********************************************************************************/
262 static void ticker(void)
264 // Movement parameters
265 // The chain consists of four sin/cos waves per axis
266 // *dis* represents distance between blobs in the chain
267 // *add* represents the movement speed of the chain/waves
269 // Implemented by using local floats to make it easier
270 // to later implement CLI parameter values.
272 float xdis1
= 394 /balls
;
273 float xdis2
= -363 /balls
;
274 float xdis3
= 336 /balls
;
275 float xdis4
= -344 /balls
;
277 float ydis1
= 354 /balls
;
278 float ydis2
= -324 /balls
;
279 float ydis3
= 373 /balls
;
280 float ydis4
= 382 /balls
;
282 float xadd1
= 2.10 *speed
;
283 float xadd2
= -1.25 *speed
;
284 float xadd3
= -0.55 *speed
;
285 float xadd4
= 0.93 *speed
;
287 float yadd1
= 1.55 *speed
;
288 float yadd2
= 0.63 *speed
;
289 float yadd3
= -0.23 *speed
;
290 float yadd4
= -0.94 *speed
;
297 float xnew
= 0, ynew
= 0;
299 memset(chunkybuffer
, 0, sizeof(chunkybuffer
));
301 // Precalculating position of each wave
312 for(i
= 0; i
< balls
; i
++)
315 xnew
= hW
+ // - ball[i].dia/2 +
316 eW
* sin ((xdis1
* i
+ xpos1
) * deg
)+
317 eW
* sin ((xdis2
* i
+ xpos2
) * deg
)+
318 eW
* sin ((xdis3
* i
+ xpos3
) * deg
)+
319 eW
* sin ((xdis4
* i
+ xpos4
) * deg
);
321 ynew
= hW
+ // - ball[i].dia/2 +
322 eH
* cos ((ydis1
* i
+ ypos1
) * deg
)+
323 eH
* cos ((ydis2
* i
+ ypos2
) * deg
)+
324 eH
* cos ((ydis3
* i
+ ypos3
) * deg
)+
325 eH
* cos ((ydis4
* i
+ ypos4
) * deg
);
327 Do_Ball((WORD
)xnew
,(WORD
)ynew
,
328 ball
[i
].dia
, ball
[i
].dia
, ball
[i
].p
);
334 /***********************************************************************************/
336 static void cleanup(char *msg
)
341 printf("rubberstrings: %s\n",msg
);
344 if (win
) CloseWindow(win
);
350 for(i
= 0; i
< 256; i
++)
352 ReleasePen(scr
->ViewPort
.ColorMap
, remaptable
[i
]);
359 UnlockPubScreen(0, scr
);
364 if (CyberGfxBase
) CloseLibrary(CyberGfxBase
);
365 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
366 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
371 /***********************************************************************************/
373 #define ARG_TEMPLATE "WINPOSX=X/N/K,WINPOSY=Y/N/K,FORCESCREEN=SCR/S,FORCEWINDOW=WIN/S"
380 static IPTR args
[NUM_ARGS
];
382 static void getarguments(void)
384 struct RDArgs
*myargs
;
386 if ((myargs
= ReadArgs(ARG_TEMPLATE
, args
, NULL
)))
390 else if (args
[ARG_WIN
])
393 if (args
[ARG_X
]) winx
= *(IPTR
*)args
[ARG_X
];
394 if (args
[ARG_Y
]) winy
= *(IPTR
*)args
[ARG_Y
];
400 /***********************************************************************************/
402 static void openlibs(void)
404 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39)))
406 cleanup("Can't open intuition.library V39!");
409 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39)))
411 cleanup("Can't open graphics.library V39!");
414 if (!(CyberGfxBase
= OpenLibrary("cybergraphics.library",0)))
416 cleanup("Can't open cybergraphics.library!");
421 /***********************************************************************************/
423 static void getvisual(void)
430 scr
= OpenScreenTags(NULL
, SA_Width
, W
,
434 if (!scr
) cleanup("Failed to open specified screen!");
436 else if (!(scr
= LockPubScreen(NULL
)))
438 cleanup("Failed to lock pub screen (workbench)!");
441 truecolor
= (GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
) >= 15) ? TRUE
: FALSE
;
443 if ((!truecolor
) && (wbscreen
))
447 /***********************************************************************************/
449 static void makewin(void)
451 struct TagItem winonwbtags
[] =
453 {WA_DragBar
, TRUE
},
454 {WA_DepthGadget
, TRUE
},
455 {WA_CloseGadget
, TRUE
},
456 {WA_Title
, (IPTR
)"Rubberstrings 1.0 - by Orgin" },
460 struct TagItem winonscrtags
[] =
462 {WA_Borderless
, TRUE
},
466 if (winx
== -1) winx
= (scr
->Width
- W
- scr
->WBorLeft
- scr
->WBorRight
) / 2;
467 if (winy
== -1) winy
= (scr
->Height
- H
- scr
->WBorTop
- scr
->WBorTop
- scr
->Font
->ta_YSize
- 1) / 2;
469 win
= OpenWindowTags(NULL
, WA_CustomScreen
, (IPTR
)scr
,
474 WA_AutoAdjust
, TRUE
,
476 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
478 TAG_MORE
, wbscreen
? winonwbtags
: winonscrtags
);
480 if (!win
) cleanup("Can't open window");
485 /***********************************************************************************/
488 #define KC_RIGHT 0x4E
493 /***********************************************************************************/
495 static void getevents(void)
497 struct IntuiMessage
*msg
;
499 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
503 case IDCMP_CLOSEWINDOW
:
509 WORD code
= msg
->Code
& ~IECODE_UP_PREFIX
;
511 Keys
[code
] = (code
== msg
->Code
) ? 1 : 0;
517 ReplyMsg((struct Message
*)msg
);
522 /***********************************************************************************/
524 static void action(void)
529 while (!Keys
[KC_ESC
])
540 /***********************************************************************************/
554 /***********************************************************************************/