How to draw an arc?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- prototypez
- Prole
- Posts: 14
- Joined: Wed Jul 21, 2010 8:17 pm
How to draw an arc?
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!
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: How to draw an arc?
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
http://love2d.org/wiki/love.graphics.setScissor
http://love2d.org/wiki/love.graphics.circle
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to draw an arc?
Oh, that's a good idea! I usually build a polygon with cos and sin and then draw that.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
Help us help you: attach a .love.
Re: How to draw an arc?
What about bezier curves? You can't really use circles for that.
Here's a simple non-linear equation drawing example:
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.
- prototypez
- Prole
- Posts: 14
- Joined: Wed Jul 21, 2010 8:17 pm
Re: How to draw an arc?
Thank you for the tips! They help out a lot. This place really is too friendly...
I love dashes... -- omnomnomnom oishii desu!
Re: How to draw an arc?
Dude, were called the "LÖVE" forums. Of course we're friendly.prototypez wrote:Thank you for the tips! They help out a lot. This place really is too friendly...
@rynesaur
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: How to draw an arc?
Welcome to Costco. I love you.
- prototypez
- Prole
- Posts: 14
- Joined: Wed Jul 21, 2010 8:17 pm
Re: How to draw an arc?
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?
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 189 times
I love dashes... -- omnomnomnom oishii desu!
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to draw an arc?
Where does that come from? Java?prototypez wrote:org.theflameimperishable.love.ArcChart
OMG, I was right!prototypez wrote:(gritting teeth because field hiding has been ingrained in me since the Java days...)
But anyway, I should definitely take a look at it. This should be some useful shit.
Help us help you: attach a .love.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: How to draw an arc?
You could do the same like this: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
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
...
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.
I'm so sorry for you.prototypez wrote:(gritting teeth because field hiding has been ingrained in me since the Java days...)
Learning Ruby on Rails will purify you, given enough time.
When I write def I mean function.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests