0
我有一個50x50的像素空間,其中需要繪製五條線:X和Y軸,以及steepest
,average
和flattest
中的每一個斜線。在狹窄的空間中繪製斜線
我正在使用(Java)代碼,這是傳給我沒有任何文檔或評論,我從來沒有在畫布上繪製過。這是一個175x75像素的盒子的代碼。如上所述,這需要適應50x50的區域。
DrawingArea canvas = new DrawingArea(175, 75);
canvasContainer.add(canvas);
Rectangle rectangle = new Rectangle(0, 0, 174, 75);
canvas.add(rectangle);
Line slopeMainLineX = new Line(5, 70, 170, 70);
slopeMainLineX.setStrokeOpacity(0.5);
canvas.add(slopeMainLineX);
Line slopeMainLineY = new Line(40, 70, 40, 0);
slopeMainLineY.setStrokeOpacity(0.5);
canvas.add(slopeMainLineY);
steepestLine = new Line(40, 70, 0, 0);
steepestLine.setStrokeWidth(3);
canvas.add(steepestLine);
avgSlopeLine = new Line(40, 70, 0, 0);
avgSlopeLine.setStrokeWidth(2);
canvas.add(avgSlopeLine);
flattestLine = new Line(40, 70, 0, 0);
flattestLine.setStrokeWidth(1);
canvas.add(flattestLine);
int steepestAngle = Math.round(site.getSlope().getMax());
int averageAngle = Math.round(site.getSlope().getAvg());
int flatestAngle = Math.round(site.getSlope().getMin());
double xPointSteepestAngle = 40 + 120 * Math.cos(steepestAngle*0.0174532925);
double yPointSteepestAngle = 70 + 120 * Math.sin(steepestAngle*0.0174532925);
double xPointAverageAngle = 40 + 120 * Math.cos(averageAngle*0.0174532925);
double yPointAverageAngle = 70 + 120 * Math.sin(averageAngle*0.0174532925);
double xPointFlatestAngle = 40 + 120 * Math.cos(flatestAngle*0.0174532925);
double yPointFlatestAngle = 70 + 120 * Math.sin(flatestAngle*0.0174532925);
steepestLine.setX2((int) xPointSteepestAngle);
steepestLine.setY2(70 - ((int) yPointSteepestAngle - 70));
avgSlopeLine.setX2((int) xPointAverageAngle);
avgSlopeLine.setY2(70 - ((int) yPointAverageAngle - 70));
flatestLine.setX2((int) xPointFlatestAngle);
flatestLine.setY2(70 - ((int) yPointFlatestAngle - 70));
我完全失去了這裏,所以任何幫助將不勝感激。
原諒我,我顯然忘了提及這是使用GWT的DrawingArea作爲畫布。您引用的命令對於此控件不存在。 –
Ooooh,對不起。我以爲你使用的是HTML5 Canvas。實際上GWT中有更接近你的命令的等價物。看到這裏:http://code.google.com/p/gwt-graphics/wiki/Manual 讓事情像一條線幾乎完全相同 –
感謝您的幫助。 –