Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. // Random sorting algorithm attempt 1
  2. // Declare config
  3. const config = {
  4. "width": 10,
  5. "color": "#772173",
  6. "rectangeCount": 10,
  7. "maxHeight": 100,
  8. "minHeight": 0
  9. };
  10.  
  11. // Create Array and use rectangleCount to determine length
  12. let values = new Array;
  13. values.length = config.rectangeCount;
  14.  
  15. // Generates random values for the array
  16. for (let i = 0; i < config.rectangeCount; i++) {
  17. values[i] = Math.floor(Math.random() * (config.maxHeight + 1)) + config.minHeight;
  18. }
  19.  
  20. // Simple sorting algorithm
  21. function sortValues(a, b) {
  22. return a > b ? 1 : b > a ? -1 : 0;
  23. }
  24.  
  25. // Call sorting algorithm and storing it in sortedValues so-as-to preserve original data
  26. let sortedValues = values.slice(0);
  27. sortedValues = sortedValues.sort(sortValues);
  28.  
  29.  
  30. let rectNum = new Array(values.length);
  31. for (let i = 0; i < config.rectangeCount; i++) {
  32. /* #############################################
  33. Figure out an algirithm that gets the x and y coordinates of the rectangle taking into account the following variables:
  34. x:
  35. 1) Width of screen
  36. 2) Width of rectangle
  37. 3) Amount of rectangles
  38. 4) A good amount of margin space
  39. y:
  40. 1) Height of screen
  41. 2) Max height of rectangles
  42.  
  43. ########################################### */
  44. rectNum[i] = new Rect(i + 23, 100, config.width, sortedValues[i]);
  45. // console.log(rectNum[i]);
  46. }
  47.  
  48.  
  49.  
  50. console.log(values);
  51. console.log(sortedValues);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement