Android Question Perfect ratio in graphics ?

syncmaster13

Member
Licensed User
Longtime User
HI

I’ve been reading about how to handle different screen sizes and trying, and trying to draw a perfect bolt circle pattern. In my example there is a circle drawn using “canvas1.DrawCircle” which is always perfect round. Along this circle there is 36 little circles calculated using equal angles between them and they should appear exactly on black circle. Unfortunately it doesn’t work, The “Y” axis is always stretch or shrink. I try to use “getDeviceLayoutValues” to calculate ratio between x axis and y but it is not still perfect. Any idea how to make this work?


Thank You
 

Attachments

  • b_CIrcle_p.zip
    7.5 KB · Views: 242

Erel

B4X founder
Staff member
Licensed User
Longtime User
upload_2013-10-3_8-51-51.png


B4X:
Sub Globals
   Dim Panel1 As Panel   
   Dim Canvas1 As Canvas
  Dim NumberOfCircles As Int = 36
End Sub

'=============================================================

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Bolt_Circle")
   Canvas1.Initialize(Panel1)   
   Dim radius As Float = 40%x
   Canvas1.DrawCircle(50%x, 50%y, radius, Colors.Black, False, 1dip)   
   Canvas1.DrawLine(5%x,50%y, 95%x, 50%y, Colors.Black, 1dip )
   Canvas1.DrawLine(50%x,18%y, 50%x, 82%y, Colors.Black, 1dip )
   For i = 0 To NumberOfCircles - 1
     Dim angle As Float = i * 360 / NumberOfCircles
     Dim x As Int = 50%x + radius * CosD(angle)
     Dim y As Int = 50%y + radius * SinD(angle)
     Canvas1.DrawCircle(x, y, 2%x, Colors.Red, False, 2dip)
   Next
   Panel1.Invalidate
End Sub
 
Upvote 0

syncmaster13

Member
Licensed User
Longtime User
Thank You

As always it works but I have to admit that I’m still confused about x and y values. It seems the equation I used to calculate those values apply only to real world. I have a simple app that display x and y without graphic representation (just as a table) and all coordinates are correct. As I understand by using (%x, %y) everything has to be change.
 
Upvote 0
Top