Issue with Gradient

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

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)

Hello,

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

This looks like Python.

Look up the references for for() and dist():

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:

:)

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?

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

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)
1 Like

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

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

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

:)

2 Likes