mirror of
https://github.com/processing/processing4.git
synced 2026-01-29 11:21:06 +01:00
Re-adding Topics to SVN
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user