I am trying this code where I draw a horizontal line at certain height and continue a parabola after that. I am fixing the height using the variable leftY. It works fine. However, I wanted to be able to get the value of leftY from a slider value, like this
but this is not working and even causes an error. I appreciate your help in this.
var topL = 16,
a = 4,
lineL = 8;
//-----------------------------------------------------------------------
JXG.Options.point.snapToGrid = true;
var board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-20, 20, 20, -20],
axis: false,
showCopyright: false
});
var s = board.create('slider',[[-10,-10],[-10,10],[-15,5,15]]);
//var leftY=function(){return s.Value();};
var leftY = 5;
var rightY = -10;
var f=function(x) {
return -(x - a) * (x - a) + topL;
};
var rg = function(x) {
return a + Math.sqrt(topL - x)
};
var lg = function(x) {
return a - Math.sqrt(topL - x)
};
var isless = function(x, y) {
return Object.is((x - y) % 1, -0)
};
var leftX2 = lg(leftY),
leftX1 = leftX2 - lineL,
rightX1 = rg(rightY),
rightX2 = rightX1 + lineL,
leftL = [
[leftX1, leftY],
[leftX2, leftY]
],
leftLH = [
[leftX1, leftY + 1],
[leftX2, leftY + 1]
],
rightL = [
[rightX1, rightY],
[rightX2, rightY]
],
rightLH = [
[rightX1, rightY + 1],
[rightX2, rightY + 1]
];
/*--------plotting the axis-------------------------------------*/
var y_axis = [
[leftX1, -16],
[leftX1, 16]
];
var x_axis = [
[leftX1 - 0.15, -16],
[18, -16]
];
/*----- plotting dotted lines*/
var dotted1 = [
[0, 0],
[0, 0]
],
dotted2 = [
[0, 0],
[0, 0]
],
dotted3 = [
[0, 0],
[0, 0]
];
if (isless(rightY, leftY)) {
dotted1 = [
[leftX2, leftY],
[2 * a - leftX2, leftY]
];
dotted2 = [
[leftX1, rightY],
[rightX1, rightY]
];
} else {
dotted1 = [
[2 * a - rightX1, rightY],
[rightX1, rightY]
];
dotted2 = [
[leftX2, leftY],
[rightX2, leftY]
];
}
dotted3 = [
[a, topL],
[rightX2, topL]
];
//
var leftLine = board.create('segment', leftL, {
fixed: true
}),
leftLineH = board.create('segment', leftLH, {
fixed: true,
strokeWidth: 0,
highlightStrokeWidth: 0
}),
rightLine = board.create('segment', rightL, {
fixed: true
}),
rightLineH = board.create('segment', rightLH, {
fixed: true,
strokeWidth: 0,
highlightStrokeWidth: 0
});
var dotted_1 = board.create('segment', dotted1, {
fixed: true,
dash: 2
}),
dotted_2 = board.create('segment', dotted2, {
fixed: true,
dash: 2
}),
dotted_3 = board.create('segment', dotted3, {
fixed: true,
dash: 2
});
board.create('functiongraph', [f, leftX2, rightX1]);
//draw the axis
board.create('arrow', y_axis, {
strokeColor: 'black',
strokeWidth: 3,
fixed: true
});
board.create('arrow', x_axis, {
strokeColor: 'black',
strokeWidth: 3,
fixed: true
});
board.update();