1 if(!dojo._hasResource["dojox.gfx3d.gradient"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.gfx3d.gradient"] = true;
3 dojo.provide("dojox.gfx3d.gradient");
5 dojo.require("dojox.gfx3d.vector");
6 dojo.require("dojox.gfx3d.matrix");
9 var dist = function(a, b){ return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2)); };
12 dojox.gfx3d.gradient = function(model, material, center, radius, from, to, matrix){
13 // summary: calculate a cylindrical gradient
14 // model: dojox.gfx3d.lighting.Model: color model
15 // material: Object: defines visual properties
16 // center: Object: center of the cylinder's bottom
17 // radius: Number: radius of the cylinder
18 // from: Number: from position in radians
19 // to: Number: from position in radians
20 // matrix: dojox.gfx3d.Matrix3D: the cumulative transformation matrix
21 // tolerance: Number: tolerable diffirence in colors between gradient steps
23 var m = dojox.gfx3d.matrix, v = dojox.gfx3d.vector, mx = m.normalize(matrix),
24 f = m.multiplyPoint(mx, radius * Math.cos(from) + center.x, radius * Math.sin(from) + center.y, center.z),
25 t = m.multiplyPoint(mx, radius * Math.cos(to) + center.x, radius * Math.sin(to) + center.y, center.z),
26 c = m.multiplyPoint(mx, center.x, center.y, center.z), step = (to - from) / N, r = dist(f, t) / 2,
27 mod = model[material.type], fin = material.finish, pmt = material.color,
28 colors = [{offset: 0, color: mod.call(model, v.substract(f, c), fin, pmt)}];
30 for(var a = from + step; a < to; a += step){
31 var p = m.multiplyPoint(mx, radius * Math.cos(a) + center.x, radius * Math.sin(a) + center.y, center.z),
32 df = dist(f, p), dt = dist(t, p);
33 colors.push({offset: df / (df + dt), color: mod.call(model, v.substract(p, c), fin, pmt)});
35 colors.push({offset: 1, color: mod.call(model, v.substract(t, c), fin, pmt)});
37 return {type: "linear", x1: 0, y1: -r, x2: 0, y2: r, colors: colors};