Render a frame given an observation.
14170
def render_obs(self, obs):
    """"""
    start_time = time.time()
    self._obs = obs
    self.check_valid_queued_action()
    self._update_camera(point.Point.build(
        self._obs.observation.raw_data.player.camera))

    for surf in self._surfaces:
      # Render that surface.
      surf.draw(surf)

    mouse_pos = self.get_mouse_pos()
    if mouse_pos:
      # Draw a small mouse cursor
      self.all_surfs(_Surface.draw_circle, colors.green, mouse_pos.world_pos,
                     0.1)

    self.draw_actions()

    with sw("flip"):
      pygame.display.flip()

    self._render_times.append(time.time() - start_time)
720124
def render_thread(self):
    """"""
    obs = True
    while obs:  # Send something falsy through the queue to shut down.
      obs = self._obs_queue.get()
      if obs:
        for alert in obs.observation.alerts:
          self._alerts[sc_pb.Alert.Name(alert)] = time.time()
        for err in obs.action_errors:
          if err.result != sc_err.Success:
            self._alerts[sc_err.ActionResult.Name(err.result)] = time.time()
        self.prepare_actions(obs)
        if self._obs_queue.empty():
          # Only render the latest observation so we keep up with the game.
          self.render_obs(obs)
        if self._video_writer:
          self._video_writer.add(np.transpose(
              pygame.surfarray.pixels3d(self._window), axes=(1, 0, 2)))
      self._obs_queue.task_done()
260722
def render(self,scope=None,local_vars=None,block=None):
		''' 
		'''

		if not scope:
			class Scope(object):
				pass

			scope = Scope()

		return self.evaluate(scope,local_vars or {}, block)
38330
def transform(self, observation):
        """"""
        self.check_shape(observation)
        scaled = observation[25:-25, :, :]
        if self._dim < 84:
            scaled = cv2.resize(scaled, (84, 84))
        # OpenAI: Resize by half, then down to 42x42 (essentially mipmapping).
        # If we resize directly we lose pixels that, when mapped to 42x42,
        # aren't close enough to the pixel boundary.
        scaled = cv2.resize(scaled, (self._dim, self._dim))
        if self._grayscale:
            scaled = scaled.mean(2)
            scaled = scaled.astype(np.float32)
            # Rescale needed for maintaining 1 channel
            scaled = np.reshape(scaled, [self._dim, self._dim, 1])
        if self._zero_mean:
            scaled = (scaled - 128) / 128
        else:
            scaled *= 1.0 / 255.0
        return scaled
557777
def render(name, data):
        """"""
        # this raises OverflowError if Py_ssize_t can't handle the atom data
        size = len(data) + 8
        if size <= 0xFFFFFFFF:
            return struct.pack(">I4s", size, name) + data
        else:
            return struct.pack(">I4sQ", 1, name, size + 8) + data
175687
def update_frame(self):
        
        d = self.declaration
        if d.x or d.y or d.width or d.height:
            self.frame = (d.x, d.y, d.width, d.height)
