Sprite::read()\ Sprite \ Language (API) \ Wiring ALPHA 1.0
Author: Hernando Barragán
Description: Wiring is an electronic sketchbook and hardware electronics for developing ideas. It is a context for learning fundamentals of computer programming and prototyping with electronics within the context of the electronic arts.
Keywords: Wiring, Processing, Interactive Media, Electronic Arts, Programming, C, C++, Hernando Barragán

Search wiring.org.co:

Reference for Wiring version 0023+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.

Class | Sprite
Name | ### read()
Examples |
    #include "Binary.h"
    #include "Sprite.h"
    #include "Matrix.h"

    Matrix myMatrix = Matrix(0, 2, 1);

    /* create a new Sprite instance
       8 pixels wide, 4 pixels tall
    */
    Sprite wave = Sprite(
      8, 4,
      b00011000,
      b00100100,
      b01000010,
      b10000001
    );

    void setup()
    {
    }

    int x = 0;

    void loop()
    {
      myMatrix.write(x, 2, wave);     // place sprite on screen
      myMatrix.write(x - 8, 2, wave); // place sprite again, elsewhere on screen
      delay(75);                      // wait a little bit
      myMatrix.clear();               // clear the screen for next animation frame
      if(x == 8)                      // if reached end of animation sequence
      {
        x = 0;                        // start from beginning
      }
      x++;                            // advance x coordinate to the right

      // invert the value of all the pixels stored in the sprite
      for(int j = 0; j  wave.height(); j++) {
        for(int i = 0; i  wave.width(); i++) {
          if(wave.read(i, j) == 1) {
            wave.write(i, j, 0);      // sets the sprite pixel located at i, j to 0
          } else {
            wave.write(i, j, 1);
          }
        }
      }
    }
Description | The read(x, y) method returns the value stored at the x, y position of a sprite.
Syntax |
    sprite.read(x, y)
Parameters |
x | The x position
y | The y position
Returns | int
Usage | Application

Updated on November 01, 2009 09:05:41am PST