#javascript-processing-example-topic-image-linearimage.htm / htm
<!DOCTYPE html> <html><head> <script src="javascript-processing-example-processing.js"></script> <script src="javascript-processing-example-init.js"></script> <link rel="stylesheet" href="javascript-processing-example-style.css"> </head><body><h1><a href="http://ejohn.org/blog/processingjs/">Processing.js</a></h1> <h2>LinearImage</h2> <p>Click and drag mouse up and down to control the signal. Press and hold any key to watch the scanning.</p> <p><a href="http://processing.org/learning/topics/linearimage.html"><b>Original Processing.org Example:</b> LinearImage</a><br> <script type="application/processing"> PImage a; boolean onetime = true; int[] aPixels = new int[200*200]; int direction = 1; float signal; void setup() { size(33, 33); stroke(255); a = loadImage("cait.jpg"); for(int i=0; i<width*height; i++) { aPixels[i] = a.pixels[i]; } frameRate(30); } void draw() { if (signal > width-1 || signal < 0) { direction = direction * -1; } if(mousePressed) { signal = abs(mouseY\ %height); } else { signal += (0.3*direction); } if(keyPressed) { image(a, 0, 0); /* loadPixels(); for (int i=0; i<width*height; i++) { pixels[i] = aPixels[i]; } updatePixels(); */ line(0, signal, width, signal); } else { loadPixels(); for (int i=0; i<width*height; i++) { pixels[i] = aPixels[int((width*int(signal))+(i\ %width))]; } updatePixels(); } } </script><canvas width="33" height="33"></canvas></p> <div style="overflow: hidden; height: 0px; width: 0px;"><img src="javascript-processing-example-cait.jpg" id="cait.jpg"></div> <pre><b>// All Examples Written by <a href="http://reas.com/">Casey Reas</a> and <a href="http://benfry.com/">Ben Fry</a> // unless otherwise stated.</b> PImage a; boolean onetime = true; int[] aPixels = new int[200*200]; int direction = 1; float signal; void setup() { size(200, 200); stroke(255); a = loadImage("florence03.jpg"); for(int i=0; i<width*height; i++) { aPixels[i] = a.pixels[i]; } frameRate(30); } void draw() { if (signal > width-1 || signal < 0) { direction = direction * -1; } if(mousePressed) { signal = abs(mouseY\ %height); } else { signal += (0.3*direction); } if(keyPressed) { loadPixels(); for (int i=0; i<width*height; i++) { pixels[i] = aPixels[i]; } updatePixels(); line(0, signal, width, signal); } else { loadPixels(); for (int i=0; i<width*height; i++) { pixels[i] = aPixels[int((width*int(signal))+(i\ %width))]; } updatePixels(); } }</pre> </body></html>
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.