291241
function createMotionBlur (render, opts = {}) {
  const {
    samplesPerFrame = 4,
    shutterAngle = 1
  } = opts;
  const otherCanvas = document.createElement('canvas');
  const otherContext = otherCanvas.getContext('2d');

  return (props = {}) => {
    const {
      context,
      canvasWidth,
      canvasHeight,
      totalFrames,
      exporting,
      frame
    } = props;

    // Ignore blur if not exporting, it is too slow...
    if (!exporting) {
      return render(props);
    }

    otherCanvas.width = canvasWidth;
    otherCanvas.height = canvasHeight;
    otherContext.clearRect(0, 0, canvasWidth, canvasHeight);

    const size = canvasWidth * canvasHeight * 4;
    const composite = new Float32Array(size);
    for (let i = 0; i < size; i++) {
      composite[i] = 0;
    }

    // For every sample, run the render function and add the new pixel values to
    // the composite array
    for (let sample = 0; sample < samplesPerFrame; sample++) {
      const sampleFrame = frame + sample * shutterAngle / samplesPerFrame;
      render(Object.assign({}, props, {
        frame: sampleFrame % totalFrames,
        playhead: (sampleFrame / (totalFrames - 1)) % 1
      }));

      const pixels = context.getImageData(0, 0, canvasWidth, canvasHeight).data;
      for (let idx = 0; idx < pixels.length; idx++) {
        composite[idx] += pixels[idx];
      }
    }

    // Fill the pixels in `imageData` with averaged values from `composite`
    const imageData = context.createImageData(canvasWidth, canvasHeight);
    for (let idx = 0; idx < imageData.data.length; idx++) {
      imageData.data[idx] = composite[idx] / samplesPerFrame;
    }

    // Draw the averaged image data to the canvas
    context.putImageData(imageData, 0, 0);
  };
}
120455
def render_summary(self, include_title=True):
        """"""
        title = ""
        classes = ["traceback"]
        if not self.frames:
            classes.append("noframe-traceback")
            frames = []
        else:
            library_frames = sum(frame.is_library for frame in self.frames)
            mark_lib = 0 < library_frames < len(self.frames)
            frames = [group.render(mark_lib=mark_lib) for group in self.groups]

        if include_title:
            if self.is_syntax_error:
                title = u"Syntax Error"
            else:
                title = u"Traceback <em>(most recent call last)</em>:"

        if self.is_syntax_error:
            description_wrapper = u"<pre class=syntaxerror>%s</pre>"
        else:
            description_wrapper = u"<blockquote>%s</blockquote>"

        return SUMMARY_HTML % {
            "classes": u" ".join(classes),
            "title": u"<h3>%s</h3>" % title if title else u"",
            "frames": u"\n".join(frames),
            "description": description_wrapper % escape(self.exception),
        }
945491
def render(self, filename):
        
        self.elapsed_time = -time()
        dpi = 100
        fig = figure(figsize=(16, 9), dpi=dpi)
        with self.writer.saving(fig, filename, dpi):
            for frame_id in xrange(self.frames + 1):
                self.renderFrame(frame_id)
                self.writer.grab_frame()
        self.elapsed_time += time()
734830
def _original_frame(self, x, y):
        
        if self._inverted:
            return self.obs.naxis1 - x, self.obs.naxis2 - y
        return x, y
755299
def render(self, rect, data):
        """"""
        # We can't use our get minimum size, because that enforces
        # the size limits.
        size = self.element.get_minimum_size(data)

        # Assume we're bottom left at our natural size.
        x = rect.x
        y = rect.y
        w = size.x
        h = size.y

        extra_width = rect.w - w
        extra_height = rect.h - h

        if self.horizontal_align == AlignLM.ALIGN_CENTER:
            x += extra_width * 0.5
        elif self.horizontal_align == AlignLM.ALIGN_RIGHT:
            x += extra_width
        elif self.horizontal_align == AlignLM.GROW_X:
            w = rect.w

        if self.vertical_align == AlignLM.ALIGN_MIDDLE:
            y += extra_height * 0.5
        elif self.vertical_align == AlignLM.ALIGN_TOP:
            y += extra_height
        elif self.vertical_align == AlignLM.GROW_Y:
            h = rect.h

        self.element.render(datatypes.Rectangle(x, y, w, h), data)
524954
function () {
				if (this.__private.isRenderRequested) { return; }
				this.__private.isRenderRequested = true;

				var self = this;
				myRequestAnimationFrame(function () {
					self.__private.isRenderRequested = false;
					self.render();
				});
			}
