Exemplo n.º 1
0
int		color_pixel(t_ray *rayon, double coef, int depth)
{
	t_data		*d;
	void		*inter;
	int			color;

	d = data_init();
	d->current = NULL;
	inter = intersection(d, rayon, &coef);
	if (inter != NULL && coef < 200000)
	{
		eb_debug_object(inter);
		d->current = inter;
		color = color_find(inter, rayon->d, coef, depth);
		return (color);
	}
	if (depth < DEPTH)
		return 0; // no stars for reflect part.
	return (rand_color(1, 1000, color_norm(0,0,0)));
}
Exemplo n.º 2
0
    virtual GClick* onFindClickHandler(GPoint loc) {
        if (fShape) {
            GPoint anchor;
            if (in_resize_corner(fShape->getRect(), loc.x(), loc.y(), &anchor)) {
                return new ResizeClick(loc, anchor);
            }
        }

        for (int i = fList.size() - 1; i >= 0; --i) {
            if (contains(fList[i]->getRect(), loc.x(), loc.y())) {
                fShape = fList[i];
                this->updateTitle();
                return new GClick(loc, "move");
            }
        }
        
        // else create a new shape
        fShape = new RectShape(rand_color());
        fList.push_back(fShape);
        this->updateTitle();
        return new GClick(loc, "create");
    }
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
	unsigned char cmap[16][3];
	int ret = EXIT_FAILURE;
	int fd;
	unsigned int seed;

	if (1 != argc) {
		(void) fprintf(stderr, USAGE, argv[0]);
		goto end;
	}

	fd = open(_PATH_CONSOLE, O_WRONLY | O_NOCTTY);
	if (-1 == fd)
		goto end;

	seed = (unsigned int) time(NULL);

	/* 0 must be very dark - the background color of pretty much everything */
	rand_color(&seed, cmap[0], 0, 0x12);

	rand_color(&seed, cmap[1], RAND_MIN, UCHAR_MAX);
	rand_color(&seed, cmap[2], RAND_MIN, UCHAR_MAX);
	rand_color(&seed, cmap[3], RAND_MIN, UCHAR_MAX);

	/* 4 must be blue - MC, ytree and others assume this and pick a matching
	 * forgeround color */
	cmap[4][0] = 0;
	cmap[4][1] = 0;
	cmap[4][2] = 0xaa;

	rand_color(&seed, cmap[5], RAND_MIN, UCHAR_MAX);

	/* 6 must be cyan, often used as for text on blue background */
	cmap[6][0] = 0;
	cmap[6][1] = 0xaa;
	cmap[6][2] = 0xaa;

	/* 7 must be light, used for text */
	cmap[7][0] = 0xaa;
	cmap[7][1] = 0xaa;
	cmap[7][2] = 0xaa;

	/* 8 must be gray, used for text */
	rand_color(&seed, cmap[8], 0x33, 0x55);

	rand_color(&seed, cmap[9], RAND_MIN, UCHAR_MAX);
	rand_color(&seed, cmap[10], RAND_MIN, UCHAR_MAX);
	rand_color(&seed, cmap[11], RAND_MIN, UCHAR_MAX);

	/* 12 must be dark - ytree uses it for highlighted text, with a light
	 * background */
	rand_color(&seed, cmap[12], 0x33, 0x55);

	rand_color(&seed, cmap[13], RAND_MIN, UCHAR_MAX);

	/* 14 must be light cyan */
	cmap[14][0] = 0x55;
	cmap[14][1] = 0xff;
	cmap[14][2] = 0xff;

	/* 15 must be white */
	cmap[15][0] = 0xef;
	cmap[15][1] = 0xef;
	cmap[15][2] = 0xef;

 	if (-1 == ioctl(fd, PIO_CMAP, (void *) cmap))
		goto close_fd;

	ret = EXIT_SUCCESS;

close_fd:
	(void) close(fd);

