Пример #1
0
/* Choose a primary color mapped from 0-255 */
uint32_t pixel_primary(byte position) {
  switch (map(position, 0, 255, 0, 3)) {
  case 0: return pixel_color(255, 0,   0); break;
  case 1: return pixel_color(0,   255, 0); break;
  case 2: return pixel_color(0,   0,   255); break;
  default: {
    /* This should never be reached */
    return 0;
  }
  }
}
Пример #2
0
//Input a value 0 to 255 to get a color value.
//The colours are a transition r - g -b - back to r
uint32_t pixel_wheel(byte WheelPos, byte max)
{
  // XXX - max should be scaling factor

  if (WheelPos < 85) {
   return pixel_color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if (WheelPos < 170) {
   WheelPos -= 85;
   return pixel_color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170; 
   return pixel_color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}
Пример #3
0
/* 
 * The same pixel heat range, but with full discrete colors
 *   Blue -> Green -> Red -> Yellow -> White
 */
uint32_t pixel_heat_discreet(byte position) {
  if (position == 0) return 0;
  switch (map(position, 0, 255, 0, 4)) {
  case 0: return pixel_color(0,   0,   255); break;
  case 1: return pixel_color(0,   255, 0  ); break;
  case 2: return pixel_color(255, 0,   0  ); break;
  case 3: return pixel_color(255, 255, 0  ); break;
  case 4: return pixel_color(255, 255, 255); break;
  default : {
    /* This should never be reached */
    return 0;
  }
  }
}
Пример #4
0
Файл: fbdev.c Проект: ARO17/prog
int main()
{
    struct fb_fix_screeninfo finfo;
    struct fb_var_screeninfo vinfo;

    int fb_fd = open("/dev/fb0",O_RDWR);

    //Get variable screen information
    ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo);
    vinfo.grayscale=0;
    vinfo.bits_per_pixel=32;
    ioctl(fb_fd, FBIOPUT_VSCREENINFO, &vinfo);
    ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo);

    ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo);

    long screensize = vinfo.yres_virtual * finfo.line_length;

    uint8_t *fbp = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, (off_t)0);

    int x,y;

    for (x=0;x<vinfo.xres;x++)
	for (y=0;y<vinfo.yres;y++)
	    {
		long location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length;
		*((uint32_t*)(fbp + location)) = pixel_color(0xFF,0x00,0xAA, &vinfo);
	    }

    return 0;
}
Пример #5
0
/* 
 * A pixel heat range, "evenly" distributed
 *   Blue -> Green -> Red -> Yellow -> White
 */
