front_idill/src/search/js/curve.js
author bastiena
Mon, 24 Sep 2012 15:20:10 +0200
changeset 124 d2b4682dc9cc
parent 44 8393d3473b98
permissions -rw-r--r--
Étiquette V00.17 ajoutée à la révision 57a65edde708
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
     1
/*
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
     2
* This file is part of the TraKERS\Front IDILL package.
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
     3
*
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
     4
* (c) IRI <http://www.iri.centrepompidou.fr/>
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
     5
*
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
     6
* For the full copyright and license information, please view the LICENSE
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
     7
* file that was distributed with this source code.
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
     8
*/
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
     9
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    10
/*
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    11
 * Projet : TraKERS
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    12
 * Module : Front IDILL
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    13
 * Fichier : mosaic.js
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    14
 * 
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    15
 * Auteur : alexandre.bastien@iri.centrepompidou.fr
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    16
 * 
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    17
 * Fonctionnalités : Définit la "classe" courbe et définit des fonctions d'intéractions (dessin...).
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    18
 */
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    19
 
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    20
function curve()
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    21
{
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    22
	tool.fixedDistance = 10;
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    23
	this.path;
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    24
	this.pathStroke;
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    25
	this.lastPoint;
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    26
}
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    27
44
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    28
curve.prototype.onPointerIn = function(pointerX, pointerY)
35
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    29
{
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    30
	this.pathStroke = new Path();
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    31
	this.path = new Path();
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    32
	
44
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    33
	var point = new paper.Point(pointerX, pointerY);
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    34
	
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    35
	if(!this.lastPoint)
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    36
	{
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    37
		this.lastPoint = point;
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    38
	}
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    39
	
35
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    40
	this.pathStroke.fillColor = '#366F7A';
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    41
	this.path.fillColor = '#02FEFF';
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    42
};
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    43
44
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    44
curve.prototype.onPointerMove = function(pointerX, pointerY)
35
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    45
{
44
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    46
	var point = new paper.Point(pointerX, pointerY);
35
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    47
	
44
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    48
	var delta = new paper.Point(this.lastPoint.x - point.x, this.lastPoint.y - point.y);
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    49
	
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    50
	var step = delta / 5;
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    51
	var stepStroke = delta / 3;
35
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    52
	step.angle += 90;
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    53
	stepStroke.angle += 90;
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    54
44
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    55
	var top = point + step;
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    56
	var bottom = point - step;
35
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    57
	
44
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    58
	var topStroke = point + stepStroke;
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    59
	var bottomStroke = point - stepStroke;
35
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    60
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    61
	this.path.add(top);
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    62
	this.path.insert(0, bottom);
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    63
	this.path.smooth();
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    64
	
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    65
	this.pathStroke.add(topStroke);
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    66
	this.pathStroke.insert(0, bottomStroke);
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    67
	this.pathStroke.smooth();
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    68
	
44
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    69
	this.lastPoint = point;
35
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    70
};
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    71
44
8393d3473b98 Front IDILL:
bastiena
parents: 35
diff changeset
    72
curve.prototype.onMouseUp = function(pointerX, pointerY)
35
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    73
{
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    74
	this.pathStroke.remove();
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    75
	this.path.remove();
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    76
};
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    77
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    78
curve.prototype.onKeyDown = function(event)
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    79
{
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    80
	//S'il n'y a rien a colorier, on quitte.
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    81
	if(typeof this.pathStroke === 'undefined' || typeof this.path === 'undefined')
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    82
		return;
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    83
	
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    84
	if(event.key == 'r' || event.key == 'R')
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    85
	{
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    86
		this.pathStroke.fillColor = '#49564F';
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    87
		this.path.fillColor = '#00FE00'
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    88
	}
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    89
	else if(event.key == 'x' || event.key == 'X')
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    90
	{
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    91
		this.pathStroke.fillColor = '#535F6D';
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    92
		this.path.fillColor = '#CCCCCC'
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    93
	}
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    94
	else if(event.key == 'w' || event.key == 'W')
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    95
	{
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    96
		this.pathStroke.fillColor = '#366F7A';
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    97
		this.path.fillColor = '#02FEFF'
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    98
	}
4267d6d27a7d Front IDILL :
bastiena
parents:
diff changeset
    99
};