コード例 #1
0
  public static float getModifiedValue(float value, Shade shade) {

    if (shade.getValue() == 500) {
      return value;
    }

    float indexFloat = ((float) shade.getValue()) / 100.0f;

    int indexFloor = (int) Math.floor(indexFloat);
    int indexCeil = (int) Math.ceil(indexFloat);

    int max = mValuePercentConversion.length - 1;
    int lowerIndex = Math.min(Math.max(indexFloor, 0), max);
    int upperIndex = Math.min(Math.max(indexCeil, 0), max);

    float lowerPercent = mValuePercentConversion[lowerIndex];
    float valuePercent;
    if (lowerIndex != upperIndex) {
      float upperPercent = mValuePercentConversion[upperIndex];
      float deltaPercent = upperPercent - lowerPercent;
      float deltaIndex = upperIndex - lowerIndex;
      valuePercent = lowerPercent + (deltaPercent / deltaIndex) * (indexFloat - (float) lowerIndex);
    } else {
      valuePercent = lowerPercent;
    }

    if (shade.getValue() < 500) {
      return value + ((1.0f - value) * valuePercent);
    } else {
      return value + (value * valuePercent);
    }
  }
コード例 #2
0
ファイル: Greenhouse.java プロジェクト: myeu/YeungFarm
  public Greenhouse(Timer timer, Sun sun, int numTrays, int DLI) {
    this.numTrays = numTrays;
    setPointDLI = (double) DLI;
    trays = new ArrayList<Tray>();

    Lamp lamp = new Lamp();
    lamp.setPower(true);

    Shade shade = new Shade();
    shade.setPower(true);

    LightSensor lightSensor = new LightSensor(sun, lamp, shade, setPointDLI);
    timer.addTimeSubscriber(lightSensor);
  }
コード例 #3
0
  private void generateShade() {

    DCHalfEdge topEdge =
        new DCHalfEdge(
            new CompPoint(xMainTop[0][1], yMainTop[0]), new CompPoint(xMainTop[0][0], yMainTop[0]));
    shade.addEdgeWithPartner(topEdge);

    // myParent.println("left edge");
    for (int j = 0; j < curveResolution - 1; j++) {

      DCHalfEdge prevEdge = shade.edges.get(shade.edges.size() - 1);
      double dx = xMainBottom[j][0] - xMainTop[j][0];
      double dy = yMainBottom[j] - yMainTop[j];
      double edgeHeight = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));

      double yTop = prevEdge.end.getY();
      double yBottom = prevEdge.end.getY() + edgeHeight;

      DCHalfEdge leftSide =
          new DCHalfEdge(
              new CompPoint(xMainTop[j][0], yTop), new CompPoint(xMainBottom[j][0], yBottom));
      shade.addEdgeWithPartner(leftSide);
    }

    DCHalfEdge prevBottomEdge = shade.edges.get(shade.edges.size() - 1);
    DCHalfEdge bottomEdge =
        new DCHalfEdge(
            new CompPoint(xMainBottom[curveResolution - 2][0], prevBottomEdge.end.getY()),
            new CompPoint(xMainBottom[curveResolution - 2][1], prevBottomEdge.end.getY()));
    shade.addEdgeWithPartner(bottomEdge);

    // myParent.println("right edge");
    for (int j = curveResolution - 2; j >= 0; j--) {

      DCHalfEdge prevEdge = shade.edges.get(shade.edges.size() - 1);
      double dx = xMainBottom[j][0] - xMainTop[j][0];
      double dy = yMainTop[j] - yMainBottom[j];
      double edgeHeight = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));

      double yTop = prevEdge.end.getY();
      double yBottom = prevEdge.end.getY() - edgeHeight;

      DCHalfEdge rightSide =
          new DCHalfEdge(
              new CompPoint(xMainBottom[j][1], yTop), new CompPoint(xMainTop[j][1], yBottom));
      shade.addEdgeWithPartner(rightSide);
    }
    shade.completePartners();
  }
コード例 #4
0
 public static float getModifiedHue(float hue, Shade shade) {
   float s = (float) shade.getValue();
   if (s > 500) {
     // Initial calculations are based on hue being in the range [0.0-1.0]
     // java has the range [0.0-360.0] so we'll do a little conversion
     hue = hue / 360.0f;
     float hueAt900 = (1.003f * hue) - 0.016f;
     hue = ((hueAt900 - hue) / ((float) 900 - (float) 500)) * (s - (float) 500) + hue;
     return hue * 360.0f;
   } else {
     return hue;
   }
 }
コード例 #5
0
  public static float getModifiedSaturation(float saturation, Shade shade) {
    if (shade.getValue() == 500) {
      return saturation;
    }

    if (shade.getValue() < 500) {
      // get the saturation target @ 50:
      // clamp to 0.0
      float f = (0.136f * saturation) - 0.025f;
      float satAt50 = Math.max(f, 0.0f);
      // lerp shade 500->900
      return ((saturation - satAt50) / (500 - 50)) * (shade.getValue() - 50) + satAt50;
    } else {
      // get the saturation target @ 900:
      // quick inaccurate version:
      // 110% of the base saturation (clamped to 1.0)
      //            CGFloat satAt900 = MIN(baseSaturation * 1.10, 1.0);
      // expensive(?) accurate version
      float satAt900 =
          Math.min((-1.019f * saturation * saturation) + (2.283f * saturation) - 0.281f, 1.0f);
      // lerp shade 500->900
      return ((satAt900 - saturation) / (900 - 500)) * (shade.getValue() - 500) + saturation;
    }
  }
コード例 #6
0
  public DoublyConnectedEdgeList[] renderLamp() {

    /*need to calc width and height */
    shade = new Shade(0, maxHeight);
    rib = new Rib(0, maxHeight);
    bottomBase = new Base(0, 0, "bottom");
    topBase = new Base(0, 0, "top");

    calculateDimensions();
    generateRib();
    generateShade();

    shade.translate(myParent.width / 2, myParent.height / 2);

    // add notches
    rib.addNotches(notchWidth, notchHeight, ribNotchOffset, topCirclePos, bottomCirclePos);
    calculateDimensions();

    generateBases(ribNum);

    bottomBase.addNotches(notchWidth * 2, notchHeight, ribNotchOffset, ribNum, false);
    topBase.addNotches(notchWidth * 2, notchHeight, ribNotchOffset, ribNum, false);

    bottomBase.generateHole(bottomHoleWidth);

    topBase.generateHole(topHoleWidth);

    rib.translate(myParent.width / 2, 0);

    // return all parts

    Part[] borders = new Part[4];
    borders[0] = shade;
    borders[1] = rib;
    borders[2] = topBase;
    borders[3] = bottomBase;

    return borders;
  }