GeoGebra JavaScript evaluation and XML modification demonstration
//The following JavaScript plots a curve representing the harmonic series of the note, C1.
//It also plots a series of points that correspond to the notes of the C major (Ionian) scale.
//The units for the y-axis are hertz; the units for the x-axis are cents.
var notes = ['C','Db','D','Eb','E','F','Gb','G','Ab','A','Bb','B']
var ionian = [1,0,1,0,1,1,0,1,0,1,0,1]
var harmonic_minor = [1,0,1,1,0,1,0,1,1,0,0,1]
function PlotPoints(steptable, octaves, mode) {
var newcolor = [Math.floor(Math.random()*255),Math.floor(Math.random()*255),Math.floor(Math.random()*255)]
for (var j = 0; j < octaves; j++) {
for (var i = 0; i < steptable.length; i++) {
if (steptable[i] == 1) {
var notelabel = notes[i % notes.length]
var thisoctave = j + 1
var objectname = notelabel + '_{' + thisoctave + '}'
if (mode == 1) {
var xvalue = j * 1200 + i * 100
document.ggbApplet.evalCommand(objectname + '=(' + xvalue + ',h(' + xvalue + '))')
document.ggbApplet.setLabelVisible(objectname,true)
document.ggbApplet.setColor(objectname,newcolor[0],newcolor[1],newcolor[2])
}
else {
document.ggbApplet.deleteObject(objectname)
}
}
}
}
}
function PlotFunction() {
document.ggbApplet.setCoordSystem(-600, 6000, -65.406, 490.548)
document.ggbApplet.evalCommand('h(x) = 440 * 2^((x - 4500) / 1200)')
}
PlotFunction()
PlotPoints(harmonic_minor, 4, 1)