The Artima Developer Community
Sponsored Link

Java Answers Forum
Graphics 2D sprayPaint stroke/brush needed

1 reply on 1 page. Most recent reply: Oct 6, 2003 3:52 AM by Joe Parks

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
ArcherDaPunk

Posts: 2
Nickname: archer
Registered: Oct, 2003

Graphics 2D sprayPaint stroke/brush needed Posted: Oct 5, 2003 10:41 PM
Reply to this message Reply
Advertisement
hi,
I'm trying to make a a stroke or brush similar to a spray can. What would be the easiest way to do this? Is it a texture job or can it be done with java.awt.strokes?

Thanks,
Archer


Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: Graphics 2D sprayPaint stroke/brush needed Posted: Oct 6, 2003 3:52 AM
Reply to this message Reply
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();
	}

Flat View: This topic has 1 reply on 1 page
Topic: Need help on masking Previous Topic   Next Topic Topic: Struts Validator,Tag libraries!! help needed

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use