So when I change my code over to javascript it just doesn't work at all.
Which makes uploading it impossible at the moment.
here is my code(not converted):
import java.io.File;
PImage img;
int cellsize = 5;
int cols, rows;
void setup() {
selectInput("Select a file to process:", "fileSelected");
size(500, 500, P3D);
frame.setResizable(true);
}
void fileSelected(File selection) {
if (selection.exists()) {
img = loadImage(selection.getAbsolutePath());
}
frame.setSize(img.width, img.height);
cols = width/cellsize; // Calculate # of columns
rows = height/cellsize; // Begin loop for rows
if (selection == null) {
println("Window was closed or the user hit cancel.");
}
else {
println("User selected " + selection.getAbsolutePath());
}
}
void draw() {
background(245, 245, 245);
loadPixels();
if ( img != null )
{
image( img, 0, 0 );
}
if (mousePressed == true) {
background(245, 245, 245);
// Begin loop for columns
for (int i = 0; i < cols; i++) {
// Calculate # of 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*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 = (mouseX/(float)width*10) * saturation(img.pixels[loc])-(img.width/1);
// Translate to the location, set fill and stroke, and draw the rect
float r = (mouseX/(float)width*10) * red(img.pixels[loc])-(img.width/1);
float g = (mouseX/(float)width*10) * blue(img.pixels[loc])-(img.width/1);
float b = (mouseX/(float)width*10) * green(img.pixels[loc])-(img.width/1);
pushMatrix();
translate(x,y,z);
translate(r, g, b);
fill(c);
noStroke();
rectMode(CENTER);
rect(.5*width, .5*height, cellsize, cellsize);
popMatrix();
}
}
}
}
1