Sircle Segment

Hi

Does any one know how you can draw a circle segment whos angle can change dynamicaly?

Thanks in advance

No option for partial circle. You would have to use image and rotate it as you wish

Thank you

I have partially solved the problem. I draw a line and then a rotate it. The code goes sth like this
[lua] local w=0[/lua]
[lua] local lines={}[/lua]
[lua] for i=1,200 do[/lua]
[lua] lines[i]=display.newLine(xstart,ystart,xend,yend)[/lua]
[lua] lines[i].rotation=w+i[/lua]
[lua] end[/lua]
The problem is that the segment of the circle that is being created doesn’t have a uniform color. So I came up with the following idea. The cordinates of a point in the plane can be expressed using polar cordinates as
(xp,yp)=(radius*cos(θ), radius*sin(θ)) so if you want to draw a segment of a circle with radius let’s say 2 and angle 30 degrees then you have to let the radius span from 0 to 2 and the angle θ from 0 to 30. So my question is can you draw in lua a specific pixel? I think that with this approach it will be feasible to draw circle segments when users dragging finger.

No, you cannot. What you try to do is low-level stuff and it’s rather hidden under Corona api (meaning you have no access to it if there is). If you would like to draw circle using lines then you can do it but I bet it would be performance insufficient.

Thank you piotrz55. One last question If a make an image with 1x1 pixel could it be possible to follow the procedure I described ?

Workaround but for me totaly performance drop. But I have suggestion. If circle can be image then I would create 2 imgs for two halfes then draw them and insert into one group to get full circle. Next I would create image which is black and in shape of half circle and size like your other halves. Then I would load this twice as masks for each circle half.

When you change angle of part of circle to be visible then if angle is between 0 and 180 degrees then make second half invisible and rotate first mask. When over 180 then make first half fully visible and rotate second mask.

No option for partial circle. You would have to use image and rotate it as you wish

Thank you

I have partially solved the problem. I draw a line and then a rotate it. The code goes sth like this
[lua] local w=0[/lua]
[lua] local lines={}[/lua]
[lua] for i=1,200 do[/lua]
[lua] lines[i]=display.newLine(xstart,ystart,xend,yend)[/lua]
[lua] lines[i].rotation=w+i[/lua]
[lua] end[/lua]
The problem is that the segment of the circle that is being created doesn’t have a uniform color. So I came up with the following idea. The cordinates of a point in the plane can be expressed using polar cordinates as
(xp,yp)=(radius*cos(θ), radius*sin(θ)) so if you want to draw a segment of a circle with radius let’s say 2 and angle 30 degrees then you have to let the radius span from 0 to 2 and the angle θ from 0 to 30. So my question is can you draw in lua a specific pixel? I think that with this approach it will be feasible to draw circle segments when users dragging finger.

No, you cannot. What you try to do is low-level stuff and it’s rather hidden under Corona api (meaning you have no access to it if there is). If you would like to draw circle using lines then you can do it but I bet it would be performance insufficient.

Thank you piotrz55. One last question If a make an image with 1x1 pixel could it be possible to follow the procedure I described ?

Workaround but for me totaly performance drop. But I have suggestion. If circle can be image then I would create 2 imgs for two halfes then draw them and insert into one group to get full circle. Next I would create image which is black and in shape of half circle and size like your other halves. Then I would load this twice as masks for each circle half.

When you change angle of part of circle to be visible then if angle is between 0 and 180 degrees then make second half invisible and rotate first mask. When over 180 then make first half fully visible and rotate second mask.

Works like a charm, thank you Piotrz55 for the hint !

Works like a charm, thank you Piotrz55 for the hint !