559574
def draw_mini_map(self, surf):
    """"""
    if (self._render_rgb and self._obs.observation.HasField("render_data") and
        self._obs.observation.render_data.HasField("minimap")):
      # Draw the rendered version.
      surf.blit_np_array(features.Feature.unpack_rgb_image(
          self._obs.observation.render_data.minimap))
    else:  # Render it manually from feature layer data.
      hmap_feature = features.MINIMAP_FEATURES.height_map
      hmap = hmap_feature.unpack(self._obs.observation)
      if not hmap.any():
        hmap = hmap + 100  # pylint: disable=g-no-augmented-assignment
      hmap_color = hmap_feature.color(hmap)

      creep_feature = features.MINIMAP_FEATURES.creep
      creep = creep_feature.unpack(self._obs.observation)
      creep_mask = creep > 0
      creep_color = creep_feature.color(creep)

      if self._obs.observation.player_common.player_id in (0, 16):  # observer
        # If we're the observer, show the absolute since otherwise all player
        # units are friendly, making it pretty boring.
        player_feature = features.MINIMAP_FEATURES.player_id
      else:
        player_feature = features.MINIMAP_FEATURES.player_relative
      player_data = player_feature.unpack(self._obs.observation)
      player_mask = player_data > 0
      player_color = player_feature.color(player_data)

      visibility = features.MINIMAP_FEATURES.visibility_map.unpack(
          self._obs.observation)
      visibility_fade = np.array([[0.5] * 3, [0.75]*3, [1]*3])

      # Compose and color the different layers.
      out = hmap_color * 0.6
      out[creep_mask, :] = (0.4 * out[creep_mask, :] +
                            0.6 * creep_color[creep_mask, :])
      out[player_mask, :] = player_color[player_mask, :]
      out *= visibility_fade[visibility]

      # Render the bit of the composited layers that actually correspond to the
      # map. This isn't all of it on non-square maps.
      shape = self._map_size.scale_max_size(
          self._feature_minimap_px).floor()
      surf.blit_np_array(out[:shape.y, :shape.x, :])

      surf.draw_rect(colors.white * 0.8, self._camera, 1)  # Camera
      pygame.draw.rect(surf.surf, colors.red, surf.surf.get_rect(), 1)
598054
def processFrame(frame):
    """"""
    # The pixels are grey-scale values from 0-255 - white = 255, black = 0
    # We want to turn the image into two values, one for the left "sensor" and one for the right.
    # There are many possible ways to do this. The very simplest way would be
    # to examine the values of two pixels - one in the centre of the left half of the image,
    # and one in the centre of the right half. What are the obvious problems with this?

    # NB: The pixels are stored in a flat (1 dimensional) array, so to calculate the index of the pixels
    # at (x,y), we do:
    # index = x + (y * width)

    width = frame.width
    height = frame.height
    pixels = frame.pixels

    USE_SIMPLE_APPROACH = False  # Change this to False to use more sophisticated approach.

    if USE_SIMPLE_APPROACH:
        # Simplest approach.
        left_centre_x = int(width / 4)      # Centre of left half
        right_centre_x = int(3 * width / 4) # Centre of right half
        centre_y = int(height / 2)          # Middle row
        left_pixel_index = left_centre_x + (centre_y * width)
        right_pixel_index = right_centre_x + (centre_y * width)
        left_sensor = float(pixels[left_pixel_index]) / 255.0
        right_sensor = float(pixels[right_pixel_index]) / 255.0
    else:
        # Obviously, the simple approach misses a lot of data, and is very susceptible to noise.
        # A better approach would be to consider more pixels.
        # You could take the average of all the pixels - it's slower but better.
        # Or you could use the median value, which is less noisy than the mean.
        # Here we calculate both, and estimate the median using histograms:
        left_total = 0
        right_total = 0
        left_hist = [0 for i in range(256)]
        right_hist = [0 for i in range(256)]
        # Create a histogram for each half of the image:
        for y in range(height):
            for x in range(int(width/2)):
                i = pixels[x + y*width]
                left_hist[i] += 1
                left_total += float(i)/255.0
            for x in range(int(width/2), width):
                i = pixels[x + y*width]
                right_hist[i] += 1
                right_total += float(i)/255.0
        # Calculate the mean values:
        left_mean, right_mean = left_total / (width*height/2), right_total / (width*height/2)
        # Now use the histogram to estimate the median value
        left_total, right_total = 0, 0
        pixels_per_half = width * height / 2
        cut_off_value = pixels_per_half / 2
        left_cut_off_point, right_cut_off_point = 0, 0
        while (left_total < cut_off_value):
            left_total += left_hist[left_cut_off_point]
            left_cut_off_point += 1
        while(right_total < cut_off_value):
            right_total += right_hist[right_cut_off_point]
            right_cut_off_point += 1
        left_median, right_median = left_cut_off_point / 255.0, right_cut_off_point / 255.0
        
        # Use the median values:
        left_sensor, right_sensor = left_median, right_median
        # Or uncomment this line to use the mean values:
        # left_sensor, right_sensor = left_mean, right_mean
    
    # In our gloomy arena, we never get particularly bright, so the sensor values tend to be low.
    # To get more action from our vehicle, we can scale up (keeping 1.0 as the max).
    # What values work well for GAIN? What happens if it's too high or too low?
    GAIN = 1.8
    left_sensor = min(1, left_sensor * GAIN)
    right_sensor = min(1, right_sensor * GAIN)
    # Done - return the values:
    return left_sensor, right_sensor
