SlimRunner

dcg-viewport-tracker

Oct 20th, 2020 (edited)
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.     'use strict';
  3.     const ID_PREFIX = 'vp_tracker';
  4.     const FOLDER_ID = ID_PREFIX + '_folder';
  5.     // change this to false to make expressions visible
  6.     const HIDDEN_EXPRESSIONS = true;
  7.     // Github: https://github.com/SlimRunner
  8.     // Twitter: @runner_slim
  9.    
  10.     let state = Calc.getState();
  11.     let newExprs = [
  12.         String.raw`X_{vpmin}`,
  13.         String.raw`Y_{vpmin}`,
  14.         String.raw`X_{vpmax}`,
  15.         String.raw`Y_{vpmax}`
  16.     ].map((expval, i) => {
  17.         return {
  18.             id: `${ID_PREFIX}_${i}`,
  19.             latex: `${expval}=0`,
  20.             folderId: FOLDER_ID,
  21.             type: 'expression'
  22.         };
  23.     });
  24.    
  25.     newExprs.unshift({
  26.         collapsed: true,
  27.         secret: HIDDEN_EXPRESSIONS,
  28.         id: FOLDER_ID,
  29.         type: 'folder'
  30.     });
  31.    
  32.     state.expressions.list.push(...newExprs);
  33.     Calc.setState(state, {allowUndo: true});
  34.    
  35.     Calc.observe('graphpaperBounds',() => {
  36.         // this happens each time the GraphPaper is updated in Desmos
  37.         let mCoords = Calc.graphpaperBounds.mathCoordinates;
  38.        
  39.         Calc.setExpression({
  40.             id: `${ID_PREFIX}_0`,
  41.             latex: `X_{vpmin}=${mCoords.left}`
  42.         });
  43.         Calc.setExpression({
  44.             id: `${ID_PREFIX}_1`,
  45.             latex: `Y_{vpmin}=${mCoords.top}`
  46.         });
  47.         Calc.setExpression({
  48.             id: `${ID_PREFIX}_2`,
  49.             latex: `X_{vpmax}=${mCoords.right}`
  50.         });
  51.         Calc.setExpression({
  52.             id: `${ID_PREFIX}_3`,
  53.             latex: `Y_{vpmax}=${mCoords.bottom}`
  54.         });
  55.        
  56.     });
  57. }());
Add Comment
Please, Sign In to add comment