uint32_t pixel_heat(byte position) {
  if (position == 0) return 0;
 
  uint16_t range = map(position, 1, 255, 0, 256 * 5);
  byte offset = range % 256;
  if (range < 256) {
    return pixel_color(0,   0,   offset);
  } else if (range < 256*2) {
    return pixel_color(0,   offset, 255 - offset);
  } else if (range < 256*3) {
    return pixel_color(offset, 255 - offset,   0  );
  } else if (range < 256*4) {
    return pixel_color(255, offset, 0  );
  } else {
    return pixel_color(255, 255, offset);
  }
}
Пример #6
0
int get_color(Display *display, int x, int y)
{
	XColor color;

	pixel_color(display, x, y, &color);

	if(color.red > 50000) return RED;
	if(color.green > 50000) return GREEN;

	return BLACK;
}
Пример #7
0
void draw_object(int size_x, int size_y, int object[size_x][size_y], int startX, int startY) {
    int pixel = 5;
    int x,y;
    for(y = startX; y < startX+size_x*pixel; y++) {
        for(x = startY; x < startY+size_y*pixel; x++) {
            if(object[(y-startX)/pixel][(x-startY)/pixel] == 0) {
                // warna langit
            }
            else if(object[(y-startX)/pixel][(x-startY)/pixel] == 1) {
                // warna hitam
                draw(x,y,pixel_color(0,0,0,&vinfo));
            }
            else if(object[(y-startX)/pixel][(x-startY)/pixel] == 2) {
                // warna biru
                draw(x,y,pixel_color(0,0,205,&vinfo));
            }
            else if(object[(y-startX)/pixel][(x-startY)/pixel] == 3) {
                // warna abu
                draw(x,y,pixel_color(128,128,128,&vinfo));
            }
            else if(object[(y-startX)/pixel][(x-startY)/pixel] == 4) {
                // warna merah
                draw(x,y,pixel_color(139,0,0,&vinfo));
            }
            else if(object[(y-startX)/pixel][(x-startY)/pixel] == 5) {
                // warna oren
                draw(x,y,pixel_color(255,140,0,&vinfo));
            }
            else if(object[(y-startX)/pixel][(x-startY)/pixel] == 6) {
                // warna kuning
                draw(x,y,pixel_color(255,255,0,&vinfo));
            }
        }
    }
}
RGBColor
RenderEngine::trace_ray(const Ray& ray, int rayDepth)
{

    Vector3D normal; // don't need until lighting and shading is added
    Vector3D local_hit_point;
    float	tmin 			= kHugeValue;
    int 	num_objects 	= world_ptr->objects.size();
    RGBColor pixel_color(0,0,0);

    ShadeRec sr;  // stores information about the closest object (so far) that has been it. Look at sphere.cpp to see what is stored.
    sr.t = 100000;   //  need to initialize to a value larger than any expected hit so that this value of t is rejected.

    // PART 1:  JUST NEED TO IMPLEMENT THE LOOP OVER OBJECTS:
    // loop over objects in the scene
    //   Remember, the objects are stored in the World in a vector object (look up vector class) and also use
    //        the variable above num_objects
    // For each object, check to see if the ray intersects it:
            // ShadeRec srObject = world_ptr->objects[j]->hit(ray); // compare with sr
            // if this is closer than anything else previously seen, update  sr
            // and set pixel color:
            //        pixel_color = world_ptr->objects[j]->color; // only used until lights and materials are implemented

    for (int i = 0; i<num_objects; i++){
        ShadeRec srObject = world_ptr->objects[i]->hit(ray);
        if (srObject.t < sr.t && srObject.hit_an_object){
                sr = srObject;
                pixel_color = world_ptr->objects[i]->color;
            }
    }
    // Now, check to see if there has been a hit.  If so, sr should contain the information
    // about the closest hit. Use the pixel_color above and sr to determine the final pixel color.
    //  (Nothing to do below here for PART 1 since we aren't implementing shading yet.
    if (sr.hit_an_object)
    {
        // PART 1:Nothing to do here

        // PART 2:
        //    Need to implement calc_shade
        pixel_color =  calc_shade(ray, sr);
        // PART 3:   need to implement reflected color here
    }
    else
    {
        // If nothing is hit, use the background color.
        pixel_color = world_ptr->background_color;
    }

    return pixel_color;
}
Пример #9
0
/* Return a color 'percent' of the way between the from and to colors */
uint32_t fadeTowards(uint32_t from, uint32_t to, byte percent) {
  int fromR = pixel_red(from);
  int fromG = pixel_green(from);
  int fromB = pixel_blue(from);
  int toR = pixel_red(to);
  int toG = pixel_green(to);
  int toB = pixel_blue(to);

  byte retR = fromR + ((toR - fromR) * percent) / 100;
  byte retG = fromG + ((toG - fromG) * percent) / 100;
  byte retB = fromB + ((toB - fromB) * percent) / 100;

  return pixel_color(retR, retG, retB);
}
Пример #10
0
void shoot(){
    cleararea(133,298,227,392);
	int xPos = calculateX(135+degree, calculateY(135+degree));
	int yPos;
	if (xPos == 750){
		yPos = calculateIfXMax(135+degree, calculateY(135+degree));
	}
	else {
		yPos = 20;
	}
    draw_line(135,390,xPos,yPos,pixel_color(200,0,0,&vinfo));
    usleep(10000);
    clearscreen();
	target(degree);
}
Пример #11
0
RGBColor
RenderEngine::calc_shade(const Ray& ray, ShadeRec& sr)
{
    RGBColor pixel_color(0,0,0);
    Material *m_ptr =  sr.material_ptr;

   // Nothing to do here for PART 1.
   //   Implement below for PART 2 (except for shadows which are done in PART 3).
   int num_lights = world_ptr->lights.size();


   for (int i=0; i<num_lights; i++){
        PointLight *light = world_ptr->lights[i];
        RGBColor ambient = m_ptr->ka * m_ptr->ca * light->intensity * light->color;
        pixel_color 	 +=  ambient;
        //NEED TO IMPLEMENT:
        // Check if in shadow (the check for shadows is done in PART 3.)
        // if not   (do this below for PART 2 without the shadow check)
        Vector3D ldir = light->location-sr.local_hit_point;
        //      calculate the light direction L
        ldir.normalize();
        Vector3D vdir =world_ptr->camera_ptr->loc -sr.local_hit_point;
        vdir.normalize();

        Vector3D ndir = sr.normal;
        ndir.normalize();

        if (!(ldir*ndir<0)) {
            RGBColor diffuse = m_ptr->kd* m_ptr->cd * light->intensity * light->color * (ldir*ndir);
            Vector3D reflect = 2*(ldir*ndir)*ndir-ldir;
            reflect.normalize();
            if (vdir*reflect>0) {
				RGBColor specular = m_ptr->cs * m_ptr->ks * light->intensity * light->color * pow((vdir*reflect),30);
				pixel_color+= specular;
			}
            pixel_color+= diffuse;
        }
    }

    return pixel_color;
}
Пример #12
0
int main() {
    struct fb_fix_screeninfo finfo;
    struct fb_var_screeninfo vinfo;

    char hidecursor[7] = {0x1b, '[', '?', '1', '6', 'c', 0};
    char restorecursor[6] = {0x1b, '[', '?', '0', 'c', 0};

    write((int)stdout, hidecursor, 6);

    int fb_fd = open("/dev/fb0",O_RDWR);

    // Get Variable Screen Information
    ioctl(fb_fd,FBIOGET_VSCREENINFO, &vinfo);
    vinfo.grayscale = 0;
    vinfo.bits_per_pixel = 32;
    ioctl(fb_fd,FBIOPUT_VSCREENINFO, &vinfo);
    ioctl(fb_fd,FBIOGET_VSCREENINFO, &vinfo);

    ioctl(fb_fd,FBIOGET_FSCREENINFO, &finfo);

    long screensize = vinfo.yres_virtual * finfo.line_length;

    uint8_t *fbp = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, (off_t)0);

    int x,y;

    for (x = 0; x < vinfo.xres; x++) {
        for (y = 0; y < vinfo.yres; y++) {
            long location = (x + vinfo.xoffset) * (vinfo.bits_per_pixel / 8) + (y + vinfo.yoffset) * finfo.line_length;
            *((uint32_t*)(fbp + location)) = pixel_color(x * (1<<vinfo.red.length) / vinfo.xres, 0x00, y * (1<<vinfo.blue.length) / vinfo.yres, &vinfo);
        }
    }

    sleep(1);

    write((int)stdout, restorecursor, 5);

    return 0;
}
Пример #13
0
void color(struct pixl *dest, struct pixl *src, int x, int y) {
    dest->r = (src->r+3.0/(WIDTH*HEIGHT));
    if (dest->r > 1) {
        dest->r = 0;
    }
    dest->g = (src->g+3.0/(WIDTH*HEIGHT));
    if (dest->g > 1) {
        dest->g = 0;
    }
    dest->b = (src->b+3.0/(WIDTH*HEIGHT));
    if (dest->b > 1) {
        dest->b = 0;
    }
#ifdef FRAMEBUFFER
    if(sleep_t)usleep(sleep_t);
    long location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8)
                  + (y+vinfo.yoffset) * finfo.line_length;

    *((uint32_t*)(fbp + location))
