In c++, a for loop is composed of three parts.
for( initializer; condition; iterator)
The initializer is a statement that gets called when the loop starts, and is usually used to define a local variable to loop with.
The condition is a statement used to determine when to stop the loop.
And the iterator is a statement that gets called each iteration; it's usually used to change the variable being iterated somehow.
For example, here are a couple for loops in c++, and their GDScript equivalent.
for (int i = 0; i < 5; i++)
for i in range(5)
for (int t = 2; t < 6; t+=2)
for t in range(2,6,2)
Because of their flexibility, a for loop in c++ doesn't always have a proper GDScript equivalent; you see, those three statements I described are optional, hence the empty statements in your for loops. It would be a good idea to replace them with while loops, which can still do the same thing.
for (wd = (wd+1)/2; ; )
// As this is just an initializer a while loop with the initializer before it should do the trick.
wd = (wd+1)/2
while true:
# don't worry about an infinite loop; there seems to be a break statement inside this loop to handle that.
You can sometimes have multiple statements in one initializer, like in this one.
for (e2 += dy, y2 = y0; e2 < ed*wd && (y1 != y2 || dx > dy); e2 += dx)
// Due to its complexity, we'll have to break it down into a while loop.
e2 += dy
y2 = y0
while e2 < ed*wd and (y1 != y2 or dx > dy):
...
# at the end of the loop block, call the iterator.
e2 += dx
And as for setPixelColor
, that depends on the way you're drawing. I'm assuming you're manipulating an image, so the function you are looking for is Image.set_pixel(x, y, color)
.
Edit: Just noticed the component of the setPixelColor
function; it's a number instead of a color. For that you'd have to convert it into a color. If you have alpha then you could just do this.
Color(1,1,1, value)
# if not do this.
Color(value, value, value)
# but if the value statement is big, you could ease on readability by doing this.
var col = value
Color(col, col, col)