void ofApp::setup(){ // Img.load("Water Spinach.jpg"); // ofSetWindowShape(Img.getWidth(), Img.getHeight()); // ====== Random version ======== // ofSetFrameRate(10); // ofBackground(0); // //Initialize the grid with random values // for (int i = 0; i < gridSize; i++) { // for (int j = 0; j < gridSize; j++) { // grid[i][j] = ofRandom(1) > 0.5; // } // } // ===== image version ===== ofSetFrameRate(10); image.load("Water Spinach.jpg"); // image.load("cat-fully-charged.jpg"); image.resize(gridSize, gridSize); cout << "Image width: " << image.getWidth() << " height: " << image.getHeight() << endl; for (int i = 0; i < gridSize; i++) { for (int j = 0; j < gridSize; j++) { ofColor pixelColor = image.getColor(i, j); int totalRGB = pixelColor.r + pixelColor.g + pixelColor.b; // cout << totalRGB << endl; if (totalRGB > 255*3/4) { grid[i][j] = true; } else { grid[i][j] = false; } } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter