How to draw an arc?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
prototypez
Prole
Posts: 14
Joined: Wed Jul 21, 2010 8:17 pm

How to draw an arc?

Post by prototypez »

This question has probably been asked a thousand times, but what is the best way to draw an arc? I don't see a standard method for drawing one on the module wiki, so I thought I might ask here...
I love dashes... -- omnomnomnom oishii desu!
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: How to draw an arc?

Post by TechnoCat »

If it is an arc as part of a circle. Using scissor with circle will do just fine.
http://love2d.org/wiki/love.graphics.setScissor
http://love2d.org/wiki/love.graphics.circle
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How to draw an arc?

Post by Robin »

TechnoCat wrote:If it is an arc as part of a circle. Using scissor with circle will do just fine.
http://love2d.org/wiki/love.graphics.setScissor
http://love2d.org/wiki/love.graphics.circle
Oh, that's a good idea! I usually build a polygon with cos and sin and then draw that.
Help us help you: attach a .love.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: How to draw an arc?

Post by zac352 »

What about bezier curves? You can't really use circles for that.

Here's a simple non-linear equation drawing example:

Code: Select all

function f(x) --Squirrel ftw. :O local f=@(x) x^2+2*x+3
return x^2 + 2*x + 3 --Edit: I forgot that Lua nor Squirrel do "2x". 2*x, yes.
end
for i=1,1000 do
love.graphics.line(i-1,f(i-1),i,f(i))
end
Hello, I am not dead.
User avatar
prototypez
Prole
Posts: 14
Joined: Wed Jul 21, 2010 8:17 pm

Re: How to draw an arc?

Post by prototypez »

Thank you for the tips! They help out a lot. This place really is too friendly... :ultrahappy:
I love dashes... -- omnomnomnom oishii desu!
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: How to draw an arc?

Post by Ryne »

prototypez wrote:Thank you for the tips! They help out a lot. This place really is too friendly... :ultrahappy:
Dude, were called the "LÖVE" forums. Of course we're friendly. :)
@rynesaur
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: How to draw an arc?

Post by TechnoCat »

Welcome to Costco. I love you.
User avatar
prototypez
Prole
Posts: 14
Joined: Wed Jul 21, 2010 8:17 pm

Re: How to draw an arc?

Post by prototypez »

So, I actually got off my lazy bottom(okay, sat on my lazy bottom) and wrote out a arc-drawing module... I'm posting it in it's rather fragile and unstable form for comments, as this is my first public bit of LOVE programming... I used quads to interpolate arcs that can be either like a pie chart or like a true arc. Next additions will be elliptical arcs.

Usage is as follows:

arcchart = org.theflameimperishable.love.ArcChart({

x = --center of chart--,
y = --center of chart--,
innerradius = --radius of inner circle--,
outerradius = --outside radius--,
segments = --requested number of segments--

})

Draw in the love.draw() cycle with:

arcchart:drawSegments(startsegment, endsegment) -- for particular segments
arcchart:drawDegrees(startdegrees, enddegrees) -- for arc in degrees(yeah yeah, I'm not a math major so I don't like rads, don't yell at me!)

Also, just calling arcchart:draw() draws the stored segment dictated by member variables arcchart.startsegment and arcchart.endsegment, and these can be either set directly(gritting teeth because field hiding has been ingrained in me since the Java days...) or calling arcchart:increment(), arcchart:decrement(), and arcchart:reset(), all of which accept values as well.

I'd be interested in comments if anybody needs such a thing. Also, as it uses quads, I used lookup tables for all of the values, but this can be turned off if the arcs need to be zoomed or moved dynamically, just set the precomputed bool value in the object to false. I haven't seen a huge performance difference between the two, any ideas about that out there?
Attachments
arcchart.lua
an arc drawing library
(10.17 KiB) Downloaded 193 times
I love dashes... -- omnomnomnom oishii desu!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How to draw an arc?

Post by Robin »

prototypez wrote:org.theflameimperishable.love.ArcChart
Where does that come from? Java? :cry:
prototypez wrote:(gritting teeth because field hiding has been ingrained in me since the Java days...)
OMG, I was right! :(

But anyway, I should definitely take a look at it. This should be some useful shit.
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: How to draw an arc?

Post by kikito »

prototypez wrote:

Code: Select all

if (not org) then
	org = {}
end
if (not org.theflameimperishable) then
	org["theflameimperishable"] = {}
end
if (not org.theflameimperishable.love) then
	org.theflameimperishable["love"] = {}
end

org.theflameimperishable.love["ArcChart"] = {}

--Begin ArcChart namespace

do
You could do the same like this:

Code: Select all

 org = org or {}
org.theflameimperisable = org.theflameimperisable or {}
org.theflameimperishable.love = org.theflameimperishable.love or {}
org.theflameimperishable.love.ArchChart = org.theflameimperishable.love.ArchChart or {}

do
...
Or you could use the built-in module function in two lines:

Code: Select all

module('org.theflameimperishable.love.ArchChart', package.seeall) -- creates the tables automatically
-- everything declared from here on is inside the org.theflameimperishable.love.ArchChart module.
Some people don't like that though.
prototypez wrote:(gritting teeth because field hiding has been ingrained in me since the Java days...)
I'm so sorry for you.

Learning Ruby on Rails will purify you, given enough time.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 10 guests