Hi!
I wanted to point out some issues that I ran on, while testing on FF 6.0 .
Probably my code is messy, but it works 100% the way I want it, on Chrome 13 and Chrome Canary (15.0.857.0).
First I noticed that in FF all the code that is out of any functions is executed fine, but when it comes to functions(such as onMouseMove(event)), it doesnt do anything. I runned firebug to find the problem, and it gave me this line in the console, every time I moved the mouse over the canvas:
uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOMCanvasRenderingContext2D.textAlign]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: path/paper.js :: <TOP_LEVEL> :: line 5624" data: no]
Line 5624 is actually:
ctx.textAlign = this.getJustification();
Next, when I go to the debugger, enable the "Break On Next", then move my mouse over the canvas, it allways stops at line 6733:
6732 | function mousemove(event) {
6733 | var view;
The console say:
"attempt to run compile-and-go script on a cleared scope
path/paper.js
Line 975"
Line 975:
if (arguments.length == 4) {
What is strange, is that the console not allways show this line, its more like 50% chance to appear.
Thats how the message looks:
http://imageshack.us/photo/my-images/651/screenshot1mi.png/
Also there is the onFrame problem, the debugger keeps breaking on line 6683:
requested = false;
No matter if the onFrame function have any code inside, or is clean. I still guess that my code have nothing to do with it, because both Chrome 13 and Canary dev tools, dont seem to give me any notifications.
Here's my code, the idea behind it is to get used to paper.js:
[js]
var mousePos; //Parameter for holding the mouse position
//Make long story short, define short and clear parameter for center coordinates:
var centerX = view.center.x;
var centerY = view.center.y;
var center = view.center;
var displayX, displayY, sectionN, m; //Parameters in whitch we keep the correct coordinates and a parameter to hold the section of the grid, m representing the gradient of the line between the center and the current coordinates
var coordinates = new PointText(new Point(10, 20)); //Define a "label" in the given position, that will show us current coordinates later
coordinates.justification = 'bottomleft'; //Set an anchor point, from where it will determine the position
coordinates.fillColor = 'white'; //Color - White
var section = new PointText(new Point(10, 40)); //Define a "label" in the given position, that will show us current section later
section.justification = 'left'; //Set an anchor point, from where it will determine the position
section.fillColor = 'white'; //Color - White
var angle = new PointText(new Point(10, 60)); //Define a "label" in the given position, that will show us current angle later
angle.justification = 'left'; //Set an anchor point, from where it will determine the position
angle.fillColor = 'white'; //Color - White
var playerDot = new Path.Circle(center, 30); //Define circle, to represent the player
playerDot.position = center; //Put the "player" in the middle
playerDot.strokeColor = 'blue';
playerDot.strokeWidth = 5;
playerDot.fillColor = 'white';
var test;
var vectorItem;
vectorItem = new Path(new Point(centerX, centerY), new Point(centerX, centerY));
// The amount of circles we want to make:
var counter = 100;
// Create a symbol, which we will use to place instances of later:
var paths = new Path.Circle(new Point(0, 0), 10);
paths.style = {
fillColor: 'red',
strokeColor: 'black'
};
var symbol = new Symbol(paths);
// Place the instances of the symbol:
for (var i = 0; i < counter; i++) {
// The center position is a random point in the view:
var centers = Point.random() * view.size;
var placedSymbol = symbol.place(centers);
placedSymbol.scale(i / counter);
}
project.activeLayer.reverseChildren();
//The event is fired each time the mouse is moved over ther canvas:
function onMouseMove(event)
{
mousePos = event.point; //Define short parameter for current mouse position
//The center of the canvas is the (0,0) coordinate, that means we got to transfer the coordinates
// from positive to negative, when the mouse is lefter/under the center:
if(mousePos.y > centerY)
{
displayY = mousePos.y - centerY + 0.5;
displayY = displayY-displayY*2;
}
else if (mousePos.y < centerY)
{
displayY = centerY - mousePos.y - 0.5;
}
if(mousePos.x > centerX)
{
displayX = mousePos.x - centerX;
}
else if (mousePos.x < centerX)
{
displayX = centerX - mousePos.x;
displayX = displayX - displayX*2;
}
m = displayY/displayX;
//Find the section in whitch the mouse is right now:
if(displayY>0&&displayX>0)
{
test = Math.atan(displayY/displayX)*180/Math.PI;
test = Math.round(test);
sectionN = 1;
}
else if(displayY>0&&displayX<0)
{
test = Math.atan(displayX/displayY)*180/Math.PI*-1+90;
test = Math.round(test);
sectionN = 2;
}
else if(displayY<0&&displayX<0)
{
test = Math.atan(displayY/displayX)*180/Math.PI+180;
test = Math.round(test);
sectionN = 3;
}
else if(displayY<0&&displayX>0)
{
test = Math.atan(displayX/displayY)*180/Math.PI*-1+270;
test = Math.round(test);
sectionN = 4;
}
coordinates.content = 'X = ' + displayX + ', Y = ' + displayY;
coordinates.position = new Point(mousePos.x + 10, mousePos.y);
section.content = 'Section: ' + sectionN + ', m = ' + m;
angle.content = 'Angle: ' + test;
vectorItem.remove();
vectorItem = new Path(new Point(centerX, centerY), new Point(mousePos.x, mousePos.y));
vectorItem.strokeWidth = 2;
vectorItem.strokeColor = '#e4141b';
vectorItem.insertBelow(project.activeLayer);
}
function onFrame(event)
{
}
[/js]
I cleaned the code from all the unnessesary, commented code that I had. First time I'm posting an issue, so correct/ask me for any misstakes/information you need.
P.S.
Forgot to mention, I'm using the last stable version of paper.js - 0.21 .