![]() |
|
||||||||||
|
|||||
|
Регистрация: Apr 2006
Сообщений: 19
|
Доброго дня!
Такая проблема: нужно взять алгоритм по подсчету площади методом Грина, реализованный в файле 3, который успешно работает, и заставить его работать в файле 1. Просто в разных файлах разные механизмы отрисовки линии и как применять данный алгоритм подсчета я не знаю, но полагаю это несложно сделать. Профи, помогите новичку разобраться! Нужно, чтобы все рисовалось как в файле 1 и просчитывало площадь как в файле 3. Вот. Спасибо. |
|
|||||
|
Регистрация: Apr 2006
Сообщений: 19
|
Неужели так никто ничего и не напишет? Хоть подарок бы сделали на ДР....
![]() |
|
|||||
|
Регистрация: Apr 2006
Сообщений: 19
|
Файл 3:
Мувик main: onClipEvent (load)
{
// points of the object the user draws
points = new Array ();
// number of lines that make up the shape (used for duplicated names and depths)
num_lines = 0;
// current and old position of the mouse
x = _root._xmouse;
y = _root._ymouse;
ox = x;
oy = y;
// determines whether the user is clicking and drawing on the screen or not
drag = 0;
// determines whether the user is still drawing a shape or not
done = 0;
// keeps track of the number of mouse clicks (used to get rid of a small bug)
click = 0;
}
onClipEvent (mouseDown)
{
drag = 1;
click++;
if (click == 1)
{
x = _root._xmouse;
y = _root._ymouse;
}
}
onClipEvent (mouseUp)
{
drag = 0;
}
onClipEvent (enterFrame)
{
if (drag && ! done)
{
ox = x;
oy = y;
x = _root._xmouse;
y = _root._ymouse;
// make a new line and connect the new and old position of the mouse with it
_root.line.duplicateMovieClip ("line" + num_lines, num_lines);
_root.draw_line ("line" + num_lines, ox, oy, x, y);
points[num_lines] = new Array (ox, oy);
num_lines++;
}
}
onClipEvent (keyDown)
{
// calculate area
if (Key.isDown (65))
{
done = 1;
area = _root.calculate_area (points, num_lines);
_root.area = "area = " + Math.round (area * 1000) / 1000 + " pixels squared";
_root.line.duplicateMovieClip ("line" + num_lines, num_lines);
_root.draw_line ("line" + num_lines, x, y, points[0][0], points[0][1]);
}
// get rid of lines and reset variables
if (Key.isDown (82))
{
points = new Array ();
num_lines = 0;
x = _root._xmouse;
y = _root._ymouse;
ox = x;
oy = y;
drag = 0;
done = 0;
click = 0;
_root.area = "";
for (j in _root)
{
_root[j].removeMovieClip ();
}
}
}
function calculate_area (p, n)
{
var area = 0, k;
for (var j = 0; j < n; j++)
{
k = (j + 1) % n;
area += p[j][0] * p[k][1] - p[j][1] * p[k][0];
}
area *= .5;
return Math.abs (area);
}
function draw_line (mc, x1, y1, x2, y2)
{
_root[mc]._x = x1;
_root[mc]._y = y1;
_root[mc]._xscale = x2 - x1;
_root[mc]._yscale = y2 - y1;
}
fscommand ("allowscale", false);
stop ();
Первый кадр: var tol=20;
var path=[];
var gridStep=10;
_root.ris_mc.onMouseUp=function():Void{
var dx=_xmouse-path[0].x,dy=_ymouse-path[0].y;
if(Math.sqrt(dx*dx+dy*dy)<tol){
delete this.onEnterFrame;
this.clear();
this.moveTo(_xmouse,_ymouse);
this.beginFill(0xFF0000, 50);
this.lineStyle(0,0xFF0000);
for(var i=0;i<path.length;i++)this.lineTo(path[i].x,path[i].y);
this.endFill();
}
path.push({x:gridStep*Math.round(_xmouse/gridStep),y:gridStep*Math.round(_ymouse/gridStep)});
}
_root.ris_mc.onEnterFrame=function():Void{
//trace(this);
this.clear();
this.lineStyle(1);
this.moveTo(path[0].x,path[0].y);
for(var i=1;i<path.length;i++)this.lineTo(path[i].x,path[i].y);
if(path.length) this.lineTo(gridStep*Math.round(_xmouse/gridStep),gridStep*Math.round(_ymouse/gridStep));
}
|
|
|||||
|
Регистрация: Apr 2006
Сообщений: 19
|
Спасибо!
![]() |
![]() |
![]() |
Часовой пояс GMT +4, время: 02:22. |
|
|
« Предыдущая тема | Следующая тема » |
|
|