#ifdef USEGRADIENT
        = pixel_color(gradient(grada[0], gradb[0], gradc[0], gradd[0], dest->r)*255, gradient(grada[1], gradb[1], gradc[1], gradd[1], dest->r)*255, gradient(grada[2], gradb[2], gradc[2], gradd[2], dest->r)*255, &vinfo);
#else
        = pixel_color(dest->r*255, dest->g*255, dest->b*255, &vinfo);
Пример #14
0
void shoot(){
    clearscreen();
    draw_line(135,390,700,20,pixel_color(200,0,0,&vinfo));
    usleep(10000);
    clearscreen();
}
Пример #15
0
void target(int degree){
    cleararea(133,298,227,389);
	int yPos = calculateY(135+degree);
	if (degree >= 1 || degree <=87)
		directDraw(135,390,135+degree,yPos,pixel_color(0,200,0,&vinfo));
}
Пример #16
0
void removeshoot(){
    draw_line(135,390,calculateX(135+degree, calculateY(135+degree)),20,pixel_color(224,248,255,&vinfo));
}
Пример #17
0
uint32_t PRGB::color() {
  return pixel_color(red, green, blue);
}
Пример #18
0
uint32_t PixelUtil::getColor(uint16_t led) {
  return pixel_color(leds[led].r, leds[led].g, leds[led].b);
}
Пример #19
0
void removeshoot(){
    draw_line(135,390,700,20,pixel_color(224,248,255,&vinfo));
}
Пример #20
0
bool start_render(Globals *globales)
{
	CRandomMother 	rng(time(NULL));

	std::cout 	<< "\nRendering:\n"
				<< " - Samples per pixel:     \t" << globales->samples_per_pixel << " spp\n"
				<< " - Shadow rays per sample:\t" << globales->shadow_rays << " sps\n"
				<< " - Maximum depth:         \t" << globales->max_depth << "\n"
				<< " - Image resolution:      \t" << globales->res_x << "x" << globales->res_y << " px\n"
				<< " - Illumination strategy: \t" << globales->renderer->renderer_type()
				<< std::endl << std::endl;

	// Si se indica, mostramos las AABB
	if(globales->options & Global_opts::kglb_show_aabb)
		globales->scene->show_AABB();

    LOG() << "start_render:: Generando BVH...";

    globales->scene->create_bvh();

    LOG() << "start_render::      ... hecho.";

    // Una divisón y n multiplicaciones se hacen mas
    // rapido que n divisiones.
    double  samp_div = 1.0f / globales->samples_per_pixel;

    LOG() << "start_render:: Generando muestras...";

    // Generamos las posiciones de muestreo.
    std::vector<Vec2>   pix_samp, cam_samp;

    // Tanto para los pixels como para los rayos de la camara.
    for(int k = 0; k < globales->samples_per_pixel; ++k) {
        pix_samp.push_back(Vec2(rng.Random() - 0.5f, rng.Random() - 0.5f));
        cam_samp.push_back(Vec2(rng.Random(), rng.Random()));
    }

    LOG() << "start_render::   ... hecho.";

    LOG() << "start_render:: Entrando en el bucle principal...";

	for(int i = 0; i < globales->res_x; i++) {
		imprime_info(i+1, globales->res_x);
		for(int j = 0; j < globales->res_y; j++) {
			RGB pixel_color(0.0f);

			//i = globales->res_x/2; j = globales->res_y/2;
			//i=50; j=250;
			//std::clog << "StartRender::Shooting ray!" << endl;

            for(int k = 0; k < globales->samples_per_pixel; ++k) {
                //std::clog << "Sampling (i, j, k) = (" << i << ", " << j << ", " << k << ")" << std::endl;

                double  cam_x = (static_cast<double>(i) + pix_samp[k].x()) / static_cast<double>(globales->res_x),
                        cam_y = (static_cast<double>(j) + pix_samp[k].y()) / static_cast<double>(globales->res_y);

                Ray r = globales->camera->get_ray(cam_x, cam_y, cam_samp[k].x(), cam_samp[k].y());

                pixel_color += globales->renderer->get_color(r, globales->scene, .00001f, 1e5, 1) * samp_div;
            }

			//std::clog << "RgbPixelColor: " << pixel_color << endl;
			globales->image->set(i, j, pixel_color);

			//i=globales->res_x; j=globales->res_y;
		}
	}

	LOG() << "start_render:  ... Fin del bucle principal.";

	return true;
}