Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

39
LINES

< > BotCompany Repo | #1031973 // Stripes - parallel stripes in any direction

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4230L/23K).

1  
sclass Stripes implements MakesBufferedImage {
2  
  int w, h;
3  
  double angle; // radians
4  
  new L<Color> colors;
5  
  new DoubleList positionsInDirection;
6  
  new L<DoublePt> pixelPositions;
7  
  
8  
  *() {}
9  
  *(int *w, int *h, double *angle, DoubleList *positionsInDirection) {}
10  
  *(int *w, int *h, double *angle, DoubleList *positionsInDirection, L<Color> *colors) {}
11  
  
12  
  public int getWidth() { ret w; }
13  
  public int getHeight() { ret h; }
14  
  
15  
  public BufferedImage getBufferedImage() {
16  
    var img = newBufferedImage(w, h, first(colors));
17  
    var g = graphics(img);
18  
    translateGraphics(g, w*.5, h*.5);
19  
    rotateGraphicsClockwise_radians(g, angle);
20  
    double bigNumber = (w+h)*2;
21  
    int n = numberOfStripes()-1;
22  
    for (int i = 0; i < n; i++) {
23  
      double x1 = positionsInDirection.get(i);
24  
      double x2 = getOr(positionsInDirection, i+1, bigNumber);
25  
      Color color1 = or(cyclicGet(colors, i+1), Color.black);
26  
      /*Color color2 = or(cyclicGet(colors, i+1), Color.white);
27  
      if (eq(color1, color2))*/
28  
        g.setColor(color1);
29  
      /*else
30  
        g.setPaint(new GradientPaint((float) x1, 0, color1, (float) x2, 0, color2));*/
31  
        
32  
      fillPrecisePolygon(g, ll(doublePt(x1, -bigNumber), doublePt(x2, -bigNumber),
33  
        doublePt(x2, bigNumber), doublePt(x1, bigNumber)));
34  
    }
35  
    ret img;
36  
  }
37  
  
38  
  int numberOfStripes() { ret l(positionsInDirection)+1; }
39  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1031973
Snippet name: Stripes - parallel stripes in any direction
Eternal ID of this version: #1031973/19
Text MD5: 7ccf29052003528449ba93cbf507cc67
Transpilation MD5: 8e2872247fb1f4a1989093f7505b0b5b
Author: stefan
Category: javax / image reconstruction [dev.]
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-17 16:08:05
Source code size: 1413 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 249 / 428
Version history: 18 change(s)
Referenced in: [show references]