Advertisement
Guest User

fdamned26 FDTD range jQuery script

a guest
Nov 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getZones() {
  2.  var $ = window.jQuery,
  3.  j = "_",
  4.  p = "#zone" + j,
  5.  q = p.substr(1),
  6.  css = "ul > li[id^=" + q + "]";
  7.  return $(css);
  8. }
  9.  
  10.  
  11. function getZoneXY(zones0, i0) {
  12.  var zones = zones0 || getZones(),
  13.  i = +i0 || 0,
  14.  f = zones[i > 0 ? i : 0],
  15.  id = (f && f.id) || '',
  16.  xy = id.substr(5).split(/_/g),
  17.  x = +xy[0] || 0,
  18.  y = +xy[1] || 0,
  19.  r = [x, y];
  20.  return r;
  21. }
  22.  
  23.  
  24. function pyth(x, y, isAP) {
  25.  x = Math.abs(+x || 0);
  26.  y = Math.abs(+y || 0);
  27.  return +Math.round(isAP ? (x + y) : Math.sqrt(x * x + y * y));
  28. }
  29.  
  30. function drawRange(zones0, dist, color, isAP) {
  31.  var zones = zones0 || getZones() || [],
  32.  nbZones = (zones && zones.length) || 0,
  33.  $ = window.jQuery,
  34.  i = 0,
  35.  x = 0,
  36.  y = 0,
  37.  xy, o,
  38.  blc = "border-left-color",
  39.  brc = "border-right-color",
  40.  bbc = "border-bottom-color",
  41.  btc = "border-top-color";
  42.  
  43.  if (dist > 0 && color) {
  44.  for (i = 0; i < nbZones; ++i) {
  45.  xy = getZoneXY(zones, i);
  46.  if (xy) {
  47.  x = xy[0];
  48.  y = xy[1];
  49.  
  50.  if (pyth(x, y, isAP) === dist) {
  51.  o = zones.eq(i);
  52.  if (x < 0 && pyth(x - 1, y, isAP) !== dist) {
  53.  o.css(blc, color);
  54.  } else if (x > 0 && pyth(x + 1, y) !== dist) {
  55.  o.css(brc, color);
  56.  } else if (isAP) {
  57.  if (x === 0) {
  58.  o.css(blc, color);
  59.  o.css(brc, color);
  60.  } else if (x === (dist - 1)) {
  61.  o.css(brc, color);
  62.  }
  63.  }
  64.  
  65.  if (y < 0 && pyth(x, y - 1, isAP) !== dist) {
  66.  o.css(bbc, color);
  67.  } else if (y > 0 && pyth(x, y + 1) !== dist) {
  68.  o.css(btc, color);
  69.  } else if (isAP) {
  70.  if (y === 0) {
  71.  o.css(bbc, color);
  72.  o.css(btc, color);
  73.  } else if (y === (dist - 1)) {
  74.  o.css(btc, color);
  75.  }
  76.  }
  77.  }
  78.  }
  79.  }
  80.  }
  81. }
  82.  
  83. function drawRangeHR(zones0) {
  84.  drawRange(zones0, 11, "yellow");
  85. }
  86.  
  87. function drawRangeWT4(zones0) {
  88.  drawRange(zones0, 1, "gray");
  89. }
  90.  
  91. function drawRangeWT5(zones0) {
  92.  drawRange(zones0, 2, "yellow");
  93. }
  94.  
  95. function drawRangeDistant(zones0) {
  96.  drawRange(zones0, 5, "cyan");
  97. }
  98.  
  99. function drawRangeEE(zones0) {
  100.  drawRange(zones0, 17, "white");
  101. }
  102.  
  103. function drawRange9AP(zones0) {
  104.  drawRange(zones0, 9, "yellow", true);
  105. }
  106.  
  107. function drawRange11AP(zones0) {
  108.  drawRange(zones0, 11, "pink", true);
  109. }
  110.  
  111. var zones0 = getZones();
  112. drawRangeHR(zones0);
  113. drawRangeEE(zones0);
  114. drawRangeWT4(zones0);
  115. drawRangeWT5(zones0);
  116. drawRange9AP(zones0);
  117. drawRange11AP(zones0);
  118. drawRangeDistant(zones0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement