home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
MM1
/
UTIL
/
mm1_colormix.lzh
/
colmix.c
Wrap
C/C++ Source or Header
|
1994-05-18
|
3KB
|
106 lines
/* colmix.c - additive color mixtures for MM/1 */
/* inspired by a program published once in "Rainbow" for Coco 3 ... */
/* released to PD by Andrzej Kotanski, May 1994 */
/* type: "cc colmix.c -t=/r0 -ix -l=/dd/lib/cgfx.l" to compile */
#include <stdio.h>
#include <errno.h>
int red = 200, green = 200, blue = 200, ncol;
char pal_data[12][3];
char *name;
FILE *coltab;
struct color {
int r, g, b;
char name[25];
};
struct color Cols[550];
char *getcolor(red, green, blue)
{
register int i;
register char *ptr;
register int val, tempval = 100000;
for ( i = 0; i < ncol; i++ ) {
val = abs(Cols[i].r - red) + abs(Cols[i].g - green)
+ abs(Cols[i].b - blue);
if ( val < tempval ) {
tempval = val;
ptr = Cols[i].name;
}
}
return ptr;
}
main()
{
pal_data[9][0] = pal_data[9][1] = pal_data[9][2] = 255;
setpal();
FColor(1, 9);
BColor(1, 8);
Clear(1);
SetDPtr(1, 260, 60); Circle(1, 90);
SetDPtr(1, 360, 60); Circle(1, 90);
SetDPtr(1, 310, 100); Circle(1, 90);
coltab = fopen("/dd/sys/rgb.txt", "r");
if ( coltab == NULL )
exit(_errmsg(errno, "cannot open '/dd/sys/rgb.txt'\n"));
ncol = 0;
while ( !feof(coltab) ) {
fscanf(coltab, "%d %d %d %s", &Cols[ncol].r, &Cols[ncol].g,
&Cols[ncol].b, Cols[ncol].name);
ncol++;
}
CurXY(1, 0, 0); printf("ADDITIVE\n\nCOLOR\n\nMIXTURES\n"); fflush(stdout);
CurXY(1, 50, 18); printf("COLOR"); fflush(stdout);
CurXY(1, 50, 20); printf("RED"); fflush(stdout);
CurXY(1, 50, 22); printf("GREEN"); fflush(stdout);
CurXY(1, 50, 24); printf("BLUE"); fflush(stdout);
CurXY(1, 56, 26); printf("enter new intensity !"); fflush(stdout);
while (1) {
SetDPtr(1, 220, 60); FColor(1, 1); FFill(1);
SetDPtr(1, 310, 40); FColor(1, 2); FFill(1);
SetDPtr(1, 380, 60); FColor(1, 3); FFill(1);
SetDPtr(1, 250, 80); FColor(1, 4); FFill(1);
SetDPtr(1, 310, 80); FColor(1, 5); FFill(1);
SetDPtr(1, 360, 80); FColor(1, 6); FFill(1);
SetDPtr(1, 310, 120); FColor(1, 7); FFill(1);
FColor(1, 9);
CurXY(1, 56, 20); ErEOLine(1); printf("%d", red); fflush(stdout);
CurXY(1, 56, 22); ErEOLine(1); printf("%d", green); fflush(stdout);
CurXY(1, 56, 24); ErEOLine(1); printf("%d", blue); fflush(stdout);
CurXY(1, 57, 18); ErEOLine(1); FColor(1, 5);
name = getcolor(red, green, blue);
printf("%s", name); fflush(stdout);
FColor(1, 9);
CurXY(1, 0, 23); ErEOLine(1);
printf("%s", name); fflush(stdout);
do {
CurXY(1, 56, 20); scanf("%d", &red);
} while ( red < 0 || red > 255);
do {
CurXY(1, 56, 22); scanf("%d", &green);
} while ( green < 0 || green > 255);
do {
CurXY(1, 56, 24); scanf("%d", &blue);
} while ( blue < 0 || blue > 255);
setpal();
}
}
setpal()
{
pal_data[1][0] = pal_data[2][0] = pal_data[4][0] = pal_data[5][0] = red;
pal_data[2][1] = pal_data[3][1] = pal_data[5][1] = pal_data[6][1] = green;
pal_data[4][2] = pal_data[5][2] = pal_data[6][2] = pal_data[7][2] = blue;
_ss_palette(1, 1, &pal_data[1][0], 9);
}