# Pixel Colour Changing

I made a project that processes through all the pixels in an image, finds a specific one that has a specific colour and changes it. In my project, I have a drawing of a red 1971 Corvette with a bit of a cornflower blue background.

It grabs all pixels with the same RGBA value of red and blue and changes it to a randomly picked colour. It then switches the costume of the sprite to those pixels and stamps it onto the stage. It repeats this process however many times the user wants. It stores all the new drawings inside a visible list. It also has a view image feature at the end of the process. The user simply presses the view button and selects an image they want to see clearly from the list, or they can cycle through all the images with 5 seconds between each.

Example Outputs

During the process, it supplies information such as average time between each new drawing, progress in the form of a percent, estimated time to finish in minutes and seconds and variables that tell you how many pixels the code has to process to read your image correctly. To change the image, simply upload your own image and ensure that the image name is "pixel-frame-0" with a space at the end (to make it easier with all the switch costume blocks).

What I Need Help With
If there are any bugs or glitches please tell me on this forum. Also, you might notice after looking in the code, there is a script that removes the red outline on the car. Unfortunately, the outline contains many different colours and I cant seem to get them right. If anyone can find a solution, it'd be very appreciated if you could share it on this forum. Thank you very much in advance!
...Oh. And I also need a better name for the project and the forum. The current one is terrible.

Car repainting? Body shop?

If you're going to put more than one of these on the stage, don't you want the background to be transparent?

I would edit a copy of the picture, use the paint can to paint over everything but the red outline with transparent paint (I will never understand why "real" painting software doesn't have this abstraction of transparent paint), then use what's left as a mask to select the border pixels of the repainted cars.

(Even though Jens tells me this is impossible, I want Snap! to do graphics without antialiasing, then at the last microsecond antialias the actual visible stage, but continue to use the non-antialiased version for COLOR AT and so on.)

I feel like that would be a little too specific. I made the project for every picture, not just car pictures.

I don't think that is the problem though. I know I'm getting the right colours because I'm using the colour [ ] block from @helicoptur to select the colour then getting the RGBA of it.

I think it's one of those problems that you just can't fix.

...Without nonzero tolerance.

Do you understand what aliasing does? I'm not sure how much to explain.

But @warped_wart_wars is right; the pixels in that border aren't all the same color. You'd have to compute the difference between the color you're looking at and the border color (sum of absolute values of R, G, B differences) and select the point if that difference is less than some number, say 20.

Yeah, no. I don't understand. Sorry, maybe someone else could explain.

:~( I can explain antialiasing; I just didn't know if that was necessary!

In the old days, when you drew a line on the screen at an angle that's not a multiple of 45 degrees, you'd get a zigzag or "staircase" effect:

Those gray pixels look weird blown up this much, but when you zoom out, what you see looks like a perfectly straight line, without zigzags.

When I was a Stanford CS grad student, the Lucasfilm computer graphics people used to hang out in t-shirts like this:

(search for "no jaggies t-shirt") because antialiasing was a newly invented technique and they were early adopters.

Somewhat later than that, I had an HP laser printer that couldn't do antialiasing that way because it could only print black or white pixels, but it did something similar: it printed some pixels with a smaller diameter, effectively doubling the resolution, to get smoother serifs on fonts.

Anyway, this is great for making straight lines look straight, but it's not so great if you're trying to examine the pixels of an image thinking that everything that looks the same color will have the same RGB values. (Transparency is also sometimes used to help with antialiasing, because you don't want a half-red pixel to be red+white; you want it to be red+whatever the adjacent color is.)

Does that help?

This is a higher definition version, showing what I did:

I called it "gradient". I also have a transparency version.

Yes, this helps in explaining why I couldn't get it right. Thank you very much.

Can anyone give me a more accurate way of estimating how long it will take to finish? Here is the script I currently have:

You can take a closer look at the whole script in the link above (first post). Help would be greatly appreciated. Thanks!

I don't know, but I do know that this script needlessly takes ϴ(n²) time instead of ϴ(n) time. Make a a global variable (with a better name), get rid of the SET A TO 0, and replace the FOR loop with just CHANGE A BY (ITEM LAST OF TIMES).

Thanks!

Are there any other areas where you think the code can be improved?