2014-10-30 1 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