Changing the background for an image (related to the arduino logo example)

For the life of my, I can’t sort out why this won’t work, despite looking at several examples and tutorials online that would suggest this should work. I am largely using the example from the Arduino projects book, chapter 14 on “changing the arduino logo” but I’ve removed the actual Arduino dependency to make it easy for someone to run and review. Any help would be appreciated!


//Creating an object for the image
PImage logo;
//Creating a variable to store the background colour
int bgcolor=0;
void setup(){
 //Setting the colour mode. In this case we're useing HSB(HueSaturationBrightness). The hue will change while turning the potentiometer.
 colorMode(HSB,255);
 //loading the image directly form the Internet
 logo=loadImage("http://arduino.cc/logo.png");
 // you can use "size(logo.width,logo.height)" to automatically adjust the scale
 //if you have problems, adjust it manually:
 size(170,120);
 
}

void draw(){

  for (int i = 0; i < 255; i = i+1) {
    bgcolor = i;
    //changing the image background
    background(bgcolor,255,255);
    //Displaying the image and starting drawing on top left (0.0)
    image(logo,0,0);
    delay(10);
  }
 println("looping again");
 delay(1000);
 
}

I should note it compiles and runs, but you do not see the background change at all. I am using a windows 7 laptop

-a- your linked picture is good
( transparent… )
-b- it loads
-c- your draw loop

    • for color and
    • using delay

not good style…

try:

PImage logo;        //Creating an object for the image
int bgcolor=0;      //Creating a variable to store the background colour

void setup() {
  size(170, 120);
  colorMode(HSB, 255);
  logo=loadImage("http://arduino.cc/logo.png");
  println("image loaded");
}

void draw() {
  bgcolor++;
  if (bgcolor > 255 ) bgcolor = 0;
  background(bgcolor, 255, 255);
  image(logo, 0, 0);
}

you want more show? click

here
PImage logo;        //Creating an object for the image
int bgcolor=0;      //Creating a variable to store the background colour
String mytext="0000000000000000000000000000";
String file = "http://arduino.cc/logo.png";

void setup() {
  size(320, 240);
  background(255);                    // need some INTRO
  fill(0);
  textSize(12);
  text("wait until "+file+" loaded",20,height/2);
  colorMode(HSB, 255);
  logo=loadImage(file);                // load from internet can take a few seconds
  frameRate(10);                       // here is our BEAT
}

void myBackground() {
  bgcolor++;                           // here is our COLOR SHOW
  if (bgcolor > 255 ) bgcolor = 0;
  background(bgcolor, 255, 255);
}

void myHeader() {
  textSize(18);
  String mytextnew = "";
  for ( int i=0;i<mytext.length();i++) {
    int bit = round(random(0,1.1));                     // create a random 1 OR 0
     //println("i "+i+" bit "+bit);
     if ( random(0,1) > 0.2 ) mytextnew += mytext.charAt(i);
     else                     mytextnew += bit;         // and use it with a chance of 20% 
  }
  mytext = mytextnew;                                   // overwrite string
  text(mytext,1,15);                                    // and show as headerline
}

void draw() {
  myBackground();
  myHeader();
  image(logo, 30, 30, width-60, height-60);  // center and scale it ( no problem as we are slow anyhow )
}