e2651e1e2d77bdf3c8e2d2847e4b5518f78b3e39.svn-base 2.2 KB

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