This commit is contained in:
benfry
2011-01-26 19:22:19 +00:00
parent d3a18c7964
commit eb64b2d4fc
1234 changed files with 96518 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
/**
* Pixel Array.
*
* Click and drag the mouse up and down to control the signal and
* press and hold any key to see the current pixel being read.
* This program sequentially reads the color of every pixel of an image
* and displays this color to fill the window.
*
* Updated 28 February 2010.
*/
PImage img;
int direction = 1;
float signal;
void setup() {
size(200, 200);
noFill();
stroke(255);
frameRate(30);
img = loadImage("ystone08.jpg");
}
void draw() {
if (signal > img.width*img.height-1 || signal < 0) {
direction = direction * -1;
}
if (mousePressed) {
int mx = constrain(mouseX, 0, img.width-1);
int my = constrain(mouseY, 0, img.height-1);
signal = my*img.width + mx;
} else {
signal += 0.33*direction;
}
int sx = int(signal) % img.width;
int sy = int(signal) / img.width;
if (keyPressed) {
set(0, 0, img); // fast way to draw an image
point(sx, sy);
rect(sx - 5, sy - 5, 10, 10);
} else {
color c = img.get(sx, sy);
background(c);
}
}

View File

@@ -0,0 +1,83 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class PixelArray extends PApplet {
/**
* Pixel Array.
*
* Click and drag the mouse up and down to control the signal and
* press and hold any key to see the current pixel being read.
* This program sequentially reads the color of every pixel of an image
* and displays this color to fill the window.
*/
PImage a;
int[] aPixels;
int direction = 1;
boolean onetime = true;
float signal;
public void setup()
{
size(200, 200);
aPixels = new int[width*height];
noFill();
stroke(255);
frameRate(30);
a = loadImage("ystone08.jpg");
for(int i=0; i<width*height; i++) {
aPixels[i] = a.pixels[i];
}
}
public void draw()
{
if (signal > width*height-1 || signal < 0) {
direction = direction * -1;
}
if(mousePressed) {
if(mouseY > height-1) { mouseY = height-1; }
if(mouseY < 0) { mouseY = 0; }
signal = mouseY*width+mouseX;
} else {
signal += (0.33f*direction);
}
if(keyPressed) {
loadPixels();
for (int i=0; i<width*height; i++) {
pixels[i] = aPixels[i];
}
updatePixels();
rect(signal%width-5, PApplet.parseInt(signal/width)-5, 10, 10);
point(signal%width, PApplet.parseInt(signal/width));
} else {
loadPixels();
for (int i=0; i<width*height; i++) {
pixels[i] = aPixels[PApplet.parseInt(signal)];
}
updatePixels();
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "PixelArray" });
}
}

View File

@@ -0,0 +1,63 @@
/**
* Pixel Array.
*
* Click and drag the mouse up and down to control the signal and
* press and hold any key to see the current pixel being read.
* This program sequentially reads the color of every pixel of an image
* and displays this color to fill the window.
*/
PImage a;
int[] aPixels;
int direction = 1;
boolean onetime = true;
float signal;
void setup()
{
size(200, 200);
aPixels = new int[width*height];
noFill();
stroke(255);
frameRate(30);
a = loadImage("ystone08.jpg");
for(int i=0; i<width*height; i++) {
aPixels[i] = a.pixels[i];
}
}
void draw()
{
if (signal > width*height-1 || signal < 0) {
direction = direction * -1;
}
if(mousePressed) {
if(mouseY > height-1) { mouseY = height-1; }
if(mouseY < 0) { mouseY = 0; }
signal = mouseY*width+mouseX;
} else {
signal += (0.33*direction);
}
if(keyPressed) {
loadPixels();
for (int i=0; i<width*height; i++) {
pixels[i] = aPixels[i];
}
updatePixels();
rect(signal%width-5, int(signal/width)-5, 10, 10);
point(signal%width, int(signal/width));
} else {
loadPixels();
for (int i=0; i<width*height; i++) {
pixels[i] = aPixels[int(signal)];
}
updatePixels();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB