Dots
August 10, 2018
Someone made a drawing with 3 million dots in 300 hours. I thought that’s a waste of time. So I wrote a processing sketch that takes any photo and outputs a dot image effect at any size you want. The programming took about 30 minutes, and the image generation now takes less than 1 second. Which is less than 300 hours.
Code and processing sketch below free to download, modify, reuse in any way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
import processing.pdf.*; PImage img; PImage displayImg; // change this to get a bigger final image int scale = 4; float xScreen, yScreen; float randomPixel; color pixelColor; int totalPoints = 0; void setup() { size(600, 800); //size(2400, 3200, PDF, "womanDots.pdf"); background(255); //work in Hue Saturation Brightness instead of RGB, since the image is b/w //with a max value of 100 colorMode(HSB, 100); fill(255); img = loadImage("woman2.jpg"); displayImg = createImage(img.width * scale, img.height * scale, RGB); //make the display image white initially for (int i=0; i<displayImg.pixels.length; i++) { displayImg.pixels[i] = color(0, 0, 100); } //this only needs to be created once //beginRecord(PDF, "womanDots.pdf"); createDotImage(); } void draw() { // we want to move the image around on the screen and see it in full even if it's a few times larger than the canvas rect(0, 0, width, height); xScreen = map(mouseX, 0, width, width - displayImg.width, 0); yScreen = map(mouseY, 0, height, height - displayImg.height, 0); image(displayImg, xScreen, yScreen); } void createDotImage() { //loop through all the pixels of the original image and create dots in a square for each of them // how many dots depends on how bright / dark the pixel is for (int y=0; y<img.height; y++) { for (int x=0; x<img.width; x++) { pixelColor = img.get(x, y); //now use the color information in a square that's scale*scale pixels large in the displayImg for (int j=0; j<scale; j++) { for (int i=0; i<scale; i++) { randomPixel = random(100); //pixels need to be black or white depending on whether they pass a certain threshold if (brightness(pixelColor) < randomPixel) { displayImg.set((x*scale)+i, (y*scale)+j, color(0, 0, 0)); totalPoints++; } } } } } println("Total number of points = " + totalPoints); //image(displayImg, 0, 0); //endRecord(); } |
Foarte interesant, felicitari!
De curiozitate, ce limbaj de programare este acesta? In videoclip apare “Java” intr-un colt din drapta sus, dar analizand codul nu pare sa aiba legatura cu Java. Este cumva scris in “Processing”? Mersi!
Salut Calin!
Din cate vad in cod el importa o biblioteca care se numeste Processing(poti sa o gasesti si tu pe internet; din ce am citit au api pt JavaScript, Java si Python). Limbajul de programare pare sa fie cel ce este folosit in mediul Arduino in editorul lor.
Bună ziua!
In primul rând,multumim pentru aceasta inventie,e super si de abia astept să o folosesc.In schimb,neavând un fundal pe software,nu stiu cum să schimb poza.VĂ ROG..Mă poate ajuta cineva cu asta?
Dau o bere..Patreon or w/ever
Multumesc.