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 › Re: Help with graph style drawing
Page Index Toggle Pages: 1
Re: Help with graph style drawing (Read 1516 times)
Re: Help with graph style drawing
May 6th, 2009, 12:39am
 
there are infinite ways of doing it Smiley

for example you could draw directly the needed pixels
Code:
loadPixels();
for(int i=start; i<end; i++){
for(int j=start1; j<end1; j++){
pixels[j*width+i]=mycolor;
}
}
updatePixels();


or write a custom block class, which is probably the best way iin most scenarios.
Re: Help with graph style drawing
Reply #1 - May 7th, 2009, 3:27am
 
did you read the reference page

the pixels of an image are stored into an array called pixels[]; to access the pixel at position x,y you'll have to write into pixels[y*width+x].

if you still have doubts, you could maybe ask a scenario specific question Smiley
Re: Help with graph style drawing
Reply #2 - May 7th, 2009, 5:11am
 
Although he mentioned the idea of drawing pixels for your graph. I would definetly go with the rect... should be much easier.
Maybe you can post an example pic or something...
Re: Help with graph style drawing
Reply #3 - May 7th, 2009, 7:14am
 
Well, as you guessed, use line() to draw the grid and then rect() on the right coordinates to draw the blocks.
Re: Help with graph style drawing
Reply #4 - May 7th, 2009, 10:15am
 
i dont get why you want to assign more than one coordinate to a point?
That doesnt make a lot of sense to me. How should the result look like?
Re: Help with graph style drawing
Reply #5 - May 7th, 2009, 11:14am
 
Sorry, not coordinate to a point.

I mean I have a square, i would like to put that same square in other places without using loads of markup. I'm guessing this isn't possible though.
Re: Help with graph style drawing
Reply #6 - May 7th, 2009, 11:41am
 
i made up a quick sketch, hope that helps to understand

int gridSize = 20;

void setup() {
 size(400,600);
 background(255);
 smooth();
 noFill();
 stroke(120,100);

 //the grid
 for (int i = 0; i <width; i+=gridSize) {
   for (int j = 0; j < height; j+=gridSize) {
     rect(i,j,gridSize,gridSize);
   }
 }
}  


void draw(){

//drawing the bars with a given position, value and color
bar(2,5,color(#ff0000));
bar(4,3,color(#ffff00));
bar(6,8,color(#0000ff));


}


void bar(int pos, int value, color c){
   for (int i = 0; i <value; i++) {
   fill(c);
   rect(gridSize*pos, (height-gridSize)-(gridSize*i),gridSize,gridSize);
 }
}
Page Index Toggle Pages: 1