如何在顯示X軸和Y軸的數學圖中繪製三角形。如何在數學圖中繪製三角形?
2
A
回答
0
這聽起來像你需要知道繪圖API如何在Flash中工作。你的問題含糊不清,但這可能有助於你開始 - 谷歌「Flash繪製API」的更多信息。
var point1:Point = new Point (0, 0);
var point2:Point = new Point (25, -50);
var point3:Point = new Point (50, 0);
var s:Sprite = new Sprite();
s.graphics.lineStyle(1, 0xff0000);
s.graphics.beginFill(0x000000);
s.graphics.moveTo(point1.x, point1.y);
s.graphics.lineTo(point2.x, point2.y);
s.graphics.lineTo(point3.x, point3.y);
s.graphics.lineTo(point1.x, point1.y);
s.graphics.endFill();
s.graphics.lineStyle(0);
s.x = (stage.stageWidth - s.width)/2;
s.y = ((stage.stageHeight - s.height)/2) + 50;
addChild(s);
我希望有幫助,讓我知道如果您有任何問題。
注意:此解決方案使用的是ActionScript 3.如果您需要使用AS2,這將無法正常工作,而且我不知道如何提供幫助,但您可能只是嘗試使用Google搜索「AS2繪圖API」或有這樣的結果。
+0
從標籤可以清楚地看到AS2是必需的 – 2010-04-01 19:07:14
1
要繪製使用ACTIONSCRIPT2形狀,您可以使用的moveTo()和了lineTo()MovieClip對象的方法。您可以使用lineStyle()或使用beginFill()和endFill()指定線條顏色和厚度。
所以請你圖和三角形,你可以做以下步驟:
- 製作一個影片剪輯名爲「圖形」
- 定義你的圖形應該多大(使用flash.geom.Rectangle對象)
- 畫出使用graph.beginFill(灰色)和然後的moveTo()和了lineTo()
- 畫出定期一些藍色線網格
- 畫出X和Y上的側軸灰色背景和底部o ˚F網格
- 使稱爲第二動畫片段 「形」
- 選擇3個隨機點:的moveTo(點1),了lineTo(點2),了lineTo(POINT3)了lineTo(點1)
這裏是如何的代碼可能是:
import flash.geom.Point;
import flash.geom.Rectangle;
function drawGraph(mc:MovieClip, rect:Rectangle):Void {
//this is a function to draw the graph
//draw the background
mc.beginFill(0xF8F8F8);
mc.moveTo(rect.left, rect.bottom);
mc.lineTo(rect.left, rect.top);
mc.lineTo(rect.right, rect.top);
mc.lineTo(rect.right, rect.bottom);
mc.lineTo(rect.left, rect.bottom);
mc.endFill();
//draw a grid
var unit:Number = 20;
mc.lineStyle(1, 0x0000FF, 20, true, "none", "round", "round");
var i:Number=rect.x;
do {
i=i+unit;
mc.moveTo(i, rect.bottom);
mc.lineTo(i, rect.top);
} while (i<rect.right);
i=rect.bottom;
do {
i=i-unit;
mc.moveTo(rect.left, i);
mc.lineTo(rect.right,i);
} while (i>rect.top);
//draw the axes
mc.lineStyle(2, 0x808080, 100, true, "none", "round", "round");
mc.moveTo(rect.left, rect.bottom);
mc.lineTo(rect.left, rect.top);
mc.moveTo(rect.left, rect.bottom);
mc.lineTo(rect.right, rect.bottom);
}
function randomPoint(rect:Rectangle):Point {
//this is a function which returns a random point within rect
var p:Point = new Point(rect.x+Math.random()*rect.width, rect.y+Math.random()*rect.height);
return p;
}
function drawTriangle(mc:MovieClip, rect:Rectangle):Void {
//this is a function to draw the triangle
// pick 3 random points within rect
var p1:Point = randomPoint(rect);
var p2:Point = randomPoint(rect);
var p3:Point = randomPoint(rect);
//connect the points to make a triangle
mc.lineStyle(3, 0xFF0000, 100, true, "none", "round", "round");
mc.moveTo(p1.x, p1.y);
mc.lineTo(p2.x, p2.y);
mc.lineTo(p3.x, p3.y);
mc.lineTo(p1.x, p1.y);
}
//make the 'graph' clip:
var myGraph:MovieClip = this.createEmptyMovieClip("myGraph", this.getNextHighestDepth());
//define the graph size:
var myRect:Rectangle = new Rectangle(50,50,300,300);
drawGraph(myGraph,myRect);//draw the graph
var myShape:MovieClip = this.createEmptyMovieClip("myShape", this.getNextHighestDepth());//make the 'shape' clip
drawTriangle(myShape,myRect);//draw a random triangle
//add a function to draw a new triangle when the graph is clicked:
myGraph.onRelease = function() {
myShape.clear();//erase the old triangle
drawTriangle(myShape,myRect);//draw a new one
}
可以單擊圖形生成一個新的隨機三角形。
graph + triangle http://roi.webfactional.com/img/so/graph.jpg
相關問題
- 1. 在三角形的三角形中繪製三角形
- 2. 如何在java中繪製三角形?
- 3. 繪製三角形
- 4. 在Blend中繪製圓角三角形
- 5. 如何在silverlight中使用度數來繪製數學三角形?
- 6. 如何在MATLAB中的圖像中繪製三角形?
- 7. iOS - 如何在視圖中繪製透明三角形
- 8. 如何在R中繪製三角形作爲圖例?
- 9. Mathematica - 「三角測量」 - 在圖上繪製三角形網格
- 10. 如何繪製和定位三角形?
- 11. 如何繪製相反的三角形?
- 12. GL_LINE_LOOP如何繪製三角形?
- 13. 如何繪製一個三角形UIButton
- 14. 如何使用OpenTK繪製三角形?
- 15. 尋找繪製三角形
- 16. 三角形繪製方法
- 17. Direct3D 11 - 繪製三角形
- 18. 繪製旋轉三角形
- 19. 繪製紋理三角形
- 20. 繪製三角形iOS
- 21. 在Java中繪製Sierpinski的三角形
- 22. 在XNA中繪製的三角形
- 23. 如何在二維數組中繪製三角形(Java)
- 24. Qt:繪製三角形圖片
- 25. 僅繪製熱圖上/下三角形
- 26. 試圖繪製2個三角形
- 27. 如何在android xml中繪製三角形形狀
- 28. 如何在python中繪製三角形形狀?
- 29. 數學 - 從坡度角度繪製第三個三角點
- 30. Android:在三角形上繪製三角形
你能展示你想要做的事情嗎? – 2010-04-01 07:35:21