Initial Commit
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Alpha Mask.
|
||||
*
|
||||
* Loads a "mask" for an image to specify the transparency
|
||||
* in different parts of the image. The two images are blended
|
||||
* together using the mask() method of PImage.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
PImage imgMask;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
img = loadImage("moonwalk.jpg");
|
||||
imgMask = loadImage("mask.jpg");
|
||||
img.mask(imgMask);
|
||||
imageMode(CENTER);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0, 102, 153);
|
||||
image(img, width/2, height/2);
|
||||
image(img, mouseX, mouseY);
|
||||
}
|
||||
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 117 KiB |
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Background Image.
|
||||
*
|
||||
* This example presents the fastest way to load a background image
|
||||
* into Processing. To load an image as the background, it must be
|
||||
* the same width and height as the program.
|
||||
*/
|
||||
|
||||
PImage bg;
|
||||
int y;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
// The background image must be the same size as the parameters
|
||||
// into the size() method. In this program, the size of the image
|
||||
// is 640 x 360 pixels.
|
||||
bg = loadImage("moonwalk.jpg");
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(bg);
|
||||
|
||||
stroke(226, 204, 0);
|
||||
line(0, y, width, y);
|
||||
|
||||
y++;
|
||||
if (y > height) {
|
||||
y = 0;
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 117 KiB |
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Create Image.
|
||||
*
|
||||
* The createImage() function provides a fresh buffer of pixels to play with.
|
||||
* This example creates an image gradient.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
img = createImage(230, 230, ARGB);
|
||||
for(int i = 0; i < img.pixels.length; i++) {
|
||||
float a = map(i, 0, img.pixels.length, 255, 0);
|
||||
img.pixels[i] = color(0, 153, 204, a);
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
image(img, 90, 80);
|
||||
image(img, mouseX-img.width/2, mouseY-img.height/2);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Load and Display
|
||||
*
|
||||
* Images can be loaded and displayed to the screen at their actual size
|
||||
* or any other size.
|
||||
*/
|
||||
|
||||
PImage img; // Declare variable "a" of type PImage
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
// The image file must be in the data folder of the current sketch
|
||||
// to load successfully
|
||||
img = loadImage("moonwalk.jpg"); // Load the image into the program
|
||||
}
|
||||
|
||||
void draw() {
|
||||
// Displays the image at its actual size at point (0,0)
|
||||
image(img, 0, 0);
|
||||
// Displays the image at point (0, height/2) at half of its size
|
||||
image(img, 0, height/2, img.width/2, img.height/2);
|
||||
}
|
||||
|
After Width: | Height: | Size: 117 KiB |
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Pointillism
|
||||
* by Daniel Shiffman.
|
||||
*
|
||||
* Mouse horizontal location controls size of dots.
|
||||
* Creates a simple pointillist effect using ellipses colored
|
||||
* according to pixels in an image.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
int smallPoint, largePoint;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
img = loadImage("moonwalk.jpg");
|
||||
smallPoint = 4;
|
||||
largePoint = 40;
|
||||
imageMode(CENTER);
|
||||
noStroke();
|
||||
background(255);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
float pointillize = map(mouseX, 0, width, smallPoint, largePoint);
|
||||
int x = int(random(img.width));
|
||||
int y = int(random(img.height));
|
||||
color pix = img.get(x, y);
|
||||
fill(pix, 128);
|
||||
ellipse(x, y, pointillize, pointillize);
|
||||
}
|
||||
|
After Width: | Height: | Size: 117 KiB |
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Request Image
|
||||
* by Ira Greenberg ( From Processing for Flash Developers).
|
||||
*
|
||||
* Shows how to use the requestImage() function with preloader animation.
|
||||
* The requestImage() function loads images on a separate thread so that
|
||||
* the sketch does not freeze while they load. It's very useful when you are
|
||||
* loading large images.
|
||||
*
|
||||
* These images are small for a quick download, but try it with your own huge
|
||||
* images to get the full effect.
|
||||
*/
|
||||
|
||||
int imgCount = 12;
|
||||
PImage[] imgs = new PImage[imgCount];
|
||||
float imgW;
|
||||
|
||||
// Keeps track of loaded images (true or false)
|
||||
boolean[] loadStates = new boolean[imgCount];
|
||||
|
||||
// For loading animation
|
||||
float loaderX, loaderY, theta;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
imgW = width/imgCount;
|
||||
|
||||
// Load images asynchronously
|
||||
for (int i = 0; i < imgCount; i++){
|
||||
imgs[i] = requestImage("PT_anim"+nf(i, 4)+".gif");
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(0);
|
||||
|
||||
// Start loading animation
|
||||
runLoaderAni();
|
||||
|
||||
for (int i = 0; i < imgs.length; i++){
|
||||
// Check if individual images are fully loaded
|
||||
if ((imgs[i].width != 0) && (imgs[i].width != -1)){
|
||||
// As images are loaded set true in boolean array
|
||||
loadStates[i] = true;
|
||||
}
|
||||
}
|
||||
// When all images are loaded draw them to the screen
|
||||
if (checkLoadStates()){
|
||||
drawImages();
|
||||
}
|
||||
}
|
||||
|
||||
void drawImages() {
|
||||
int y = (height - imgs[0].height) / 2;
|
||||
for (int i = 0; i < imgs.length; i++){
|
||||
image(imgs[i], width/imgs.length*i, y, imgs[i].height, imgs[i].height);
|
||||
}
|
||||
}
|
||||
|
||||
// Loading animation
|
||||
void runLoaderAni(){
|
||||
// Only run when images are loading
|
||||
if (!checkLoadStates()){
|
||||
ellipse(loaderX, loaderY, 10, 10);
|
||||
loaderX += 2;
|
||||
loaderY = height/2 + sin(theta) * (height/8);
|
||||
theta += PI/22;
|
||||
// Reposition ellipse if it goes off the screen
|
||||
if (loaderX > width + 5){
|
||||
loaderX = -5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return true when all images are loaded - no false values left in array
|
||||
boolean checkLoadStates(){
|
||||
for (int i = 0; i < imgs.length; i++){
|
||||
if (loadStates[i] == false){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Transparency.
|
||||
*
|
||||
* Move the pointer left and right across the image to change
|
||||
* its position. This program overlays one image over another
|
||||
* by modifying the alpha value of the image with the tint() function.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
float offset = 0;
|
||||
float easing = 0.05;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
img = loadImage("moonwalk.jpg"); // Load an image into the program
|
||||
}
|
||||
|
||||
void draw() {
|
||||
image(img, 0, 0); // Display at full opacity
|
||||
float dx = (mouseX-img.width/2) - offset;
|
||||
offset += dx * easing;
|
||||
tint(255, 127); // Display at half opacity
|
||||
image(img, offset, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 117 KiB |