Joe Parks
Posts: 107
Nickname: joeparks
Registered: Aug, 2003
|
|
Re: Graphics 2D sprayPaint stroke/brush needed
|
Posted: Oct 6, 2003 3:52 AM
|
|
There is a painting applet, including source, at http://javaboutique.internet.com/Childs_Paint/
If you download and unzip "paint.zip", take a look at the spray() method in DrawPanel .
//spray uses Math.random() to get a random set of pixels within a radius coloured in
public void spray(int x, int y){
Graphics2D g2 = currentImage.createGraphics();
g2.setPaint(drawColor);
for (i=0; i<35; i++){
// use static final ints now
tempx = (x + (int) Math.round(2*SMALL_OFFSET*(Math.random() -0.5)));
tempy = (y + (int) ( ((Math.random()-0.5)*2) * Math.sqrt(
(SMALL_OFFSET * SMALL_OFFSET) - ((x - tempx) * (x - tempx)))));
g2.drawLine(tempx, tempy, tempx, tempy);
}
for (i=0; i<12; i++){
tempx = (x + (int) Math.round(2*BIG_OFFSET*(Math.random() -0.5)));
tempy = (y + (int) ( ((Math.random()-0.5)*2) * Math.sqrt(
(BIG_OFFSET * BIG_OFFSET) - ((x - tempx) * (x - tempx)))));
g2.drawLine(tempx, tempy, tempx, tempy);
}
repaint();
}
|
|