724891
def render(self, model, color, num_turtles):
        """"""
        self.program.bind()
        glBindVertexArray(self.vao)

        self.model_buffer.load(model.data, model.byte_size)
        self.color_buffer.load(color.data, color.byte_size)

        glDrawArraysInstanced(
            GL_TRIANGLES,
            0,
            len(self.geometry.edges) // 7,  # 7 = 4 for vertex, 3 for edge
            num_turtles
        )

        glBindVertexArray(0)
        self.program.unbind()
456904
def render(self):
        """"""
        self.screen.fill(self.BACKGROUND_COLOR)

        for wid, cond in self._widgets:
            if cond():
                wid.render(self.screen)

        if self.BORDER_COLOR is not None:
            pygame.draw.rect(self.screen, self.BORDER_COLOR, ((0, 0), self.SCREEN_SIZE), 1)

        if self.SHOW_FPS:
            self.fps.render(self.screen)
514102
function render() {
            // If first render call, wait for next animationFrame
            if (!renderID) {
                renderID = rAF(render);
                if (dragging.released) {
                    trigger('moveStart');
                }
                return;
            }

            // If immediate repositioning is requested, SLIDEE is being dragged, or animation duration would take
            // less than 2 frames, don't animate
            if (animation.immediate || (!dragging.released ? dragging.source === 'slidee' : o.speed < 33)) {
                pos.cur = animation.to;
            }
            // Use tweesing for animations without known end point
            else if (!dragging.released && dragging.source === 'handle') {
                pos.cur += (animation.to - pos.cur) * o.syncFactor;
            }
            // Use tweening for basic animations with known end point
            else {
                animation.time = Math.min(+new Date() - animation.start, o.speed);
                pos.cur = animation.from + animation.delta * jQuery.easing[o.easing](animation.time/o.speed, animation.time, 0, 1, o.speed);
            }

            // If there is nothing more to render (animation reached the end, or dragging has been released),
            // break the rendering loop, otherwise request another animation frame
            if (animation.to === Math.round(pos.cur) && (!dragging.released || animation.time >= o.speed)) {
                pos.cur = pos.dest;
                renderID = 0;
            } else {
                renderID = rAF(render);
            }

            trigger('move');

            // Update SLIDEE position
            if (!parallax) {
                if (transform) {
                    $slidee[0].style[transform] = gpuAcceleration + (o.horizontal ? 'translateX' : 'translateY') + '(' + (-pos.cur) + 'px)';
                } else {
                    $slidee[0].style[o.horizontal ? 'left' : 'top'] = -Math.round(pos.cur) + 'px';
                }
            }

            // When animation reached the end, and dragging is not active, trigger moveEnd
            if (!renderID && dragging.released) {
                trigger('moveEnd');
            }

            syncScrollbar();
        }