Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Forks of this sketch will no longer be attributed to this sketch.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution NonCommercial ShareAlike
Shiffman's Mirror
Levin
xxxxxxxxxx
// Learning Processing by Daniel Shiffman
// http://www.learningprocessing.com
// Example 16-6: Drawing a grid of squares
// "Brightness Mirror"
// videoScale is the size of each cell in the grid,
// and the ratio of canvas size to video capture size
// 40 * 16 = 640
// 30 * 16 = 480
var videoScale = 16;
// Number of columns and rows in our system
var cols, rows;
function setup() {
createCanvas(640, 480);
// Initialize columns and rows
cols = width/videoScale;
rows = height/videoScale;
pixelDensity(1);
video = createCapture(VIDEO);
video.size(cols, rows);
video.hide();
}
function draw() {
background(0);
rectMode(CENTER);
video.loadPixels();
// Begin loop for columns
for (var i = 0; i < cols; i++) {
// Begin loop for rows
for (var j = 0; j < rows; j++) {
// Reversing x to mirror the image
// In order to mirror the image, the column is reversed with the following formula:
// mirrored column = width - column - 1
var loc = ((cols - i - 1) + j * cols) * 4;
// The functions red(), green(), and blue()
// extract these color components from a pixel.
var r = video.pixels[loc ];
var g = video.pixels[loc + 1];
var b = video.pixels[loc + 2];
// A rectangle size is calculated as a function of the pixel's brightness.
// A bright pixel is a large rectangle, and a dark pixel is a small one.
var sz = map((r+g+b)/3, 0, 255, 0, videoScale);
fill(255);
noStroke();
// For every column and row, a rectangle is drawn at an (x,y) location scaled and sized by videoScale.
var x = i*videoScale;
var y = j*videoScale;
rect(x + videoScale/2, y + videoScale/2, sz, sz);
}
}
}
See More Shortcuts
Please verify your email to comment
Verify Email