Ooops
November 28, 2020, 02:02:05 PM

Author Topic: [bb] Get Area Of Circle by Polarix [ 3 months ago ]  (Read 380 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Get Area Of Circle by Polarix [ 3 months ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : Get Area Of Circle
Author : Polarix
Posted : 3 months ago

Description : Returns the area of an oval.

Code :
Code: BlitzBasic
  1. Graphics 640,480
  2. SetBuffer BackBuffer()
  3.  
  4. Global xpos = 320
  5. Global ypos = 240
  6. Global size# = 100
  7. Global radius# = size/2
  8.  
  9. While Not KeyHit(1)
  10.         Cls
  11.        
  12.         Oval xpos,ypos,size,size
  13.         Text 0,0,"The area of the circle is "+GetCircleArea(radius#)+" pixels" 
  14.        
  15.         Flip
  16. Wend
  17. End
  18.  
  19. Function GetCircleArea(r#)
  20.         Return(r#*r#*Pi)
  21. End Function


Comments :


Kryzon(Posted 3 months ago)

 [Corrected]


Polarix(Posted 3 months ago)

 Oops. My bad, thanks for telling me!


TomToad(Posted 3 months ago)

 No need to pass x and y to the function since they never get used


Matty(Posted 2 months ago)

 Is Pi a defined constant in blitz. .. i didnt think it was....this will return zero


Matty(Posted 2 months ago)

 Also the function will only return an integer.


TomToad(Posted 2 months ago)

 Pi is defined as 3.14159 in Blitz3D.


Polarix(Posted 2 months ago)

 <div class="quote">  Also the function will only return an integer.  </div> Pixels cannot be halfed or cut into smaller bits. so it will always be a whole number of pixels.


Polarix(Posted 2 months ago)

 <div class="quote">  Is Pi a defined constant in blitz. .. i didnt think it was....this will return zero  </div>I checked the example. It works fine for me.


Kryzon(Posted 2 months ago)

 You're right, pixels are always at integral coordinates.Still, in some cases it's useful to work with floating point coordinates because then you have sub-pixel coverage: a graphic covers "part" of the pixel, so the pixel is semitransparent. This is how some software do antialiased graphics.


Floyd(Posted 2 months ago)

 <div class="quote"> Pixels cannot be halfed or cut into smaller bits. so it will always be a whole number of pixels.  </div>The point of the comment about the function returning an integer is that it computes a floating point value but returns an integer.The fact that the number of pixels is an integer is not really relevant. GetCircleArea is not counting pixels and will match the number of pixels drawn only by coincidence.For example, with width = height = 8 GetCircleArea returns 50 when the actual number of pixels is 52.


Polarix(Posted 1 month ago)

 I don't get what you are saying, it works fine


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal