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 & HelpPrograms › Drawing brushstrokes onto PGraphics - not working.
Page Index Toggle Pages: 1
Drawing brushstrokes onto PGraphics - not working. (Read 875 times)
Drawing brushstrokes onto PGraphics - not working.
Mar 14th, 2010, 3:31pm
 
Hi everyone,

I've written a brush class which simulates a brushstroke (in a basic way). I need to be able to make these brushstrokes in a PGraphics buffer, but I can't seem to get it to work....

code here: http://pastebin.ca/1840461

I wrote the program below as a simple model - just drawing a rectangle instead of something more complicated....and this does work......what is the difference

Code:
PGraphics pg;
rectangle r;


void setup()
{
size(300,300);
pg=createGraphics(width,height,P2D);
r = new rectangle(100, 100, 50, 60, PI/8, color(100, 200, 100));

pg.beginDraw();
r.render();
pg.endDraw();

image(pg, 0, 0);
}

void draw()
{

}

class rectangle
{
float x,y,w,h;
float angle;
color c;

rectangle(float x, float y, float w, float h, float angle, color c)
{
this.x=x;
this.y=y;
this.w=w;
this.h=h;
this.angle=angle;
this.c=c;
}

void render()
{
pg.rectMode(CENTER);
pg.fill(c);
pg.pushMatrix();
pg.translate(x, y);
pg.rotate(angle);
pg.rect(x,y,w,h);
pg.popMatrix();
}
}


Re: Drawing brushstrokes onto PGraphics - not working.
Reply #1 - Mar 15th, 2010, 6:56am
 
try to change it to
 pg=createGraphics(width,height,JAVA2D);
instead of P2D
is that what you want ?
Re: Drawing brushstrokes onto PGraphics - not working.
Reply #2 - Mar 15th, 2010, 10:35am
 
Yes, thanks. Why does that make a difference?

(I thought it didn't work properly at first, but I'd forgotten to put in pg.smooth() which makes the brushstroke look much nicer).
Page Index Toggle Pages: 1