|
Post by u9 on Mar 19, 2007 14:49:14 GMT -5
if possible, it would be nice to be able to draw a filled circle. It would also be nice to be able to draw a non-filled rectangle.
If not, then it would be nice to be able to use floats as radius parameter to graphics.setcircle.
|
|
|
Post by Guilect on Mar 19, 2007 20:00:53 GMT -5
I am tired but, you can't set a pixel at a non integer value, so why would you need the graphics routine to take floating values for the radius?
On the to do list How does graphics.setbox(x1,y1,x2,y2,x3,y3,x4,y4,color) sound for syntax?
I do believe that this would be too slow to be of any practical real time use.
|
|
|
Post by u9 on Mar 20, 2007 3:07:12 GMT -5
I think graphics.setbox should have same syntax as graphics.setrect for consistency. They are almost the same function. Well, the thing with circles is that although when going strictly horizontal or vertical, then yes, you cannot set a pixel at a non-int value. However, going in a direction of 45 degrees the pixel that should be set would be cos(45), sin(45) which if the radius was 1 would be the pixel at 0.7, 0.7. But you are right, it is really not a necessary function. I think all the graphics primitive commands are too slow to be used in real time. They cost too much. What I do is render to a created surface when i initialize the game and load graphics, then use that in the main loop. But i just thought of a way to draw a filled circle, so it is ok
|
|
|
Post by Guilect on Mar 20, 2007 11:40:21 GMT -5
Have not tried it but thinking out loud:
create 2 images leave 1 blank set a square on the other set render target to the blank one draw the square rotated in all 360 degrees onto the blank one
filled circle.
|
|
|
Post by u9 on Mar 22, 2007 11:48:51 GMT -5
Here are some filled-circle routines. SetFilledCircle3 is the fastest. The others just showed how i progressed. Maybe it would be faster if you implement it as a function? anyways, even if it is that slow, I still think you should include it in the graphics object. A filled circle is always useful
graphics.initialize graphics.display
For i = 100 To 100 Step 50 graphics.clear ' Cross-hair graphics.setline 0, 240, 640, 240, argb(255,0,55,255) graphics.setline 320, 0, 320, 480, argb(255,0,55,255) ' Circle routine setfilledcircle3 320, 240, i, argb(255,55,155,55) ' Outlined circle graphics.setcircle 320, 240, i, argb(255,255,255,255) graphics.display system.pause 2000 Next graphics.terminate
' Render a filled circle using setline Sub setfilledcircle0( x, y, r, c ) If r = 0 Then Exit Sub For theta = 0 To pi Step 0.01 dx = round( cos( theta + pi/2 ) * r ) dy = round( sin( theta + pi/2 ) * r ) Call graphics.setline( -dx + x, dy + y, dx + x+1, dy + y, c ) Call graphics.display() Next End Sub
' Only draw once for each horizontal line Sub setfilledcircle1( x, y, r, c ) If r = 0 Then Exit Sub For dy = r To -r Step -1 cosa = (dy-0.5) / r system.debugPrint cosa If cosa >= 1 Or cosa <= -1 Then theta = 0 Else theta = Atn(-cosa / Sqr(-cosa * cosa + 1)) + 2 * Atn(1) End If dx = round( sin( theta ) * r ) Call graphics.setline( -dx + x, dy + y, dx + x+1, dy + y, c ) Call graphics.display() Next End Sub
' Top and bottom of circle are symetrical Sub setfilledcircle2( x, y, r, c ) If r = 0 Then Exit Sub For dy = r To 0 Step -1 cosa = (dy-0.5) / r If cosa = 1 Then theta = 0 Else theta = Atn(-cosa / Sqr(-cosa * cosa + 1)) + 2 * Atn(1) End If dx = round( sin( theta ) * r ) Call graphics.setline( -dx + x, dy + y, dx + x+1, dy + y, c ) Call graphics.setline( -dx + x, -dy + y, dx + x+1, -dy + y, c ) Call graphics.display() Next End Sub
' Fastest. Sides are same as top/bottom rotated 90 degrees. Also the middle of the circle is just a box Sub setfilledcircle3( x, y, r, c ) Dim boxlimit boxlimit = round(r * 0.70710678) ' This is cos to 45 degrees multiplied with radius If r = 0 Then Exit Sub ' Loop from top of radius down to the box limit For dy = r To boxlimit Step -1 ' Take inverse cos of adjacent/hyptonuse (gives oposite side of right triangle) cosa = (dy-0.5) / r ' -0.5 is so we find the angle at the edge before the pixel changes to then next line If cosa = 1 Then theta = 0 ' Safety as the inverse cos below doesn't like the cosa to be 1 Else theta = Atn(-cosa / Sqr(-cosa * cosa + 1)) + 2 * Atn(1) ' 2*Atn(1) can be defined as a constant for speed End If dx = round( sin( theta ) * r ) ' Render horizontal lines (bottom is symetrical to top) Call graphics.setline( -dx + x, dy + y, dx + x+1, dy + y, c ) Call graphics.setline( -dx + x, -dy + y, dx + x+1, -dy + y, c ) ' Render vertical lines (the sides are equal to the top/bottom rotated 90 degrees) Call graphics.setline( -dy + x, -dx + y, -dy + x, dx + y+1, c ) Call graphics.setline( dy + x, -dx + y, dy + x, dx + y+1, c ) Call graphics.display() Next ' Finally render the inside of the circle Call graphics.setrect( x-boxlimit, y-boxlimit, boxlimit * 2, boxlimit * 2, c ) End Sub
|
|
|
Post by u9 on Apr 5, 2007 4:07:20 GMT -5
Just a heads-up. My poor filled circle rutine above doesn't work for all resolutions it seems... (or it could just be my broken gfx card )... I'll look into this when i get back in a week or two.
|
|