0

I have made this code to create an image like the one google have when you search color picker.

the problem is in the for loop with j, if that part is commented out then I can click around in the image without slow down. So my question is if there some way to simplify the math or something I don't know about python that makes it slow here.

 def create_palette(src, color):
        width = 255
        height = 255

        for x in xrange(255):
            for y in xrange(255):
                new_color = [color[0],color[1],color[2],255.0]

                x_distance = float(x)/float(width)
                y_distance = float(y)/float(height)

                for j in xrange(3):
                    new_color[j] += float(255-new_color[apply_y]) * x_distance 
                    new_color[j] -= float(new_color[j]) * y_distance

                src.set_at((x,y), new_color)

        return src 
martineau
  • 119,623
  • 25
  • 170
  • 301
  • Although the `for` loop with `j` _is_ in the inner-most part of the nested loops, I doubt it's the causing the issue. If possible, profile your script and to determine where it's _really_ spending most of its time. See question [How can you profile a Python script?](https://stackoverflow.com/questions/582336/how-can-you-profile-a-python-script) for how to do that—it's fairly easy. – martineau Jan 24 '19 at 01:46
  • Thanks i will try that – user3478989 Jan 24 '19 at 13:02

0 Answers0