app.js 941 B

123456789101112131415161718192021222324252627282930
  1. document.getElementsByName("func_expr")[0].addEventListener("keydown", keydownhandler);
  2. document.getElementsByName("func_expr")[0].focus();
  3. var plot = new Fooplot(document.getElementsByName("plot")[0]);
  4. function keydownhandler(e){
  5. switch (e.key){
  6. case "Enter":
  7. draw_func();
  8. break;
  9. case "SoftLeft":
  10. plot.deleteAllPlots();
  11. plot.reDraw();
  12. break;
  13. case "":
  14. }
  15. }
  16. function draw_x2(){
  17. plot = new Fooplot(document.getElementsByName("plot")[0]);
  18. plot.addPlot('x^2', FOOPLOT_TYPE_FUNCTION, {'color': '#ff0000'});
  19. plot.reDraw();
  20. }
  21. function draw_func(){
  22. var func_expr = document.getElementsByName("func_expr")[0].value;
  23. var colors = ["green", "red", "blue", "purple", "black", "orange",
  24. "yellow"];
  25. var color = colors[Math.floor(Math.random() * colors.length)];
  26. plot.addPlot(func_expr, null,{"color": color});
  27. plot.reDraw();
  28. }