end:
	return ret;
}
Exemplo n.º 4
0
void input_func(gpointer data, gint source, GdkInputCondition condition) {
  int newfd, addrlen, nbytes;
  gint riga;
  struct sockaddr_in remoteaddr;
  Client *cl;
  Send s;
  char buf[128];
  char adr[32], po[32], fd[32];
  char *val[6] = {adr, po, fd, "0"};
  time_t t;

  static char no_id[] = "no server";
  static char wa_id[] = "waiting...";

/* ********************************* NUOVO CLIENT ************************** */

  if (source == serv_sock) {

    addrlen = sizeof(remoteaddr);
    newfd = accept(serv_sock, &remoteaddr, &addrlen);
    sprintf(adr, "%s", inet_ntoa(remoteaddr.sin_addr));
    sprintf(po, "%d", ntohs(remoteaddr.sin_port));
    sprintf(fd, "%d", newfd);
    t = time(NULL);
    val[4] = ctime(&t);
    val[4][strlen(val[4]) - 1] = '\0';

    cl = malloc(sizeof(Client));
    cl->fd = newfd;
    cl->callb = gdk_input_add(newfd, GDK_INPUT_READ, input_func, cl);
    cl->callb_ident = ask_for_ident_answer(&remoteaddr, cl);
    if (cl->callb_ident) {
      val[5] = wa_id;
    } else {
      val[5] = no_id;
    }
    cl->win = create_client_win(cl);
    cl->traffic = 0;
    cl->buffer[0] = '\0';
    cl->fore = rand_color();
    cl->back = rand_color();

    g_hash_table_insert(hash, GINT_TO_POINTER(newfd), cl);

    riga = gtk_clist_append(GTK_CLIST(lista), val);
    gtk_clist_set_row_data(GTK_CLIST(lista), riga, cl);    

    sprintf(cl->title, "%s:%d", inet_ntoa(remoteaddr.sin_addr), ntohs(remoteaddr.sin_port)); 
    print_on_status(cl->title);

    gtk_window_set_title(GTK_WINDOW(cl->win), cl->title);
    gtk_widget_show_all(cl->win);

    s.fd = serv_sock;
    s.buf = benvenuto;
    s.buf_len = strlen(s.buf);
    s.tit = NULL;
    s.tit_len = 0;
    send_data(NULL, cl, &s);
/* ************************************************************************* */
  } else {
/* ********************************* NUOVI DATI **************************** */
    //    cl = (Client *)g_hash_table_lookup(hash, GINT_TO_POINTER(source));
    cl = (Client *)data;
    if ((nbytes = recv(source, buf, sizeof(buf) - 1, 0)) <= 0) {
      sprintf(buf, "%s: Errore ricezione (%d) [%s]", cl->title, errno, strerror(errno));
      print_on_status(buf);
      cancella_valore(NULL, cl, NULL);
      g_hash_table_remove(hash, GINT_TO_POINTER(source));
    } else {
      if (nbytes > 0) {
        buf[nbytes] = '\0';
        check_buffer(buf, cl);
      }
    } 
/* ************************************************************************* */
  }
}
Exemplo n.º 5
0
static void
_draw_track (RendererSimTraffic *self, const lcmtypes_track_t *vd)
{
    // generate a stable non-black, non-white color from object ID
    srand(vd->id);
    GLfloat rgb[4];
    rand_color(rgb);

    glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, rgb);
    glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, rgb);

    // assumes viewing, modeling matrices, etc. set up for local frame
    // leaves these matrices as they were before invocation
    glMatrixMode (GL_MODELVIEW);
    glPushMatrix();

    glTranslated (vd->pos[0], vd->pos[1], 0);

// rotate basis to body coords of vehicle (rotate by theta about Z axis)
    glRotated (to_degrees(vd->theta), 0.0, 0.0, 1.0); // convert rad to deg

    if (self->ehandler.hovering && 
            self->selected_vehicle_id == vd->id) {
        glColor4f (1, 1, 1, 0.6);
    } else {
        glColor4fv(rgb);
    }

//    int use_model =  gtku_param_widget_get_bool(self->pw, PARAM_PRETTY);
//
//    if (use_model) {
//
//        glRotated(90, 0, 0, 1);
//        glRotated(90, 1, 0, 0);
//        
//        double s = 4.5;
//        glScalef(s,s,s);
//        
//        glTranslated(0,.115,0); // car height
//        glTranslated(0,0,.1); // front-to-back offset
//        glBegin(GL_TRIANGLES);
//        for (int i = 0; i < numChevy_vanFaces; i++) {
//            int *vs = Chevy_vanFaces[i];
//            for (int j = 0; j < 3; j++) {
//                glNormal3fv(Chevy_vanVertNorms[vs[j]]);
//                glVertex3fv(Chevy_vanVerts[vs[j]]);
//            }
//            
//        }
//        glEnd();
//    } else {

    glTranslated ( 0, 0, VEHICLE_HEIGHT / 2);

    glScalef (vd->size[0], vd->size[1], VEHICLE_HEIGHT);
    glutil_draw_cube();
//    }

    // restore matrix state
    glPopMatrix();

    if (self->ehandler.picking && self->selected_vehicle_id == vd->id) {
        glColor4f (1, 1, 1, 0.6);
        glPushMatrix ();
        glTranslatef (self->last_xy[0], self->last_xy[1], 0);
        glRotated (to_degrees(vd->theta), 0.0, 0.0, 1.0); // convert rad to deg
        glScalef (vd->size[0], vd->size[1], VEHICLE_HEIGHT);
        glutil_draw_cube_frame ();
        glPopMatrix ();
    }
}