Debian Codegraph @

dojox/gfx3d/gradient.js

raw symbols SCIP
1 define(["dojo/_base/lang","./matrix","./vector"],
2 function(lang,m,v){
3
4 var gfx3d = lang.getObject("dojox.gfx3d",true);
5
6 var dist = function(a, b){ return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2)); };
7 var N = 32;
8
9 gfx3d.gradient = function(model, material, center, radius, from, to, matrix){
10 // summary:
11 // calculate a cylindrical gradient
12 // model: dojox.gfx3d.lighting.Model
13 // color model
14 // material: Object
15 // defines visual properties
16 // center: Object
17 // center of the cylinder's bottom
18 // radius: Number
19 // radius of the cylinder
20 // from: Number
21 // from position in radians
22 // to: Number
23 // from position in radians
24 // matrix: dojox.gfx3d.Matrix3D
25 // the cumulative transformation matrix
26 // tolerance: Number
27 // tolerable difference in colors between gradient steps
28
29 var mx = m.normalize(matrix),
30 f = m.multiplyPoint(mx, radius * Math.cos(from) + center.x, radius * Math.sin(from) + center.y, center.z),
31 t = m.multiplyPoint(mx, radius * Math.cos(to) + center.x, radius * Math.sin(to) + center.y, center.z),
32 c = m.multiplyPoint(mx, center.x, center.y, center.z), step = (to - from) / N, r = dist(f, t) / 2,
33 mod = model[material.type], fin = material.finish, pmt = material.color,
34 colors = [{offset: 0, color: mod.call(model, v.substract(f, c), fin, pmt)}];
35
36 for(var a = from + step; a < to; a += step){
37 var p = m.multiplyPoint(mx, radius * Math.cos(a) + center.x, radius * Math.sin(a) + center.y, center.z),
38 df = dist(f, p), dt = dist(t, p);
39 colors.push({offset: df / (df + dt), color: mod.call(model, v.substract(p, c), fin, pmt)});
40 }
41 colors.push({offset: 1, color: mod.call(model, v.substract(t, c), fin, pmt)});
42
43 return {type: "linear", x1: 0, y1: -r, x2: 0, y2: r, colors: colors};
44 };
45
46 return gfx3d.gradient;
47 });