# Weird and unpredictable effect of strokeWeight

**URL:** <https://discourse.processing.org/t/weird-and-unpredictable-effect-of-strokeweight/40468>\
**Category:** Coding Questions\
**Created:** [January 5, 2023, 5:37pm UTC](https://discourse.processing.org/t/weird-and-unpredictable-effect-of-strokeweight/40468 "2023-01-05T17:37:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vadasambhar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vadasambhar/32/17771_2.png) [@vadasambhar](https://discourse.processing.org/u/vadasambhar)\
**Post date:** [January 5, 2023, 5:37pm UTC](https://discourse.processing.org/t/weird-and-unpredictable-effect-of-strokeweight/40468/1 "2023-01-05T17:37:03Z")

</div>

So I’m trying my hand at generative art, with nested inscribed circles within a square.  
What’s weird is that the exact same code gives wildly different output based on changing just the strokeWeight.

Here’s the link to program:

> **[p5.js Web Editor](https://editor.p5js.org/ashwin.ramaswamy.92/sketches/acMj8usGT)**
>
> A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners.

Try strokeWeights 1, 2 and 3 (and values in between)

Would really love to know what’s going on here. Interestingly there’s no obvious (to me) mapping from strokeweight to the output - value of 1 does what I want it to, 2 is completely unexpected, strokeWeight of 3 behaves as expected again. My guess is it’s a p5 bug, but I can’t think of what’s happening behind the scenes.

---

<div class="post-metadata">

**Author:** ![TimeLex](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/timelex/32/12869_2.png) [@TimeLex](https://discourse.processing.org/u/TimeLex)\
**Post date:** [January 5, 2023, 6:43pm UTC](https://discourse.processing.org/t/weird-and-unpredictable-effect-of-strokeweight/40468/2 "2023-01-05T18:43:22Z")

</div>

I tried it in Processing java mode and the code works fine. So it really has to be a bug but i don’t know how this can happen.

Here is the code for java:

```auto
float side = 400;
int[] colorMults = new int[]{3, 4, 5};

void setup() {
  size(400, 400);
  ellipseMode(RADIUS);
  rectMode(CENTER);
}

void draw() {
  background(220);
  stroke(0);
  noFill();
  side = 5;
  strokeWeight(3);
  for(int i = 1; i < 1000; i++) {
    stroke(side*colorMults[0]%255, 
           colorMults[1]%255, 
           side*colorMults[2]%255);
    rect(width/2, height/2, side, side);
    circle(width/2, height/2, side/2);
    side *= sqrt(2);
  }
}

```

---

<div class="post-metadata">

**Author:** ![TimeLex](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/timelex/32/12869_2.png) [@TimeLex](https://discourse.processing.org/u/TimeLex)\
**Post date:** [January 5, 2023, 6:58pm UTC](https://discourse.processing.org/t/weird-and-unpredictable-effect-of-strokeweight/40468/3 "2023-01-05T18:58:08Z")

</div>

Oh, no it isn’t a bug. You multiply the side-variable every iteration of the for-loop and thats 1000 times! This is exponetionally growth so the side-variable gets larger than the float limit. I guess the JAVA2D renderer handles this issue in an other way. You can simply fix this by decreasing the iteration count of the for loop (for me it works fine with 30).
