Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Commit 8eb2630

Browse files
committedJan 1, 2019
added pyramid representation
1 parent 5005b2d commit 8eb2630

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
 

‎index.html

+9
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ <h1><span class='important_letter'>S</span>orting <span class='important_letter'
106106
<option value="display_array_color_pillars">As colored pillars</option>
107107
<option value="display_array_color_dots">As colored dots</option>
108108

109+
<option value="display_array_pyramid">As pyramid</option>
110+
<option value="display_array_color_pyramid">As colored pyramid</option>
111+
109112
<option value="display_array_pillar_spiral">As spiral of pillars</option>
110113
<option value="display_array_dots_spiral">As spiral of dots</option>
111114
<option value="display_array_color_pillar_spiral">As colored spiral of pillars</option>
@@ -233,6 +236,12 @@ <h1><span class='important_letter'>S</span>orting <span class='important_letter'
233236
case 'display_array_color_circle_dots':
234237
glob_display_func = display_array_color_circle_dots;
235238
break;
239+
case 'display_array_pyramid':
240+
glob_display_func = display_array_pyramid;
241+
break;
242+
case 'display_array_color_pyramid':
243+
glob_display_func = display_array_color_pyramid;
244+
break;
236245
}
237246

238247
switch (draw_func) {

‎visualize.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function changeTheme(theme) {
2424
if (document.getElementById('theme_in')!==null)
2525
document.getElementById('theme_in').value = theme;
2626

27-
window.history.pushState(`${theme.toUpperCase()}-THEME`, 'Changed theme ... ', `${theme}`);
27+
// window.history.pushState(`${theme.toUpperCase()}-THEME`, 'Changed theme ... ', `${theme}`);
2828

2929
xhtp.open("GET", "themes/" + theme + ".css");
3030
xhtp.send();
@@ -66,6 +66,43 @@ function display_array_color_pillars(arr) {
6666
ctx.stroke();
6767
}
6868
}
69+
function display_array_pyramid (arr, focused_els_i) {
70+
focused_els_i = focused_els_i || [];
71+
72+
ctx.clearRect(0, 0, canvas.width, canvas.height);
73+
let scale = canvas.width / Math.max(...arr);
74+
75+
for (let i = canvas.height / (arr.length + 1); i <= canvas.height; i += canvas.height / (arr.length + 1)) {
76+
ctx.beginPath();
77+
78+
ctx.strokeStyle = focused_els_i.includes(Math.floor(i / (canvas.width / (arr.length + 1)))) ? "red" : glob_themes[glob_theme]["color"];
79+
ctx.lineWidth = focused_els_i.includes(Math.floor(i / (canvas.width / (arr.length + 1)))) ? 4 : 2;
80+
81+
ctx.moveTo(canvas.width/2-(arr[Math.floor(i / (canvas.width / (arr.length + 1))) - 1] * scale)/2, i);
82+
ctx.lineTo(canvas.width/2+(arr[Math.floor(i / (canvas.width / (arr.length + 1))) - 1] * scale)/2, i);
83+
84+
ctx.stroke();
85+
}
86+
}
87+
function display_array_color_pyramid (arr) {
88+
ctx.clearRect(0, 0, canvas.width, canvas.height);
89+
let scale = canvas.height / Math.max(...arr);
90+
91+
let line_weight = 2,
92+
arr_max = Math.max(...arr);
93+
94+
for (let i = canvas.width / (arr.length - 1); i <= canvas.width; i += canvas.width / (arr.length - 1)) {
95+
ctx.beginPath();
96+
97+
ctx.strokeStyle = "hsl(" + arr[Math.floor(i / (canvas.width / (arr.length - 1)))] * (360 / arr_max) + ", 100%, 50%)";
98+
ctx.lineWidth = line_weight;
99+
100+
ctx.moveTo(canvas.width/2-(arr[Math.floor(i / (canvas.width / (arr.length + 1))) - 1] * scale)/2, i);
101+
ctx.lineTo(canvas.width/2+(arr[Math.floor(i / (canvas.width / (arr.length + 1))) - 1] * scale)/2, i);
102+
103+
ctx.stroke();
104+
}
105+
}
69106
function display_array_pillar_spiral(arr, focused_els_i) {
70107
focused_els_i = focused_els_i || [];
71108
ctx.clearRect(0, 0, canvas.width, canvas.height);

0 commit comments

Comments
 (0)
This repository has been archived.