Skip to content

Commit 0cf5987

Browse files
author
Stefan Fenn
committed
fixed plot bug. added new gradient
1 parent 02baac6 commit 0cf5987

3 files changed

Lines changed: 49 additions & 6 deletions

File tree

exampleFunction2d.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@
4949
<h3>Plot of function</h3>
5050

5151
<p>
52-
\[ \frac{x^2}{10}\ \sin(x) + 0.4 + \frac{\sin(100 x)}{100} \]
52+
\[ f(x) = \frac{x^2}{10}\ \sin(x) + 0.4 + \frac{\sin(100 x)}{100} \]
5353
</p>
5454
</div>

exampleFunction3d.html

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,36 @@
3737
};
3838

3939
drawGrid(config);
40-
const gv = getGradientVector(0, 512);
41-
draw3dFunction(configF3, -3.5, 3.5, 0.8, gv, func3);
42-
</script>
40+
window.draw3dFunctionWithGradient = function(gradientIndex) {
41+
console.log("draw3dFunctionWithGradient", gradientIndex);
42+
const gv = getGradientVector(gradientIndex, 512);
43+
draw3dFunction(configF3, -3.5, 3.5, 0.9, gv, func3);
44+
};
45+
window.draw3dFunctionWithGradient(0);
46+
</script>
47+
48+
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
49+
<script id="MathJax-script" async
50+
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
51+
</script>
52+
53+
<div style="width:600px;height:600px;padding-left:620px">
54+
<select onchange="window.draw3dFunctionWithGradient(this.selectedIndex);">
55+
<option value="0">Gradient 0</option>
56+
<option value="1">Gradient 1</option>
57+
<option value="2">Gradient 2</option>
58+
<option value="3">Gradient 3</option>
59+
<option value="4">Gradient 4</option>
60+
<option value="5">Gradient 5</option>
61+
<option value="6">Gradient 6</option>
62+
<option value="7">Gradient 7</option>
63+
<option value="8">Gradient 8</option>
64+
</select>
65+
</div>
66+
67+
<div style="width:600px;">
68+
<h3>Plot of function</h3>
69+
<p>
70+
\[ f(x,y) = \sin(2 x) y + \cos(5 y) x \]
71+
</p>
72+
</div>

graphplot.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ export function getGradientVector(colorMapIndex, levels) {
251251
0.66: "rgb(122, 76, 47)",
252252
1.0: "rgb(142, 143, 79)"
253253
};
254+
const gradientColors9 = {
255+
0:'#ff3800',
256+
0.1429:'#ff6500',
257+
0.2857:'#ffa54f',
258+
0.4286:'#ffc78f',
259+
0.5714:'#ffe1c6',
260+
0.7143:'#fef9ff',
261+
0.8571:'#c9d9ff',
262+
1:'#9fbfff'
263+
};
254264

255265
const gradientColorList = [
256266
gradientColors1,
@@ -260,7 +270,8 @@ export function getGradientVector(colorMapIndex, levels) {
260270
gradientColors5,
261271
gradientColors6,
262272
gradientColors7,
263-
gradientColors8
273+
gradientColors8,
274+
gradientColors9
264275
];
265276

266277
const gradientColors = gradientColorList[colorMapIndex];
@@ -319,7 +330,9 @@ export function draw3dFunction(c, zMin, zMax, alpha, gv, func) {
319330
data.data[index + 3] = a;
320331
}
321332
c.ctx.putImageData(data, 0, 0);
322-
setTimeout(drawInTimeSlot);
333+
if (w < c.ctx.canvas.width) {
334+
drawInTimeSlot();
335+
}
323336
};
324337

325338
drawInTimeSlot();

0 commit comments

Comments
 (0)