Thread: Draw Arc

Results 1 to 10 of 10
  1. #1 Draw Arc 
    Registered Member
    Deku's Avatar
    Join Date
    May 2016
    Posts
    151
    Thanks given
    37
    Thanks received
    121
    Rep Power
    165
    Haven't seen released,



    Code:
    	public static void draw_arc(int x, int y, int width, int height, int stroke, int start, int sweep, int color, int alpha, int closure, boolean fill) {
    		Graphics2D graphics = Sprite.createGraphics(Raster.pixels, Raster.width, Raster.height);
    		graphics.setColor(new Color((color >> 16 & 0xff), (color >> 8 & 0xff), (color & 0xff), ((alpha >= 256 || alpha < 0) ? 255 : alpha)));
    		
    		RenderingHints render = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    		render.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);//fix the 'jittering'
    
    		graphics.setRenderingHints(render);
    		graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
    		if(!fill) {
    			graphics.setStroke(new BasicStroke((stroke < 1 ? 1 : stroke));
    		}
    		//Closure types - OPEN(0), CHORD(1), PIE(2)
    		Arc2D.Double arc = new Arc2D.Double(x + stroke, y + stroke, width, height, start, sweep, closure);
    		if(fill) {
    			graphics.fill(arc);
    		} else {
    			graphics.draw(arc);
    		}
    	}
    Spoiler for Might need:
    In your Sprite class
    Code:
    	private static final ColorModel COLOR_MODEL = new DirectColorModel(32, 0xff0000, 0xff00, 0xff);
    	public static Graphics2D createGraphics(int[] pixels, int width, int height) {
    		return new BufferedImage(
    			COLOR_MODEL, 
    				java.awt.image.Raster.createWritableRaster(COLOR_MODEL.createCompatibleSampleModel(width, height), 
    					new DataBufferInt(pixels, width * height), null), 
    						false, new java.util.Hashtable<Object, Object>()).createGraphics();
    	}
    wut
    Reply With Quote  
     


  2. #2  
    love

    scoob's Avatar
    Join Date
    Oct 2015
    Age
    22
    Posts
    1,641
    Thanks given
    365
    Thanks received
    641
    Rep Power
    1559
    Thanks for contributing to the community! I'm a huge fan of your work : )
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  3. #3  
    Registered Member
    Tamatea's Avatar
    Join Date
    Aug 2010
    Posts
    1,283
    Thanks given
    379
    Thanks received
    334
    Rep Power
    2318
    Awesome man thanks alot

    [Only registered and activated users can see links. ]



    Reply With Quote  
     

  4. #4  
    The Friendly Ghost

    Join Date
    Feb 2015
    Posts
    34
    Thanks given
    21
    Thanks received
    17
    Rep Power
    23
    Thanks a lot, bud.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Deku's Avatar
    Join Date
    May 2016
    Posts
    151
    Thanks given
    37
    Thanks received
    121
    Rep Power
    165
    Quote Originally Posted by Scandi View Post
    Thanks for contributing to the community! I'm a huge fan of your work : )
    Quote Originally Posted by Squxx View Post
    Awesome man thanks alot
    Quote Originally Posted by Caspa View Post
    Thanks a lot, bud.
    No problem!

    Quote Originally Posted by xfukecx View Post
    Can you give the example to use, I can't get the arc to appear
    x, y, width and height are self explanatory

    The example for the gif,
    Code:
    			int stroke = 5;
    			Raster.draw_arc(125, 125, 100, 100, stroke, 0, -(sweep), 65535, 85, 0, false);
    			sweep += 1;
    			if(sweep >= 360) {
    				sweep = 360;
    			}
    start would be the angle you want the sweep to start from,
    sweep is the distance from the start angle (+ and - determine direction)
    stroke is the line thickness




    If ya wanna know more, [Only registered and activated users can see links. ]
    wut
    Reply With Quote  
     

  6. #6  
    Donator


    Join Date
    Dec 2014
    Posts
    374
    Thanks given
    71
    Thanks received
    111
    Rep Power
    164
    Quote Originally Posted by Deku View Post
    No problem!



    x, y, width and height are self explanatory

    The example for the gif,
    Code:
    			int stroke = 5;
    			Raster.draw_arc(125, 125, 100, 100, stroke, 0, -(sweep), 65535, 85, 0, false);
    			sweep += 1;
    			if(sweep >= 360) {
    				sweep = 360;
    			}
    start would be the angle you want the sweep to start from,
    sweep is the distance from the start angle (+ and - determine direction)
    stroke is the line thickness




    If ya wanna know more, [Only registered and activated users can see links. ]
    Yes, I had stroke set to 0 like an idiot haha, anyways thank you so much for this.

    This is what I used it for:
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  7. #7  
    Registered Member

    Join Date
    Jun 2017
    Posts
    169
    Thanks given
    134
    Thanks received
    149
    Rep Power
    293
    Great work as usual, thanks bud!
    [Only registered and activated users can see links. ]

    Check out the Emulous [Only registered and activated users can see links. ]!
    Reply With Quote  
     

  8. #8  
    Registered Member OP411's Avatar
    Join Date
    May 2014
    Posts
    294
    Thanks given
    28
    Thanks received
    31
    Discord
    View profile
    Rep Power
    0
    already released but thanks
    Reply With Quote  
     

  9. #9  
    Registered Member Artemis.Dev's Avatar
    Join Date
    Nov 2017
    Posts
    9
    Thanks given
    0
    Thanks received
    3
    Rep Power
    0
    Thank you for this!

    Our task must be to free ourselves by widening our circle of compassion to embrace all living creatures and the whole of nature and its beauty.
    Reply With Quote  
     

  10. #10  
    Donator

    Join Date
    Sep 2016
    Posts
    132
    Thanks given
    115
    Thanks received
    51
    Rep Power
    62
    Another very useful snippet from Deku, thanks!
    If a man does not have the sauce, then he is lost. But the same man can be lost in the sauce.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Some graphic drawing methods
    By Meanz in forum RS2 Client
    Replies: 0
    Last Post: 02-29-2008, 07:09 PM
  2. My drawings IRL
    By Chimeric in forum Showcase
    Replies: 13
    Last Post: 02-23-2008, 02:50 PM
  3. Drawing basic Rectangles with Java
    By Alex in forum Website Development
    Replies: 7
    Last Post: 01-10-2008, 08:21 PM
  4. Drawing Of Pikachu In MS Paint
    By Zorpha1 in forum Showcase
    Replies: 7
    Last Post: 10-07-2007, 04:15 PM
  5. First rs2 drawing!
    By Saint in forum Showcase
    Replies: 5
    Last Post: 04-02-2007, 07:21 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •