Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Random sorting algorithm attempt 1
- // Declare config
- const config = {
- "width": 10,
- "color": "#772173",
- "rectangeCount": 10,
- "maxHeight": 100,
- "minHeight": 0
- };
- // Create Array and use rectangleCount to determine length
- let values = new Array;
- values.length = config.rectangeCount;
- // Generates random values for the array
- for (let i = 0; i < config.rectangeCount; i++) {
- values[i] = Math.floor(Math.random() * (config.maxHeight + 1)) + config.minHeight;
- }
- // Simple sorting algorithm
- function sortValues(a, b) {
- return a > b ? 1 : b > a ? -1 : 0;
- }
- // Call sorting algorithm and storing it in sortedValues so-as-to preserve original data
- let sortedValues = values.slice(0);
- sortedValues = sortedValues.sort(sortValues);
- let rectNum = new Array(values.length);
- for (let i = 0; i < config.rectangeCount; i++) {
- /* #############################################
- Figure out an algirithm that gets the x and y coordinates of the rectangle taking into account the following variables:
- x:
- 1) Width of screen
- 2) Width of rectangle
- 3) Amount of rectangles
- 4) A good amount of margin space
- y:
- 1) Height of screen
- 2) Max height of rectangles
- ########################################### */
- rectNum[i] = new Rect(i + 23, 100, config.width, sortedValues[i]);
- // console.log(rectNum[i]);
- }
- console.log(values);
- console.log(sortedValues);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement