Desenhando Círculos em NCL/Lua

December 11, 2009

Implementei uma função que permite desenhar circulos com o Canvas para NCL/Lua

Função


function desenharCirculo ( X0 , Y0 , raio , mode )
function converterGrau2Rad ( x )
return ( x / 180 ) * math.pi
end

local tblPt = {}

if mode ~= ‘fillthen
mode = ‘frame
end

for i=0, 360 do
local x = (raio * math.cos(converterGrau2Rad(i)))
local y = (raio * math.sin(converterGrau2Rad(i)))

if mode == ‘framethen
tblPt[i] = {}
table.insert(tblPt[i],X0 – x)
table.insert(tblPt[i],Y0 – y)
end

if mode == ‘fillthen
canvas:drawLine (X0, Y0, X0 – x, Y0 – y)
end

end

if mode == ‘framethen

for i=0, table.maxn(tblPt) do

if i == table.maxn(tblPt) then
canvas:drawLine (tblPt[i][1], tblPt[i][2], tblPt[0][1], tblPt[0][2])
else
canvas:drawLine (tblPt[i][1], tblPt[i][2], tblPt[i+1][1], tblPt[i+1][2])
end

end

end

end

A chamada para a função é a seguinte:

canvas:attrColor(96, 181, 255, 255)
desenharCirculo ( 250 , 250 , 20 , ‘frame’ )
canvas:flush()

Parâmetros
A função trabalha com quatro parâmetros, são eles:
X0: A coordenada X do ponto central.
Y0: A coodenada Y do ponto central.
Raio: O tamanho do raio do círculo.
Mode: É o tipo de desenho que será feito. Se escolhido frame, será desenhado apenas a moldura. Se for escolhido fill o desenho será preenchido. O modo frame é utilizado como default.

Problemas
Nem tudo na vida é perfeito e esta função não seria diferente. Quando desenhamos um círculo com mode fill e raio muito grande, vemos algumas falhas. Se alguém conseguir solucionar o problema, escreva nos comentários que a função será atualizada e dado os devidos créditos. :)

