رسم کمان در b4a:
جمعه, ۱۶ مرداد ۱۳۹۴، ۰۷:۰۴ ب.ظ
منبع :gameover.blog.ir
منبع :
http://www.b4x.com/android/forum/threads/trigonometric-circle.8547/#post48013
ابتدا یک روال(sub) به نام DrawArc برای رسم کمان می نویسیم :
کد:
Sub DrawArc(xc As Float, yc As Float, r As Float, a1 As Float, a2 As Float, col As Int, Strike As Float)
' The routine draws always in the trigonometric direction (counter clockwise) from angle a1 to a2
'a1=start angle
'a2=end angle
'col=color
'xc,yc=(x,y)
'r=radius
'strike=stroke width = border
Dim x1, y1, x2, y2 As Float
Dim da, a As Float
' da=260/r ' calculates the angle interval As a function of the radius
' da=250/r
da=1000/r
If a2<a1 Then
a2=a2+360
End If
x1=xc+r*CosD(a1)
y1=yc-r*SinD(a1)
cvsMain.DrawLine(x1,y1,xc,yc,col,Strike) ' draws the radius
For a = a1+da To a2 Step da
x2=xc+r*CosD(a)
y2=yc-r*SinD(a)
cvsMain.DrawLine(x1,y1,x2,y2,col,Strike)
x1=x2
y1=y2
Next
x2=xc+r*CosD(a2)
y2=yc-r*SinD(a2)
cvsMain.DrawLine(x1,y1,x2,y2,col,Strike) ' draws the last segment
cvsMain.DrawLine(x2,y2,xc,yc,col,Strike) ' draws the radius
End Sub
کد:
Sub Activity_Create(FirstTime As Boolean)
cvsMain.Initialize(Activity)
DrawArc(x0,y0,100dip,80,350,Colors.Red,1dip)
' DrawArc(x0-30dip,y0,90dip,80,350,Colors.Red,1dip)
DrawArc(x0+40dip,y0+40dip,100dip,80,350,Colors.Red,2dip)
DrawArc(x0,y0+180dip,100dip,80,359,Colors.Green,1dip)
DrawArc(x0+40dip,y0+200dip,100dip,80,1,Colors.Green,1dip)
End Sub
'angle a1 to a2
'a1=start angle
'a2=end angle
'col=color
'xc,yc=(x,y)
'r=radius
'strike=stroke width = border
'a1=start angle
'a2=end angle
'col=color
'xc,yc=(x,y)
'r=radius
'strike=stroke width = border
دو پارامتر اول x و y هست.
A1 :درجه یا زاویه شروع
A2 : زاویه ی پایان کمان
Col:رنگ رسم کمان
R : شعاع دایره ی کمان
Strike: ضخامت کمان
اینم سورس آماده :
http://s3.picofile.com/file/8204828918/DrawArc.zip.html
خرید آموزش b4a فارسی با قیمت کم:
http://gameover.blog.ir/1395/04/03/%DA%A9%D8%AA%D8%A7%D8%A8-%D9%81%D8%A7%D8%B1%D8%B3%DB%8C-%D8%A7%D9%85%D9%88%D8%B2%D8%B4-b4a-%D8%B3%D8%A7%D8%AE%D8%AA-%DA%AF%DB%8C%D9%85-%D8%A2%D9%88%D8%B1
۹۴/۰۵/۱۶