Actionscript Linestyle سماكة لملء الدائرة
-
30-09-2019 - |
سؤال
أحاول بناء دائرة باستخدام خطوط. يبدأ كل سطر في وسط الدائرة وطالما كان نصف قطر الدائرة. باستخدام حلقة جنبا إلى جنب مع موجات الجيب و cosign ، يمكنني بناء الدائرة باستخدام الجيب و cosign للاحتفال بإحداثيات lineTo
معامل.
مشكلتي هي مع معلمة سمك الخط من lineStyle
. أود أن تتطابق نهايات الخطوط بشكل مثالي ، بغض النظر عن حجم محيط الدائرة ، لكن لا يمكنني معرفة طريقة مناسبة لسمك الخط.
//this is what makes sense to me, but it still creates some gaps
lineThickness = 1 + (((nRadius * 2) * Math.PI) - 360) / 359;
for(var i:int = 0; i < 360; i++)
{
// Convert the degree to radians.
nRadians = i * (Math.PI / 180);
// Calculate the coordinate in which the line should be drawn to.
nX = nRadius * Math.cos(nRadians);
nY = nRadius * Math.sin(nRadians);
// Create and drawn the line.
graphics.lineStyle(lineThickness, 0, 1, false, LineScaleMode.NORMAL, CapsStyle.NONE);
graphics.moveTo(0, 0);
graphics.lineTo(nX, nY);
}
لجعل نهايات الخطوط تلتقي في محيط الدوائر ، دون أي فجوات ، أحتاج إلى توسيع الخطوط لملء المساحة المتبقية. ما هو منطقي بالنسبة لي ، ولكن لا يعمل ، هو طرح 360 من محيط ، ثم يقسم هذا الرقم على كمية الفتحات الفارغة بين الخطوط (وهو 359) وإضافة هذا الرقم سمك 1.
ما يثير اهتمامي هو أن lineStyle
معلمة السماكة Number
, ، ولكن يبدو أنه لا يتخذ قيمًا فقط بين 0 و 255 ، لذلك لست متأكدًا مما إذا كان رقم النقطة العائمة مثل 1.354 هو سمك صالح.
المحلول
أود أن أقترح رسمها كأوتاد بدلاً من الخطوط ، ونسخها ولصقها في فلوريدا جديدة لمعرفة ما أعنيه:
var nRadians : Number;
var nradius: number = 100 ؛
var nx: number ؛
فار نيويورك: رقم ؛
var previcx: number = nradius ؛
var previcy: number = 0 ؛
// هذا هو ما يجعلني منطقيًا ، لكنه لا يزال يخلق بعض الثغرات
var linethickness: number = 1 + (((nradius * 2) * math.pi) - 360) / 359 ؛
لـ (var i: int = 0 ؛ i <360 ؛ i ++) {
// تحويل الدرجة إلى الراديان. nradians = i * (math.pi / 180) ؛
// Calculate the coordinate in which the line should be drawn to.
nX = nRadius * Math.cos( nRadians );
nY = nRadius * Math.sin( nRadians );
// Create and drawn the line.
graphics.beginFill( Math.random() * 0xFFFFFF );
graphics.moveTo( 0, 0 );
graphics.lineTo( previousX, previousY );
graphics.lineTo( nX, nY );
graphics.lineTo( 0, 0 );
graphics.endFill();
previousX = nX;
previousY = nY;
}