Reputation: 511
I have some code below:
color = complexity * (255 / iterationCap)
r = (color >> 16) & 255
g = (color >> 8) & 255
b = (color >> 0) & 255
I am trying to calculate the color from a floating point number I get from the color
variable.
Currently, I am using python 3.3 to try to shift the bits and and
them with 255 to get the correct r
, g
, and b
values.
The error I am getting is:
TypeError: unsupported operand type(s) for >>: 'float' and 'int'
Currently I am using the image library to draw pixels to a file and I just tack my color tuple on to an array, which I then feed into Image.putdata(..)
.
Upvotes: 3
Views: 9582
Reputation: 8335
In Python 3 the /
operator is a floating point division. You want to use //
for integer division.
Given your comments about what the code is supposed to do we can write something like:
color = int(complexity * 255 / iterationCap) # gives an integer number from 0 to 255
r = color >> 16
g = color >> 8
b = color
That creates a gray gradient as complexity changes.
Upvotes: 7
Reputation: 44434
Convert into an int before trying to attempt bitwise operations.
color = int(complexity * (255 / iterationCap))
Upvotes: 0
Reputation: 28370
color = long(complexity * (255 / iterationCap))
Since bit shifting floats is an undefined operation.
Upvotes: 0