43 Responses to “Desenhando Círculos em NCL/Lua”

  1. o problema com certeza está aki "for i=0, 360 do" com passo 1 vc vai pegar so as posições de grau exato, e qdo vc aumenta muito o pixel do grau exato não vai cobrir todo espaço necessário, então ou vc diminui o passo para 0,1 para pegar mais posições ou limita um raio maximo ..

  2. Marcelo você está completamente certo.

    A partir do momento que eu vario o passo do for, aumento a precisão.

    Quando maior a precisão, melhor o resultado final, maior o processamento.

    Eu inclui uma atualização desta função no meu site pessoal: http://luizeduardoaraujo.info/?p=277

    [[]]'s

  3. This info is worth everyone’s attention. When can I find out more?|

  4. I am actually grateful to the holder of this web page who has shared this fantastic article at at this time.|

  5. Hi, i think that i saw you visited my web site so i came to “return the favor”.I am attempting to find things to enhance my web site!I suppose its ok to use some of your ideas!!|

  6. Hi there to all, how is the whole thing, I think every one is getting more from this web page, and your views are pleasant in favor of new users.|

  7. I simply couldn’t go away your site prior to suggesting that I actually enjoyed the usual info a person supply for your guests? Is going to be again incessantly to investigate cross-check new posts|

  8. Truly when someone doesn’t understand after that its up to other people that they will help, so here it happens.|

  9. Hello my loved one! I wish to say that this post is amazing, great written and come with almost all significant infos. I¡¦d like to look extra posts like this .

  10. Hello! Would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would really appreciate your content. Please let me know. Thanks|

  11. When someone writes an piece of writing he/she keeps the idea of a user in his/her brain that how a user can understand it. So that’s why this paragraph is great. Thanks!|

  12. Many of us extended the visible profile associated with licensed manufacturers together with men’s as well as ladies’ panties licenses intended for Columbia Sportswear, some sort of sleepwear and intimates licenses pertaining to Juicy Couture, and also a unique license pertaining to The puma company sportswear brand name merchandise inside Israel – tending to give rise to our own expansion prospective inside future years.

  13. Wonderful blog! I found it while browsing on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Appreciate it|

  14. Hello There. I found your blog using msn. This is a very well written article. I will make sure to bookmark it and return to read more of your useful info. Thanks for the post. I’ll certainly comeback.|

  15. What’s up, I log on to your new stuff regularly. Your writing style is witty, keep it up!|

  16. I’m now not positive where you are getting your information, but good topic. I must spend some time studying much more or working out more. Thank you for wonderful information I used to be looking for this info for my mission.|

  17. We’re a group of volunteers and starting a new scheme in our community. Your site provided us with valuable info to work on. You have done a formidable job and our entire community will be thankful to you.

  18. I’m still learning from you, but I’m trying to achieve my goals. I absolutely love reading everything that is written on your website.Keep the information coming. I loved it!

  19. Hey would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 completely different browsers and I must say this blog loads a lot faster then most. Can you suggest a good web hosting provider at a honest price? Kudos, I appreciate it!|

  20. Wow! Thank you! I continually wanted to write on my blog something like that. Can I implement a portion of your post to my blog?

  21. I have been reading out a few of your posts and i can claim pretty nice stuff. I will make sure to bookmark your site.

  22. It’s a shame you don’t have a donate button! I’d certainly donate to this fantastic blog! I guess for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to brand new updates and will talk about this blog with my Facebook group. Chat soon!

  23. Great remarkable things here. I¡¦m very happy to see your post. Thanks a lot and i am taking a look forward to touch you. Will you kindly drop me a mail?

  24. It is really a great and helpful piece of information. I am glad that you shared this helpful info with us. Please stay us informed like this. Thank you for sharing.

  25. There is evidently a bundle to know about this. I feel you made certain nice points in features also.

  26. Hello my friend! I wish to say that this post is amazing, great written and come with approximately all important infos. I would like to peer extra posts like this .

  27. You made a number of nice points there. I did a search on the theme and found nearly all folks will go along with with your blog.

  28. Unquestionably believe that which you said. Your favorite reason seemed to be on the net the easiest thing to be aware of. I say to you, I certainly get irked while people consider worries that they just don’t know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks

  29. What i don’t realize is in reality how you’re not really a lot more smartly-preferred than you might be right now. You’re so intelligent. You realize therefore considerably with regards to this subject, produced me in my view believe it from so many varied angles. Its like men and women are not involved except it¡¦s one thing to do with Lady gaga! Your own stuffs great. All the time deal with it up!

  30. Good day very cool site!! Man .. Excellent .. Amazing .. I’ll bookmark your website and take the feeds additionally¡KI am glad to find a lot of useful info right here in the submit, we’d like develop more techniques on this regard, thank you for sharing. . . . . .

  31. Hiya, I am really glad I have found this information. Today bloggers publish just about gossips and net and this is really annoying. A good website with interesting content, that is what I need. Thank you for keeping this web site, I will be visiting it. Do you do newsletters? Can’t find it.

  32. I precisely desired to appreciate you all over again. I am not sure the things that I could possibly have tried in the absence of the actual solutions shared by you relating to such topic. It previously was a very horrifying concern in my view, but looking at a skilled manner you managed it forced me to jump over contentment. I’m grateful for this support and as well , hope that you really know what a powerful job you’re getting into training other individuals through the use of your web page. More than likely you haven’t got to know any of us.

  33. hello!,I really like your writing so so much! percentage we keep in touch more about your article on AOL? I need an expert on this space to unravel my problem. May be that is you! Having a look forward to see you.

  34. You made certain fine points there. I did a search on the subject and found mainly people will have the same opinion with your blog.

  35. I cherished as much as you will obtain performed right here. The cartoon is tasteful, your authored material stylish. however, you command get got an nervousness over that you want be turning in the following. sick undoubtedly come more beforehand again as exactly the same just about very frequently within case you defend this increase.

  36. Quality content is the main to interest the visitors to go to see the web page, that’s what this site is providing.

  37. I really like the whole post. Many thanks for giving this excellent tips. I am excited now and going to check out old posts.

  38. Thank you, I’ve recently been looking for information approximately this topic for a while and yours is the greatest I’ve discovered so far. However, what concerning the conclusion? Are you certain concerning the source?

  39. Hey there, You’ve performed a great job. I’ll definitely digg it and in my view recommend to my friends. I am confident they’ll be benefited from this website.

  40. Hello.This article was really remarkable, especially since I was searching for thoughts on this topic last week.

  41. whoah this blog is great i love reading your articles. Keep up the great work! You realize, many persons are searching around for this info, you can help them greatly.

  42. Nice blog right here! Also your site so much up fast! What host are you using? Can I am getting your associate link for your host? I desire my website loaded up as quickly as yours lol

  43. Valuable info. Fortunate me I found your site unintentionally, and I’m stunned why this accident did not took place in advance! I bookmarked it.

Leave a Reply