2014-10-30 22 views
0

我的代码通过使用像素的颜色创建椭圆来获取图像并创建点像图像。计算在处理中连续创建的形状/对象

过了一段时间,图像被完全“涂抹”,我想自动切换到我的素描文件夹中的另一个图像。

我想能够计算生成的省略号的数量。一旦生成了'z'椭圆,我想告诉我的代码擦除所有的椭圆并从新的图像开始。

CODE:

PImage img; 
int smallPoint, largePoint; 

void setup() { 
    size(1920, 1080); 
    img = loadImage("rio.jpg"); 
    smallPoint = 12; 
    largePoint = 12; 
    imageMode(CENTER); 
    noStroke(); 
    background(255); 
} 

void draw() { 



for (int i = 0; i < 1000; i++) 
    { 
    drawADot(); 
    } 
} 

void drawADot() 
{ 

    int imageWidth = img.width; 
    int imageHeight = img.height; 
    int ptSize = int(random(100)) + 4; 

    float pointillize = map(mouseX, 0, width, smallPoint, largePoint); //not used right now but for controlling ellipse size 
    int x = int(random(0, imageWidth/8)); 
    int y = int(random(0, imageHeight/8)); 




    color pix = img.get(x*8, y*8); 
    fill(pix, 255); 
    ellipse(x*8, y*8, pointillize, pointillize); 


} 

回答

0

存储在数组中的图像,计数点加入,并有条件地(基于在点的数目)来改变图像被用于该阵列中下一个,就可以通过图像以drawADot()函数作为参数。例如:

PImage img[] = new PImage[2]; 
int smallPoint, largePoint; 
final int DOTSPERDRAW = 500; 
int numberOfDots = 0; 
final int MAXDOTS = DOTSPERDRAW * 100; 
PImage workingImage ; 
int index; 

void setup() { 
    size(810, 455); 
    img[0] = loadImage("http://assets2.exame.abril.com.br/assets/images/2014/8/506584/size_810_16_9_rio.jpg"); 
    img[1] = loadImage("http://upload.wikimedia.org/wikipedia/commons/1/1e/Pilcomayo_rio.jpg"); 
    img[1].resize(810, 0); 
    smallPoint = 12; 
    largePoint = 12; 
    imageMode(CENTER); 
    noStroke(); 
    background(255); 
    workingImage = img[0]; 
} 

void draw() { 

    if (numberOfDots > MAXDOTS) { 
    index = (index + 1) % img.length; 
    workingImage = img[index]; 
    numberOfDots = 0; 
    } 

    for (int i = 0; i < DOTSPERDRAW; i++) 
    { 
    drawADot(workingImage); 
    } 

    numberOfDots += DOTSPERDRAW; 
} 

void drawADot(PImage theImage) 
{ 

    int imageWidth = theImage.width; 
    int imageHeight = theImage.height; 
    int ptSize = int(random(100)) + 4; 

    float pointillize = map(mouseX, 0, width, smallPoint, largePoint); //not used right now but for controlling ellipse size 
    int x = int(random(0, imageWidth/8)); 
    int y = int(random(0, imageHeight/8)); 




    color pix = theImage.get(x*8, y*8); 
    fill(pix, 255); 
    ellipse(x*8, y*8, pointillize, pointillize); 
} 
+0

完全按照我的意愿工作。感谢您的帮助! – thearistocrat 2014-10-31 15:16:28