Esempio n. 1
1
  @Override
  public void run() {
    try {
      // Open socket
      socket = new Socket("127.0.0.1", 5432);
      // Get input streams
      DataOutputStream writer =
          new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
      DataInputStream scanner = new DataInputStream(socket.getInputStream());
      // Send calculation data
      writer.writeDouble(zoom);
      writer.writeDouble(zoomTranslateX);
      writer.writeDouble(zoomTranslateY);
      writer.writeInt(level);
      writer.writeInt(mode);
      writer.flush();
      System.out.println("Sent data");

      // Wait for server to do calculations
      while (scanner.available() == 0) {
        Thread.sleep(level);
      }
      System.out.println("Start drawing");
      // Start reading and drawing
      application.clearKochPanel();
      int counter = 0;
      while (true) {
        if (scanner.available() > 0) {
          application.drawEdge(
              new Edge(
                  scanner.readDouble(),
                  scanner.readDouble(),
                  scanner.readDouble(),
                  scanner.readDouble(),
                  Color.hsb(scanner.readDouble(), 1, 1)));
          counter = 0;
        } else {
          Thread.sleep(10);
          counter++;
          if (counter > 10) {
            break;
          }
        }
      }
      System.out.println("Finished drawing!");

      writer.writeChar('H');
      writer.flush();
      writer.close();
      scanner.close();
      socket.close();
    } catch (Exception e) {
      System.out.println("Receiving edges failed!");
      System.out.println(e.getMessage());
      Thread.currentThread().interrupt();
    }
  }
        @Override
        protected void invalidated() {

          if (!changeIsLocal) {
            changeIsLocal = true;
            color.set(Color.hsb(hue.get(), clamp(sat.get() / 100), clamp(bright.get() / 100)));
            changeIsLocal = false;
          }
        }
Esempio n. 3
0
 private LinearGradient buildHueBar() {
   double offset;
   Stop[] stops = new Stop[255];
   for (int y = 0; y < 255; y++) {
     offset = (double) (1.0 / 255) * y;
     int h = (int) ((y / 255.0) * 360);
     stops[y] = new Stop(offset, Color.hsb(h, 1.0, 1.0));
   }
   return new LinearGradient(0f, 0f, 1f, 0f, true, CycleMethod.NO_CYCLE, stops);
 }
    @Override
    public void visit(Shepherd s) {
      Stream.iterate(
          Color.RED, c -> Color.hsb(c.getHue() + .1, c.getSaturation(), c.getBrightness()));

      SpriteView tail =
          s.getAnimals().isEmpty() ? s : s.getAnimals().get(s.getAnimals().size() - 1);
      s.getAnimals()
          .addAll(
              Stream.iterate(tail, SpriteView.Lamb::new)
                  .substream(1, 8)
                  .collect(Collectors.toList()));
    }
Esempio n. 5
0
  private Color[] getSectionColors(
      final Color LCD_BACKGROUND_COLOR, final Color LCD_FOREGROUND_COLOR) {
    double hue = LCD_BACKGROUND_COLOR.getHue();
    double sat = LCD_BACKGROUND_COLOR.getSaturation();

    Color[] colors;
    if (Helper.isMonochrome(LCD_BACKGROUND_COLOR)) {
      // Section color is monochrome
      colors =
          new Color[] {
            Color.hsb(hue, 0, 0.69),
            Color.hsb(hue, 0, 1.0),
            Color.hsb(hue, 0, 0.76),
            Color.hsb(hue, 0, 0.76),
            Color.hsb(hue, sat, 0.69),
            Helper.isDark(LCD_BACKGROUND_COLOR) ? Color.WHITE : Color.BLACK,
            Helper.isDark(LCD_BACKGROUND_COLOR)
                ? Color.rgb(255, 255, 255, 0.1)
                : Color.rgb(0, 0, 0, 0.1)
          };
    } else {
      // Section color is not monochrome
      colors =
          new Color[] {
            Color.hsb(hue, sat, 0.69),
            Color.hsb(hue, sat, 1.0),
            Color.hsb(hue, sat, 0.76),
            Color.hsb(hue, sat, 0.76),
            Color.hsb(hue, sat, 0.69),
            LCD_FOREGROUND_COLOR,
            Color.color(
                LCD_BACKGROUND_COLOR.getRed(),
                LCD_BACKGROUND_COLOR.getGreen(),
                LCD_BACKGROUND_COLOR.getBlue(),
                0.1)
          };
    }
    return colors;
  }
Esempio n. 6
0
 private void updateSectionColors() {
   int listSize = sections.size();
   sectionColorMap.clear();
   for (int i = 0; i < listSize; i++) {
     Color sectionColor = sections.get(i).getColor();
     Color lcdForegroundColor;
     if (Helper.isMonochrome(sectionColor)) {
       lcdForegroundColor = Helper.isDark(sectionColor) ? Color.WHITE : Color.BLACK;
     } else {
       lcdForegroundColor =
           Color.hsb(
               sectionColor.getHue(),
               sectionColor.getSaturation(),
               sectionColor.getBrightness() * 0.3);
     }
     Color lcdBackgroundColor =
         Color.color(sectionColor.getRed(), sectionColor.getGreen(), sectionColor.getBlue(), 0.1);
     sectionColorMap.put(
         sections.get(i), getSectionColors(lcdBackgroundColor, lcdForegroundColor));
   }
 }
Esempio n. 7
0
 private void drawKochEdge(double ax, double ay, double bx, double by, int n) {
   if (!cancelled) {
     if (n == 1) {
       hue = hue + 1.0f / nrOfEdges;
       Edge e = new Edge(ax, ay, bx, by, Color.hsb(hue * 360.0, 1.0, 1.0));
       this.setChanged();
       this.notifyObservers(e);
     } else {
       double angle = Math.PI / 3.0 + Math.atan2(by - ay, bx - ax);
       double distabdiv3 = Math.sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay)) / 3;
       double cx = Math.cos(angle) * distabdiv3 + (bx - ax) / 3 + ax;
       double cy = Math.sin(angle) * distabdiv3 + (by - ay) / 3 + ay;
       final double midabx = (bx - ax) / 3 + ax;
       final double midaby = (by - ay) / 3 + ay;
       drawKochEdge(ax, ay, midabx, midaby, n - 1);
       drawKochEdge(midabx, midaby, cx, cy, n - 1);
       drawKochEdge(cx, cy, (midabx + bx) / 2, (midaby + by) / 2, n - 1);
       drawKochEdge((midabx + bx) / 2, (midaby + by) / 2, bx, by, n - 1);
     }
   }
 }
Esempio n. 8
0
 @Override
 public Color getColor() {
   return Color.hsb(359, .9, .9, 0);
 }