private void plot() {
    if (dygraphs != null) {
      if (panel.remove(dygraphs)) ;
    }

    String eq = textArea.getValue();

    double x1 = Double.parseDouble(fromTb.getValue());
    double x2 = Double.parseDouble(toTb.getValue());
    double xs = 1.0 * (x2 - x1) / width;

    JsArray<JsArrayMixed> data = JsArray.createArray().cast();
    for (int i = 0; i < width; i++) {
      double x = x1 + i * xs;
      JsArrayNumber y = evalFn(eq, x);
      JsArrayMixed row = JsArrayMixed.createArray().cast();
      row.push(x);
      for (int j = 0; j < y.length(); j++) {
        row.push(y.get(j));
      }
      data.push(row);
    }
    dygraphs = new Dygraphs(data, null);
    dygraphs.setPixelSize(width, height);
    panel.add(dygraphs);
  }
Example #2
0
  @Override
  public void onGamepadUpdated(int index) {
    Gamepad gamepad = Gamepad.getGamepad(index);
    GwtController controller = controllerMap.get(index);
    if (gamepad != null && controller != null) {
      // Determine what changed
      JsArrayNumber axes = gamepad.getAxes();
      JsArrayNumber buttons = gamepad.getButtons();
      synchronized (eventQueue) {
        for (int i = 0, j = axes.length(); i < j; i++) {
          float oldAxis = controller.getAxis(i);
          float newAxis = (float) axes.get(i);
          if (oldAxis != newAxis) {
            GwtControllerEvent event = eventPool.obtain();
            event.type = GwtControllerEvent.AXIS;
            event.controller = controller;
            event.code = i;
            event.amount = newAxis;
            eventQueue.add(event);
          }
        }
        for (int i = 0, j = buttons.length(); i < j; i++) {
          float oldButton = controller.getButtonAmount(i);
          float newButton = (float) buttons.get(i);
          if (oldButton != newButton) {
            if ((oldButton < 0.5f && newButton < 0.5f)
                || (oldButton >= 0.5f && newButton >= 0.5f)) {
              controller.buttons.put(i, newButton);
              continue;
            }

            GwtControllerEvent event = eventPool.obtain();
            event.type =
                newButton >= 0.5f ? GwtControllerEvent.BUTTON_DOWN : GwtControllerEvent.BUTTON_UP;
            event.controller = controller;
            event.code = i;
            event.amount = newButton;
            eventQueue.add(event);
          }
        }
      }
    }
  }
 public int length() {
   return jso.length();
 }
 public double get(int i) {
   return jso.get(i);
 }