GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Processing
  • Download
  • Reference
  • Environment
  • Libraries
  • Tools
  • Wiki
  • Tutorials
  • Examples
  • Books
  • Forum
  • Overview
  • People
  • Privacy

This view

  • Original page
  • New address

GeezerVison is showing processing.org — pixelHeight / Reference

Reference+
Documentation→Reference→Environment

Name

pixelHeight

Description

When pixelDensity(2) is used to make use of a high resolution display (called a Retina display on OS X or high-dpi on Windows and Linux), the width and height of the sketch do not change, but the number of pixels is doubled. As a result, all operations that use pixels (like loadPixels(), get(), set(), etc.) happen in this doubled space. As a convenience, the variables pixelWidth and pixelHeight hold the actual width and height of the sketch in pixels. This is useful for any sketch that uses the pixels[] array, for instance, because the number of elements in the array will be pixelWidth*pixelHeight, not width*height.

Examples

  • void setup() {
      size(600, 400);
      pixelDensity(2);
      println(width, height);
      println(pixelWidth, pixelHeight);
    }
    
  • void setup() {
      size(600, 400);
      pixelDensity(2);  // Double the pixel density
      println(width, height);
      println(pixelWidth, pixelHeight);
    }
    
    void draw() {
      loadPixels();
      // Fill all the pixels to blue with using
      // pixelWidth and pixelHeight
      for (int i = 0; i < pixelWidth * pixelHeight; i++) {
        pixels[i] = color(0, 0, 255);
      }
      // Fill one quarter of the pixels to yellow
      // because the pixel density is set to 2 in setup()
      // and 'width' and 'height' don't reflect the pixel 
      // dimensions of the sketch
      for (int i = 0; i < width * height; i++) {
        pixels[i] = color(255, 255, 0);
      }
      updatePixels();
      noLoop();
    }
    

Related

  • pixelWidth
  • pixelDensity()
  • displayDensity()
Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.