void ColorWheel::paintEvent(QPaintEvent *) { paintWheel(); paintCenterSample(); makeColors(); // clear marks for (int i = 0; i < 360; ++i) drawBorderPoint(i, false, true); QList<PaintPoint>::const_iterator it; for (it = pointList.constBegin(); it != pointList.constEnd(); ++it) drawBorderPoint((*it).angle, (*it).base); }
void setup() { // Use b.begin(1); if you have the original SparkButton, which does not have a buzzer or a plastic enclosure // to use, just add a '1' between the parentheses in the code below. b.begin(); //This is all you need to make the function controller() available to the internet //The API name and the local name don't need to be the same; just my style Particle.function("controller", controller); //This function figures out what combination color, brightness and LEDs to display makeColors(); }
int makePermVector(Display *dsply, int scrn, unsigned long **permIndex) { static int firstTime = yes; unsigned long *spadColorsToo; static unsigned long *pIndex; Colormap cmap; int num_colors; int i, ts; if (firstTime) { /* initialization */ cmap = DefaultColormap(dsply, scrn); /* what are other cmaps?? */ pIndex = (unsigned long *) saymem("makePermVector", Colorcells, sizeof(unsigned long)); /* get spadColors table */ if ((num_colors = makeColors(dsply, scrn, &cmap, &spadColorsToo, &ts)) < 0) { printf("num_colors < 0!!\n"); exit(-1); } /* initialize unused slots in permutation vector */ for (i = 0; i < spadColorsToo[0]; i++) pIndex[i] = 0; for (i = num_colors; i < Colorcells; i++) pIndex[i] = 0; /* make permutation vector */ for (i = 0; i < num_colors; i++) pIndex[spadColorsToo[i]] = i; firstTime = no; } *permIndex = pIndex; return (Colorcells); }
void loop(){ //Clicking "up" makes the LEDs brighter if(b.buttonOn(1)){ if(brightness < 1){ brightness += 0.005; changed = true; } } //Clicking "down" makes the LEDs dimmer else if (b.buttonOn(3)){ if(brightness > 0){ brightness -= 0.005; if(brightness < 0){ brightness = 0; } changed = true; } } //Clicking "right" and "left" change the color else if (b.buttonOn(2)){ if(whichColor < 255){ whichColor += 1; changed = true; } } else if (b.buttonOn(4)){ if(whichColor > 0){ whichColor -= 1; changed = true; } } //If anything's been altered by clicking or the Particle.function, update the LEDs if(changed){ delay(10); makeColors(); changed = false; } }
void MainWindow::colorCards() { QVector<QPair<QColor, int> > *colors = makeColors(); //Map colors to buttons int color; QVector<QPair<QPushButton*, QColor> > *buttonColors = new QVector< QPair<QPushButton*, QColor> >(); QVectorIterator<QPushButton*> it(*buttons); while(it.hasNext()) { color = rand()%numberOfColors; while(colors->at(color).second == 0) { color = rand()%numberOfColors; } buttonColors->push_back(QPair<QPushButton*, QColor>(it.next(), colors->at(color).first)); colors->replace(color, QPair<QColor, int>(colors->at(color).first, colors->at(color).second-1));; } for(int i=0; i<buttonColors->size(); ++i) { QString style_sheet_btn =" QPushButton:checked {background-color:" + buttonColors->at(i).second.name() + ";border-style:solid;}"; buttonColors->at(i).first->setStyleSheet(style_sheet_btn); } //Make pairs of the buttons for(int i=0; i<buttonColors->size(); ++i) { for(int j=0; j<buttonColors->size(); ++j) { if(i!=j) { if(buttonColors->at(i).second == buttonColors->at(j).second) { pairs->push_back(QPair<QPushButton*, QPushButton*> (buttonColors->at(i).first, buttonColors->at(j).first)); } } } } }
static void ingItColors_and_fonts(void) { char property[256]; char *prop = &property[0]; char *str_type[50]; XrmValue value; Colormap cmap; int ts; /** get the color map for the display **/ /* fprintf(stderr,"initx:ingItColors_and_fonts:entered\n");*/ /* fprintf(stderr,"initx:ingItColors_and_fonts:DefaultColorMap\n");*/ cmap = DefaultColormap(gXDisplay, gXScreenNumber); /* fprintf(stderr,"initx:ingItColors_and_fonts:init_group_stack\n");*/ init_group_stack(); /** then start getting the fonts **/ /* fprintf(stderr,"initx:ingItColors_and_fonts:mergeDatabases\n");*/ mergeDatabases(); /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.RmFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, RmFontDefault); } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 1\n");*/ load_font(&gRmFont, prop); /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 2\n");*/ load_font(&gInputFont, prop); /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 2\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.TtFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, TtFontDefault); } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 3\n");*/ load_font(&gTtFont, prop); /* fprintf(stderr,"initx:ingItColors_and_fonts:is_it_850\n");*/ gTtFontIs850=is_it_850(gTtFont); /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 5\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.ActiveFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, ActiveFontDefault); } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 4\n");*/ load_font(&gActiveFont, prop); /* maintain backwards compatibility */ /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 6\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.FriCASFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { if (XrmGetResource(rDB, "FriCAS.hyperdoc.SpadFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, fricas_font_default); } } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 5\n");*/ load_font(&fricas_font, prop); /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 7\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.EmphasizeFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, EmphasizeFontDefault); } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 6\n");*/ load_font(&gEmFont, prop); /* fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 8\n");*/ if (XrmGetResource(rDB, "FriCAS.hyperdoc.BoldFont", "FriCAS.hyperdoc.Font", str_type, &value) == True) { (void) strncpy(prop, value.addr, (int) value.size); } else { (void) strcpy(prop, BoldFontDefault); } /* fprintf(stderr,"initx:ingItColors_and_fonts:load_font 7\n");*/ load_font(&gBfFont, prop); /* * If we are on a monochrome screen, then we ignore user preferences, and * set the foreground and background as I wish */ /* fprintf(stderr,"initx:ingItColors_and_fonts:DisplayPlanes\n");*/ if (DisplayPlanes(gXDisplay, gXScreenNumber) == 1) { gActiveColor = fricas_color = gControlBackgroundColor = gInputBackgroundColor = gBfColor = gEmColor = gRmColor = gSlColor = gTtColor = BlackPixel(gXDisplay, gXScreenNumber); gBackgroundColor = gInputForegroundColor = gControlForegroundColor = WhitePixel(gXDisplay, gXScreenNumber); } else { /* * If I have gotten here, then we must be on a color screen, so see * what the user likes, and set it up */ /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 1\n");*/ gRmColor = get_color("RmColor", "Foreground", BlackPixel(gXDisplay, gXScreenNumber), &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 2\n");*/ gBackgroundColor = get_color("Background", "Background", WhitePixel(gXDisplay, gXScreenNumber), &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 3\n");*/ gActiveColor = get_color("ActiveColor", "Foreground", BlackPixel(gXDisplay, gXScreenNumber), &cmap); /* * for next two, I want name arg = class arg, ie do not want * Background and Foreground. */ /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 4\n");*/ gControlBackgroundColor = get_color("ControlBackground", "ControlBackground", WhitePixel(gXDisplay, gXScreenNumber), &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 5\n");*/ gControlForegroundColor = get_color("ControlForeground", "ControlForeground", BlackPixel(gXDisplay, gXScreenNumber), &cmap); /* maintain backwards compatibility */ /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 6\n");*/ fricas_color = get_color("FriCASColor", "Foreground", 0, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 7\n");*/ if (fricas_color == 0) fricas_color = get_color("SpadColor", "Foreground", BlackPixel(gXDisplay, gXScreenNumber), &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 8\n");*/ gInputBackgroundColor = get_color("InputBackground", "Foreground", gRmColor, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 9\n");*/ gInputForegroundColor = get_color("InputForeground", "Background", gBackgroundColor, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 10\n");*/ gEmColor = get_color("EmphasizeColor", "Foreground", gRmColor, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 11\n");*/ gTtColor = get_color("TtColor", "Foreground", gRmColor, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 12\n");*/ gSlColor = get_color("EmphasizeColor", "Foreground", gRmColor, &cmap); /* fprintf(stderr,"initx:ingItColors_and_fonts:get_color 13\n");*/ gBfColor = get_color("BoldColor", "Foreground", gRmColor, &cmap); } /* fprintf(stderr,"initx:ingItColors_and_fonts:makeColors\n");*/ makeColors(gXDisplay, gXScreenNumber, &cmap, &spadColors, &ts); /* * Now set the current color and font, so I never have to do it again */ gTopOfGroupStack->cur_color = gRmColor; gTopOfGroupStack->cur_font = gRmFont; /* fprintf(stderr,"initx:ingItColors_and_fonts:exited\n");*/ }
int XInitSpadFill(Display *dsply, int scr, Colormap * mapOfColors, int * hues, int *solid, int * dithered, int * shades) { int maxDither; XColor BlackColor, WhiteColor; XColor retColor; int maxSolid; SpadFillInit = 1; /* * First thing I should do is get the GC's */ stippleGC = XCreateGC(dsply, RootWindow(dsply, scr), 0, NULL); solidGC = XCreateGC(dsply, RootWindow(dsply, scr), 0, NULL); XSetArcMode(dsply, solidGC, ArcPieSlice); XSetArcMode(dsply, stippleGC, ArcPieSlice); cmap = DefaultColormap(dsply, scr); *mapOfColors = cmap; XAllocNamedColor(dsply, cmap, "Black", &BlackColor, &retColor); XAllocNamedColor(dsply, cmap, "White", &WhiteColor, &retColor); black = BlackColor.pixel; white = WhiteColor.pixel; /* * Now I check to see if I am on a monochrome display. If so then I * simply set totalHues to be one, and total Shades to be 2. I also have * to allocate balck and white colors. This I put into the first two * memory locations of spadcolors. * * was if(DisplayPlanes(dsply, scr) < 2) changed temporarily to < 8 * because of problems with screens with 4 planes . Now if we don't have * 8 planes to play with we switch to monochrome */ if (DisplayPlanes(dsply, scr) < 8) { *dithered = totalDithered = maxGreyShade = XInitShades(dsply, scr); maxDither = *dithered - 1; spadColors = (unsigned long *) malloc(2 * sizeof(unsigned long)); spadColors[0] = BlackColor.pixel; spadColors[1] = WhiteColor.pixel; *hues = totalHues = 1; *solid = totalSolid = 2; *shades = totalColors = totalShades = totalDithered; return (totalColors); } /* * Now I have to get all the spad colors as every good spad program * should Now I should initialize the dithering routines */ *dithered = totalDithered = XInitDither(dsply, scr, stippleGC, black, white); maxDither = *dithered - 1; if ((maxSolid = makeColors(dsply, scr, &cmap, &spadColors, &totalSolid)) > 0) { *solid = totalSolid + 2; *hues = totalHues = maxSolid / totalSolid; *shades = totalShades = (totalSolid + 1) * (totalDithered - 1) + 1; totalColors = totalHues * totalShades; return (totalColors); } else { /* * makeColors managed to fail -- switch to mono */ *dithered = totalDithered = maxGreyShade = XInitShades(dsply, scr); maxDither = *dithered - 1; spadColors = (unsigned long *) malloc(2 * sizeof(unsigned long)); spadColors[0] = BlackColor.pixel; spadColors[1] = WhiteColor.pixel; *hues = totalHues = 1; *solid = totalSolid = 2; *shades = totalColors = totalShades = totalDithered; return (totalColors); } }
/******************************************************************* KF 6/14/90 INPUT: display, screen, filename to read the pixmap data from, OUTPUT: ximage structure xi, width and height of pixmap PURPOSE: read_pixmap_file reads an Ximage data structure from the input file. This routine can handle pixmaps of both XYPixmap and ZPixmap. If a pixmap has ZPixmap format, then the image data, read in as spadColor index, is converted to the pixel value using spadColor. Note that reading in Z format takes less space and time too. ********************************************************************/ int read_pixmap_file(Display *display, int screen, char *filename, XImage **xi, int *width, int *height) { FILE *file; int wi, h, num, num_colors, read_this_time, offset; Colormap cmap; int ts; unsigned long *spadColors; /* colormap is necessary to call makeColors */ cmap = DefaultColormap(display, screen); if ((num_colors = makeColors(display, screen, &cmap, &spadColors, &ts)) < 0) { return(-1); } file = zzopen(filename, "r"); if (file == NULL) { printf("couldn't open %s\n", filename); return BitmapOpenFailed; } #define GETW(f) ntohl(getw(f)) *width = wi = GETW(file); *height = h = GETW(file); (*xi) = XCreateImage(display, DefaultVisual(display, screen), DisplayPlanes(display, screen), ZPixmap, 0, NULL, wi, h, 16, 0); /* handles both XY & Z */ if ((*xi) == NULL) { fprintf(stderr, "Unable to create image\n"); return(-1); } (*xi)->width = wi; (*xi)->height = h; (*xi)->xoffset = GETW(file); (*xi)->format = GETW(file); (*xi)->byte_order = GETW(file); (*xi)->bitmap_unit = GETW(file); (*xi)->bitmap_bit_order = GETW(file); (*xi)->bitmap_pad = GETW(file); (*xi)->depth = GETW(file); (*xi)->bytes_per_line = GETW(file); (*xi)->bits_per_pixel = GETW(file); (*xi)->red_mask = GETW(file); (*xi)->green_mask = GETW(file); (*xi)->blue_mask = GETW(file); /* program will bomb if XYPixmap is not allocated enough space */ if ((*xi)->format == XYPixmap) { /* printf("picture is in XYPixmap format.\n"); */ num = (*xi)->bytes_per_line * h * (*xi)->depth; } else /* ZPixmap */ num = (*xi)->bytes_per_line * h; (*xi)->data = (void*)halloc(num, "Ximage data"); offset = 0; while (offset < num) { read_this_time = fread(((*xi)->data + offset), 1, num - offset, file); offset = offset + read_this_time; } fclose(file); /* * pixmap data in ZPixmap format are spadColor indices; pixmap data in * XYPixmap format are pixel values */ if ((*xi)->format == ZPixmap) { int ii, jj; for (ii = 0; ii < wi; ii++) for (jj = 0; jj < h; jj++) { XPutPixel(*xi, ii, jj, spadColors[(int) XGetPixel(*xi, ii, jj)]); } } return 0; }