Limit how many times something is blurred.

edited April 2014 in How To...

Hi I was just wondering if there was a way of setting how many times something can be blurred during void draw() - at the moment my sketch blurs the (animated) line more and more until eventually the background becomes black. If someone could point me in the right direction then that would be great. Thanks

Tagged:

Answers

  • Just use a variable that keeps track of how many times the blurring has occurred, and only perform the blurring if that variable is under some threshold.

  • Any on advice on how to do this? Would I use an if/else statement and a boolean?

    Thanks

  • Yep. What happened when you tried that? Here is some pseudocode to get you started:

    int blurredCount = 0;
    int blurredMax = 10;
    
    void draw(){
       if(blurredCount < blurredMax){
          blur(); //do the blurring
          blurredCount++;
       }
    }
    
  • I was probably putting it in the wrong place so it was just doing the same thing, i'll give it shot with your pseudocode though, thanks!

  • Okay so what is happening now is the first 10 lines (int bluttedMax = 10); are being blurred and then it stops.

    if(blurredCount < blurredMax){
          filter(BLUR,1); 
          blurredCount++;
       }  
      line(x, y, x, y+lineHeight);
    

    I think it could be because I am using:

    x++;

  • Can you post your code in the form of an MCVE instead of a disconnected snippet?

  • import processing.serial.*;
    import cc.arduino.*;
    import processing.video.*; 
    
    Capture cam; 
    Arduino arduino;
    
    int xPos = 1; // horizontal position of the graph
    float lightSensor;
    int startTemp;
    int temperature;
    color[] colors;
    boolean hasReadColors = false;
    
    boolean hasBlurred = false;
    
    int colorA;
    int colorB;
    int colorC;
    int colorD;
    int colorE;
    
    float yPos = 0;
    float yPos2;
    
    int blurredCount = 0;
    int blurredMax = 100;
    
    color tempColor;
    
    void setup () {
    
      size(800, 600);
      //background(0);
      arduino = new Arduino(this, Arduino.list()[2], 57600);
      startTemp = arduino.analogRead(1);
      cam = new Capture(this);
      cam.start(); 
      colors = new color[5];
    
       if (startTemp>=200) {
      }
      else if (startTemp>=180) {
        background(238, 72, 54);
        tempColor = color(238,72,54);
      }
      else if (startTemp>=160) {
        background(244, 127, 43);
        tempColor = color(244,127,43);
      }
      else if (startTemp>=140) {
        background(252, 215, 83);
        tempColor = color(252,215,84);
      }
      else if (startTemp>=120) {
        background(236, 232, 90);
        tempColor = color(266,232,90);
      }
      else if (startTemp>=100) {
        background(237, 235, 131);
        tempColor = color(237,235,131);
      }
      else if (startTemp>=80) {
        background(244, 242, 170);
        tempColor = color(244,242,170);
      }
      else if (startTemp>=60) {
        background(251, 251, 221);
        tempColor = color(251,251,221);
      }
      else if (startTemp>=40) {
        background(199, 233, 246);
        tempColor = color(199,233,246);
      }
      else if (startTemp>=20) {
        background(166, 222, 244);
        tempColor = color(166,222,244);
      }
      else if (startTemp>=10) {
        background(126, 212, 241);
        tempColor = color(126,212,241);
      }
      else if (startTemp<10) {
        background(238, 72, 54);
        tempColor = color(238,72,54);
      }
    }
    
    
    void draw() {
    
      if (cam.available() && hasReadColors == false) { 
        cam.read(); 
        for (int i = 0; i< colors.length; i++) {
          colors[i] = cam.get((int)random(width), (int)random(height));
        }
        hasReadColors = true;
      } 
    
      colors = sort(colors);
    
      colorA = colors [0];
      colorB = colors [1];
      colorC = colors [2];
      colorD = colors [3];
      colorE = colors [4];
    
    
    
      lightSensor = arduino.analogRead(0)/3;
      temperature = arduino.analogRead(1); 
      println(temperature);
    
    
      strokeWeight(1);
    
      if (lightSensor <= 40) {
        stroke(colorA, 100);
      }
      else if (lightSensor <= 100) {
        stroke(colorB, 100);
      }
      else if (lightSensor <= 100) {
        stroke(colorC, 100);
      }
      else if (lightSensor <= 100) {
        stroke(colorD, 100);
      }
      else {
        stroke(colorE, 100);
      }
    
    
    
      //  yPos2=yPos+random(-10,10);
      yPos2=yPos+random(-1, 1); 
      yPos = yPos+random(-4, 4);
    
    
      line(xPos, yPos2+lightSensor, xPos, yPos);
      stroke(tempColor);
      strokeWeight(lightSensor/15);
      point(xPos, yPos);
      //point(xPos, yPos+lightSensor);
    strokeWeight(1);
    
      if (temperature > startTemp) {
        stroke(255, 85, 84, 100);
      }
      else if (temperature < startTemp) {
        stroke(34, 110, 137, 100);
      }
      else {
        noStroke();
        //stroke(250, 250, 250);
      }
      if (blurredCount < blurredMax && xPos == width) {
        //filter(BLUR, 1);
        blurredCount++;
      }
      line(xPos, yPos2-temperature, xPos, yPos);
      //strokeWeight(lightSensor/10);
      // point(xPos, yPos-lightSensor);
    
    
    
    
      // at the edge of the screen, go back to the beginning:
      if (xPos >= width) {
        xPos = 0;
        yPos = yPos+85;
      }
    
      if ( yPos>= height) {
        yPos = 0;
        xPos = 0;
        //background();
      }
    
      else {
        // increment the horizontal position:
        xPos++;
      }
    }
    
  • That is way too much code. You should be trying to isolate your problem, as that's the first step of debugging. You also seem to have commented out the filter() function, so I'm not sure what this is supposed to do.

Sign In or Register to comment.