y_bitmap -
Y_Less - 29.03.2013
y_bitmap
Introduction
This is a sneak-peak at something I've been working on today, but I'm going away for the weekend so I thought I would put it out there for people to at least look at. This script, quite simply, draws bitmaps and saves them. Currently there are only 4 functions, but I intend to add more for things like drawing boxes and circles etc. It does, however, support alpha blending so drawing a pixel "0xFF000080" over another pixel will be slightly transparent to the colour underneath.
As I say, this is a VERY early beta so currently it does every pixel entirely individually and has no optimisations for doing large blocks faster than otherwise possible.
Use
Given the lack of functions, this is really quite simple at this point:
Code:
main()
{
// Create the bitmap we are going to write to (default all white).
new
Bitmap:ctx;
ctx = Bitmap_Create(64, 64);
// Draw a solid red pixel at (10, 10).
Bitmap_WritePixel(ctx, 10, 10, Y_RED | 0xFF);
// Draw a nearly transparent green pixel at (10, 11).
Bitmap_WritePixel(ctx, 10, 11, Y_GREEN | 0x20);
// Save the image to a file.
Bitmap_Write(ctx, "y_bitmap_Example.bmp");
// Destroy the bitmap object to save memory.
Bitmap_Destroy(ctx);
}
Note that the orientation of the image is (0,0) is the top-left corner, so that example will draw the green pixel under the red pixel.
Examples
Because there are only pixel functions so far (though I have some code for blocks and basic text), these example just play about with blending alpha channels:
Generate an image fading from white to red over the whole image.
Code:
y_bitmap_Fade1()
{
new
Bitmap:ctx;
ctx = Bitmap_Create(256, 256);
for (new y = 0; y != 256; ++y)
{
for (new x = 0; x != 256; ++x)
{
Bitmap_WritePixel(ctx, x, y, Y_RED | (x * y / 256));
}
}
Bitmap_Write(ctx, "y_bitmap_Fade1.bmp");
Bitmap_Destroy(ctx);
}
Generate an image fading from white to red vertically, and white to green horizontally.
Code:
y_bitmap_Fade2()
{
new
Bitmap:ctx;
ctx = Bitmap_Create(256, 256);
for (new y = 0; y != 256; ++y)
{
for (new x = 0; x != 256; ++x)
{
Bitmap_WritePixel(ctx, x, y, Y_RED | y);
Bitmap_WritePixel(ctx, x, y, Y_GREEN | x);
}
}
Bitmap_Write(ctx, "y_bitmap_Fade2.bmp");
Bitmap_Destroy(ctx);
}
I should note that I converted these images to .png myself for display here. The script can ONLY generate .bmp files!
Colours
This include uses y_colours with some new names. By default the X11 colours (X11_RED) etc have an alpha already set at 0xAA. This is fine for use in-game but not here, so instead there are "Y" versions of all the colours which are exactly the same but with NO alpha. Doing this:
Code:
Bitmap_WritePixel(ctx, x, y, Y_ALICE_BLUE);
Will not do anything because that is an invisible blue.
Download
This is part of YSI:
https://sampforum.blast.hk/showthread.php?tid=321092