Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 5, 2018. It is now read-only.
This repository was archived by the owner on Dec 5, 2018. It is now read-only.

Cannot read property 'data' of undefined when use img.pixels[] #132

Closed
@ghost

Description

/* @pjs preload="tux.png"; */

PImage img;       // The source image
int cellsize = 2; // Dimensions of each cell in the grid
int columns, rows;   // Number of columns and rows in our system
int ololo = 30;

void setup(){
    size(screen.width, screen.height, P3D);
    img = loadImage("tux.png"); 
    columns = img.width / cellsize; 
    rows = img.height / cellsize;
    smooth();

}

void draw(){  
  background(0);
// Begin loop for columns
  for ( int i = 0; i < columns; i++) {
// Begin loop for rows
    for ( int j = 0; j < rows; j++) {
        int x = i*cellsize + cellsize/2;  // x position
        int y = j*cellsize + cellsize/2;  // y position
        int loc = x + y*img.width;  // Pixel array location
        color c = img.pixels[loc];  // Grab the color
        // Calculate a z position as a function of mouseX and pixel brightness
        float z = (ololo / float(screen.width)/2) * brightness(img.pixels[loc]) - 100.0;
        // Translate to the location, set fill and stroke, and draw the rect
        pushMatrix();
        translate(x + 200, y + 100, z);
        fill(c, 204);
        noStroke();
        rectMode(CENTER);
        rect(0, 0, cellsize, cellsize);
        popMatrix();
    }
  }     

}

When I use 2D mode i get

Uncaught TypeError: Cannot read property 'data' of undefined - processing.js:18301
getPixel - processing.js:18301
draw - VM48:21
Drawing2D.redraw - processing.js:13468
(anonymous function) - processing.js:13550

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions