예제 #1
0
void resolve() {
    shifter(cx);
    // Shift the palette for this iteration.
    for(int y = 0; y < imageHeight; ++y) {
    // In the imaginary axis...
        double c_im = MaxIm - (y * Im_factor);
        // The current imaginary is the max value minus the scaled vertical iterator.
        for(int x=0; x<imageWidth; ++x) {
        // In the real axis...
            double c_re = MinRe + (x * Re_factor);
            // The current real is the min value plus the scaled horizontal iterator.
            c.real = c_re;
            c.imag = c_im;
            // Change the real and imaginary components of the global complex variable c.
            int iters = fractal();
            // The returned value is the escape iterations for the current coordinate
            col = sf::Color(iters * 4, iters * 4, iters * 4, 255);
            // Create a color based on the current scape iterations.
            imagen.setPixel(x, y, col);
            // Set the image pixel at this current location to that color.
        }
    }
    mandtex.update(imagen);
    // Update the texture.
    mandelb.setTexture(mandtex);
    // Set the texture to the window.
}
예제 #2
0
 void update_image(int x, int y)
 {
   map_x = x;
   map_y = y;
   details::generate_noise(image, (float)map_x * Tile::WIDTH, (float)map_y * Tile::HEIGHT);
   texture.update(image);
 }
예제 #3
0
파일: Main.cpp 프로젝트: SGBon/emu-chip8
void updateGraphics(sgb::Chip8 &c8) {
	//window.clear();
	for (int i = 0; i < 64; i++) {
		for (int j = 0; j < 32; j++) {
			int currpos = i + j*64;
			int on = c8.gfx[currpos];
			if (on == 1)
				back.setPixel(i, j, sf::Color::Green);
			else
				back.setPixel(i, j, sf::Color::Black);
		}
	}
	c8.drawFlag = false;
	backtext.update(back);
	window.draw(backshape);
	window.display();
}
예제 #4
0
void updateViewTexture(sf::Uint8* pixels, sf::Texture& texture, const sf::Rect<T> view, const std::vector<sf::Color>& palette) {
  const auto textureSize = texture.getSize();
  sf::Vector2u ti;
  sf::Vector2<T> c(view.left, view.top);
  const sf::Vector2<T> cInc(view.width / textureSize.x, view.height / textureSize.y);
  unsigned int i = 0;
  for(ti.y = 0, c.y = view.top; ti.y < textureSize.y; ++ti.y, c.y += cInc.y) {
    for(ti.x = 0, c.x = view.left; ti.x < textureSize.x; ++ti.x, c.x += cInc.x, i += 4) {
      const auto count = mandelbrot(c, 255);
      const sf::Color color = palette.at(count);
      pixels[i] = color.r;
      pixels[i+1] = color.g;
      pixels[i+2] = color.b;
      pixels[i+3] = color.a;
    }
  }
  texture.update(pixels);
}
예제 #5
0
	void Texture::fillTexture(sf::Texture& texture, int width, int height, sf::Color color)
	{
		texture.create(width, height);

		int length = width * height * 4;
		sf::Uint8* buffer = new sf::Uint8[length];

		for(int i = 0; i < length; i += 4)
		{
			buffer[i] = color.r;
			buffer[i + 1] = color.g;
			buffer[i + 2] = color.b;
			buffer[i + 3] = color.a;
		}

		texture.update(buffer);

		delete buffer;
	}
예제 #6
0
파일: media.cpp 프로젝트: chris-vg/attract
void FeVideoImp::preload()
{
	{
		sf::Lock l( image_swap_mutex );

		if (rgba_buffer[0])
			av_freep(&rgba_buffer[0]);

		int ret = av_image_alloc(rgba_buffer, rgba_linesize,
				disptex_width, disptex_height,
				AV_PIX_FMT_RGBA, 1);
		if (ret < 0)
		{
			std::cerr << "Error allocating image during preload" << std::endl;
			return;
		}
	}

	bool keep_going = true;
	while ( keep_going )
	{
		AVPacket *packet = pop_packet();
		if ( packet == NULL )
		{
			if ( !m_parent->end_of_file() )
				m_parent->read_packet();
			else
				keep_going = false;
		}
		else
		{
			//
			// decompress packet and put it in our frame queue
			//
			int got_frame = 0;
#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 55, 45, 0 ))
			AVFrame *raw_frame = av_frame_alloc();
			codec_ctx->refcounted_frames = 1;
#else
			AVFrame *raw_frame = avcodec_alloc_frame();
#endif

			int len = avcodec_decode_video2( codec_ctx, raw_frame,
				&got_frame, packet );

			if ( len < 0 )
			{
				std::cerr << "Error decoding video" << std::endl;
				keep_going=false;
			}

			if ( got_frame )
			{
				if ( (codec_ctx->width & 0x7) || (codec_ctx->height & 0x7) )
					sws_flags |= SWS_ACCURATE_RND;

				sws_ctx = sws_getCachedContext( NULL,
					codec_ctx->width, codec_ctx->height, codec_ctx->pix_fmt,
					disptex_width, disptex_height, AV_PIX_FMT_RGBA,
					sws_flags, NULL, NULL, NULL );

				if ( !sws_ctx )
				{
					std::cerr << "Error allocating SwsContext during preload" << std::endl;
					free_frame( raw_frame );
					free_packet( packet );
					return;
				}

				sf::Lock l( image_swap_mutex );
				sws_scale( sws_ctx, raw_frame->data, raw_frame->linesize,
							0, codec_ctx->height, rgba_buffer,
							rgba_linesize );

				display_texture->update( rgba_buffer[0] );

				keep_going = false;
			}

			free_frame( raw_frame );
			free_packet( packet );
		}
	}
}
예제 #7
0
	//iterate function draw
	sf::Sprite& update() {
		graphTx.update(graph);
		graphSpr.rotate(rotation * 180. / pi);
		return graphSpr;
	}