We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › draw image from class
Page Index Toggle Pages: 1
draw image from class (Read 763 times)
draw image from class
Dec 29th, 2009, 3:13pm
 
How can i use a class to draw a image now it says:

Quote:
The file "AB.jpg" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.


But the file is there, i can draw it to the sketch the normal way, I only can't figure out how to do it with a class.

Code:
import processing.opengl.*;
import peasy.*;

PeasyCam cam;

Grid grid1 = new Grid("AB.jpg");


void setup(){
size(600, 600, OPENGL);
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(300);
cam.setMaximumDistance(500);

smooth();
}


void draw(){
background(255,0,0);
grid1.drawGrid();
translate(300, 300, 0);
}


class Grid {
PImage side1;

Grid(String s1){//side1

side1 = loadImage(s1);

}
void drawGrid(){
fill(0, 30);
box(10, 10, 10);
//image(side1, 0, 0);
}
}

Re: draw image from class
Reply #1 - Dec 29th, 2009, 3:23pm
 
Your Grid Object must be initialized in the setup() function:

Quote:
import processing.opengl.*;
import peasy.*;

PeasyCam cam;

Grid grid1;


void setup(){
  size(600, 600, OPENGL);
  cam = new PeasyCam(this, 100);
  cam.setMinimumDistance(300);
  cam.setMaximumDistance(500);
  grid1 = new Grid("AB.jpg"); // here, not before setup()
  smooth();
}


void draw(){
  background(255,0,0);
  grid1.drawGrid();
  translate(300, 300, 0);
}


class Grid {
  PImage side1;

  Grid(String s1){//side1
     side1 = loadImage(s1);
  }
  void drawGrid(){
    fill(0, 30);  
    box(10, 10, 10);
    image(side1, 0, 0);
  }
}




that's it Smiley
Re: draw image from class
Reply #2 - Dec 29th, 2009, 3:38pm
 
thx for the fast reply!

now i can continue instand of going to sleep Smiley
Re: draw image from class
Reply #3 - Dec 30th, 2009, 8:10pm
 
It's great to be helpful! Smiley
Page Index Toggle Pages: 1