# Issue with Gradient

**URL:** <https://discourse.processing.org/t/issue-with-gradient/30291>\
**Category:** Processing.py\
**Tags:** homework\
**Created:** [May 25, 2021, 10:58pm UTC](https://discourse.processing.org/t/issue-with-gradient/30291 "2021-05-25T22:58:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bridgette](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bridgette](https://discourse.processing.org/u/bridgette)\
**Post date:** [May 25, 2021, 10:58pm UTC](https://discourse.processing.org/t/issue-with-gradient/30291/1 "2021-05-25T22:58:06Z")

</div>

Hello,

I’m trying to make a gradient, yet it just doesn’t seem to work my way. Could someone please let me know what is wrong with the code below? I can’t seem to fix it

```auto
def setup():
  size(550, 700)
  noSmooth()

def draw():
  for(int y = 0; y < height; y++)
    for(int x = 0; x < width; x++)
      float distanceFromCenter = dist(x, y, width/2, height/2)
      stroke(distanceFromCenter)
      point(x, y)

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 25, 2021, 11:19pm UTC](https://discourse.processing.org/t/issue-with-gradient/30291/2 "2021-05-25T23:19:48Z")

</div>

Hello,

Is this also a homework question? Your other posts are.

This looks like Python.

Look up the references for _for()_ and _dist()_:

- [Reference](https://py.processing.org/reference/)

I have no knowledge of Python and was able to get this to work in the Processing software in Python mode in W10 from the references:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/dcf6e589b5e66e56c0a10cad4e35abed903136b2.jpeg)

`:)`

---

<div class="post-metadata">

**Author:** ![bridgette](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bridgette](https://discourse.processing.org/u/bridgette)\
**Post date:** [May 25, 2021, 11:25pm UTC](https://discourse.processing.org/t/issue-with-gradient/30291/3 "2021-05-25T23:25:49Z")

</div>

Hi!

Sorry about that, just fixed it. I tried looking for it in the link you sent, but I don’t think I understood what you meant?

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [May 26, 2021, 2:37am UTC](https://discourse.processing.org/t/issue-with-gradient/30291/4 "2021-05-26T02:37:16Z")

</div>

Your code is half Python, half Java. This should be:

```python
def setup():
  size(550, 700)
  noSmooth()

def draw():
  for y in range(height):
    for x in range(width):
      distanceFromCenter = dist(x, y, width/2, height/2)
      stroke(distanceFromCenter)
      point(x, y)

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 26, 2021, 11:15am UTC](https://discourse.processing.org/t/issue-with-gradient/30291/5 "2021-05-26T11:15:09Z")

</div>

> [@bridgette](#):
>
> I tried looking for it in the link you sent, but I don’t think I understood what you meant?

Hello,

I provided you with a link to the Python references.

The reference to _for()_ in the Python references shows how to do a for() loop in Python:  
[https://py.processing.org/reference/for.html](https://py.processing.org/reference/for.html)

I was helping you by directing you to resources that will help you with this problem and future ones.  
I do not work with Python and was able to answer your question and write code from those references.

I generally “Favor process over syntax”:  
[https://discourse.processing.org/t/guidelines-answering-questions/2145](https://discourse.processing.org/t/guidelines-answering-questions/2145)

Providing you with complete code will not help you in the long run:  
[https://discourse.processing.org/faq#homework](https://discourse.processing.org/faq#homework)

`:)`
