Script for Drawing in Any Color

Started by KamikazeHighland, Thu 23/06/2011 02:42:48

Previous topic - Next topic

KamikazeHighland

AGS cannot detect a color's RGB or draw in every color, so I wrote a script that allows you to draw with any color, including blue 0-32 and magenta 255,0,255.

You'll need to download a large picture that has every possible color on it.  This increases the size of an otherwise empty game to about 78mb, and might be slow (I haven't tried it on other computers), but no drawing game can be complete if any colors aren't allowed.

You will need the following picture.  I haven't used this as I've made my own, so reply if this one somehow doesn't work as I've described.
http://thomasinterestingblog.files.wordpress.com/2011/06/fullrgbcompressed.png


All that's required to make this script work is this picture, a trigger (hotspot or GUI), three sliders (min = 0, max = 255) or perhaps a prompt, and a sprite with a pixel of transparency.  This transparency goes on top of otherwise transparent magenta and cancels it out, allowing the game to display true magenta.

DynamicSprite* sprite is the large picture.  CopyTransparencyMask is for the picture with one pixel of transparency (when testing I used an alpha channel and NOT transparent magenta).

You'll probably also want to change the sprite.resize from 1024x768.  Reply if you have any questions:
Code: ags

function Sixteen()
{
  Red = Red - 16;
  Row = Row + 1;
}

function ColorPrompt()
{
  Red = SliderRed.Value;
  Green = SliderGreen.Value;
  Blue = SliderBlue.Value;
  while (Red > 15) {
    Sixteen();
  }
  Column = Red;
  RGBX = (Column * 256) + Green;
  RGBY = (Row * 256) + Blue;
  DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(9);
  sprite.Crop(RGBX, RGBY, 1, 1);
  sprite.Resize(1024, 768);
  sprite.CopyTransparencyMask(10);
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawImage(0, 0, sprite.Graphic);
surface.Release();
sprite.Delete();
Display("Color is in Row %d, Column %d.  RGBX is %d, RGBY is %d", Row, Column, RGBX, RGBY);
Row = 0;
Column = 0;
}

monkey0506

Are you seriously suggesting that increasing the size of your game by 78 MB and quite probable slow-downs at run-time would be an acceptable alternative to being able to draw RGB(0, 0, 1) to RGB(0, 0, 255) and RGB(255, 0, 255)?

What would be more reasonable would be modifying the way AGS handles drawing blue values with red and green values of 0 for high color games, and changing how it handles transparency.

I also don't understand what you're using CopyTransparencyMask for. Given the fact that you said the sprite with the transparency in it is 1x1 and the sprite you're trying to copy the transparency mask onto is 1024x768, the function shouldn't be doing anything at all to begin with. Even if you weren't resizing it, what is the alpha transparency supposed to be for?

Also, seeing as you're drawing onto the room background, wouldn't drawing "real magenta" work anyway? Seeing as there's nothing behind the room background, I think AGS doesn't do a transparency replacement against the background.

KamikazeHighland

#2
It's -a- solution.  Obviously it'd be more reasonable to change how the game works but I haven't found that part of the source files yet.

The transparency is there because otherwise the game displays magenta as (254,0,255).  While testing the sprite was actually the size of the room with one pixel of transparency.

What would be far more useful would be being able to accurately detect a color's rgb.  Then there'd be no limit to what you could draw, without the need to have a sprite saved for every light flicker or shadow, for example.

If you don't think my script would be useful while playing, it could come in handy for drawing while still designing a game.

monkey0506

Well you sir have some of the most highly trained color sensitive eyes I have ever heard of in my life. I, myself, would be hard pressed to see the difference between RGB(254, 0, 255) and RGB(255, 0, 255).

Khris

Hmm.
Why not put the blues (and magenta) on a sprite and draw the rest normally...?

monkey:
This *is* an important problem; seeing as the last few attempts of programming Photoshop in AGS suffered from exactly that.

78MB? I can't get over this, sorry, it's just too hilarious. ;D

Calin Leafshade

What about using a single white sprite and tinting it at 100%?

KamikazeHighland

Quote from: Khris on Thu 23/06/2011 10:47:45
78MB? I can't get over this, sorry, it's just too hilarious. ;D

Which I don't understand because the picture itself is only 58 KB...

Scarab

Quote from: KamikazeHighland on Fri 24/06/2011 04:17:23
Quote from: Khris on Thu 23/06/2011 10:47:45
78MB? I can't get over this, sorry, it's just too hilarious. ;D

Which I don't understand because the picture itself is only 58 KB...

Well I saved the picture you linked to as a .bmp, and it was bumped up to 48mb. From what I understand about the way AGS handles pictures, the image cannot be compressed at all, and as such becomes much larger.

Quote from: Khris on Thu 23/06/2011 10:47:45
Hmm.
Why not put the blues (and magenta) on a sprite and draw the rest normally...?

This seems like a viable solution. If there are only 33 values that do not work, surely you can just single them out?

Gilbert

The reason is that, sprite data in an AGS games are not compressed by default, and are RLE encoded when the "compress sprite data" option is checked.
Since each and every single pixel of this image is of a different colour, the retarded RLE sprite compression wouldn't help at all (and possibly even bumps up the size a bit due to overheads).

An alternate way that may help is to make this image a room background (as room background images adopt a better compression scheme than sprites), load this room when the game starts and create a dynamic sprite from its background for this purpose. It still wastes a large amount of memory in game, but at least hopefully the increase in file size of the game won't be that huge.

KamikazeHighland

Quote from: Scarab on Fri 24/06/2011 04:41:19
Quote from: Khris on Thu 23/06/2011 10:47:45
Hmm.
Why not put the blues (and magenta) on a sprite and draw the rest normally...?

This seems like a viable solution. If there are only 33 values that do not work, surely you can just single them out?

Yea, if running GetColorFromRGB will in fact work for every other color besides those thirty three, then it would be a lot easier to have a line of 32x1 for blue, then do:

If Red == 0 && Green == 0 && Blue <= 32, sprite.Crop(1, Blue, 1, 1);

If, however, GetColorFromRGB messes up other colors, any unreliability would mess up any drawing program.  It's just -a- solution, if someone else really needs colors to be specific.

Gilbert

Or, use my solution as described here if you don't mind slight difference from the actual "pure" blue ones.

SMF spam blocked by CleanTalk