2017-07-01 9 views
1

現在、処理スケッチを使用して、フォルダ内にある多数の画像を処理しています。文字列内の次のイメージに進むonClickコマンドを設定しました。それは非常に時間がかかり、スケッチが完成すると、スケッチは文字列から次のイメージを選択して繰り返すというアクションを自動化したいと思います。 onClickコマンドは、エクスポートフォルダのイメージも保存しますが、同じファイル名で保存するたびに、順次番号を設定しようとしましたが、それまでは機能していませんでした。どんな助けでも大歓迎です。処理の選択の自動化


String[] imgNames = {"1.jpg", "2.jpg", "3.jpg"}; 
PImage img; 
int imgIndex = 0; 


void nextImage() { 
    background(255); 
    frameRate(10000); 
    loop(); 
    frameCount = 0; 

    img = loadImage(imgNames[imgIndex]); 
    img.loadPixels(); 

    imgIndex += 1; 
    if (imgIndex >= imgNames.length) { 
    imgIndex = 0; 
    } 
} 


void paintStroke(float strokeLength, color strokeColor, int strokeThickness) { 
    float stepLength = strokeLength/4.0; 

    // Determines if the stroke is curved. A straight line is 0. 
    float tangent1 = 0; 
    float tangent2 = 0; 

    float odds = random(1.0); 

    if (odds < 0.7) { 
    tangent1 = random(-strokeLength, strokeLength); 
    tangent2 = random(-strokeLength, strokeLength); 
    } 

    // Draw a big stroke 
    noFill(); 
    stroke(strokeColor); 
    strokeWeight(strokeThickness); 
    curve(tangent1, -stepLength*2, 0, -stepLength, 0, stepLength, tangent2, stepLength*2); 

    int z = 1; 

    // Draw stroke's details 
    for (int num = strokeThickness; num > 0; num --) { 
    float offset = random(-50, 25); 
    color newColor = color(red(strokeColor)+offset, green(strokeColor)+offset, blue(strokeColor)+offset, random(100, 255)); 

    stroke(newColor); 
    strokeWeight((int)random(0, 3)); 
    curve(tangent1, -stepLength*2, z-strokeThickness/2, -stepLength*random(0.9, 1.1), z-strokeThickness/2, stepLength*random(0.9, 1.1), tangent2, stepLength*2); 

    z += 1; 
    } 
} 


void setup() { 
    size(1600, 700); 

    nextImage(); 
} 


void draw() { 
    translate(width/2, height/2); 

    int index = 0; 

    for (int y = 0; y < img.height; y+=1) { 
    for (int x = 0; x < img.width; x+=1) { 
     int odds = (int)random(20000); 

     if (odds < 1) { 
     color pixelColor = img.pixels[index]; 
     pixelColor = color(red(pixelColor), green(pixelColor), blue(pixelColor), 100); 

     pushMatrix(); 
     translate(x-img.width/2, y-img.height/2); 
     rotate(radians(random(-90, 90))); 

     // Paint by layers from rough strokes to finer details 
     if (frameCount < 20) { 
      // Big rough strokes 
      paintStroke(random(150, 250), pixelColor, (int)random(20, 40)); 
     } else if (frameCount < 1000) { 
      // Thick strokes 
      paintStroke(random(75, 125), pixelColor, (int)random(8, 12)); 
     } else if (frameCount < 1500) { 
      // Small strokes 
      paintStroke(random(20, 30), pixelColor, (int)random(1, 4)); 
     } else if (frameCount < 10000) { 
      // Big dots 
      paintStroke(random(5, 10), pixelColor, (int)random(5, 8)); 
     } else if (frameCount < 10000) { 
      // Small dots 
      paintStroke(random(1, 2), pixelColor, (int)random(1, 3)); 
     } 

     popMatrix(); 
     } 

     index += 1; 
    } 
    } 

    if (frameCount > 10000) { 
    noLoop(); 
    } 

// if(key == 's'){ 
// println("Saving..."); 
// saveFrame("screen-####.jpg"); 
// println("Done saving."); 
// } 
} 



void mousePressed() { 
    save("001.tif"); 
    nextImage(); 
} 

答えて

0

は、あなただけのこのif文の中からnextImage()関数を呼び出すことができませんか?

if (frameCount > 10000) { 
noLoop(); 
} 

は次のようになります。

if (frameCount > 10000) { 
nextImage(); 
} 

異なるファイル名を使用すると、ちょうどあなたがファイルを保存するたびにインクリメントintを使用し、save()関数内でその値を使用します。それとも、frameCount変数を使用できます:あなたがフォローアップの質問がある場合は

save("img" + frameCount + ".tif"); 

を、代わりにあなたのプロジェクト全体のMCVEを投稿してください。その1つのことだけを行う小さなサンプルプログラムでは、一度に1つの問題を切り分けてみてください。がんばろう。

+0

華麗、ありがとう。 – leonbutler

関連する問題