Posts: 46
Threads: 9
Joined: Apr 2022
Reputation:
2
Hi to all
I would like to blend two identical images. I am doing a space game, and I want to show some kind of warp flash in the ship engines
I have a flash sprite (PNG with transparency), and I want to paint two of them, one very close to the other.
But the image blending is not showing the way I like...
This is what QB64 does:
I would like to paint something like this (I made the example in photoshop):
Is there any way to paint this images as the second example?
Thank yoy very much
10 PRINT "Hola! "
20 GOTO 10
Posts: 3,974
Threads: 177
Joined: Apr 2022
Reputation:
219
02-28-2023, 02:53 PM
(This post was last modified: 02-28-2023, 03:07 PM by bplus.)
I have posted a tool/demo for fading one image into another. My previous avatar went from one image to another and back again.
https://qb64phoenix.com/forum/showthread...65#pid2665
Contains an excellent demo and is very simple to use.
To blend two identical images, you must mean put them next to each other, side by side, otherwise they blend into same one image.
Otherwise if the image has transparency and you want to show 2 objects in image side by side just use _PutImage far enough apart that the objects don't overlap.
b = b + ...
Posts: 248
Threads: 44
Joined: May 2022
Reputation:
28
Code: (Select All) Screen _NewImage(800, 600, 32)
image& = _LoadImage("1.png", 32)
W = _Width(image&): H = _Height(image&)
newimage& = _NewImage(W - 1, H - 1, 32)
_PutImage (W \ 2, 0)-(W, H), image&, newimage&, (W \ 2, 0)-(W, H) 'right half
_PutImage (0, 0)-(W \ 2, H), image&, newimage&, (W, 0)-(W \ 2, H) 'left half
_PutImage (100, 100), newimage& 'place done image
PutImage is enought for this use.
Posts: 46
Threads: 9
Joined: Apr 2022
Reputation:
2
(02-28-2023, 03:59 PM)Petr Wrote: Code: (Select All) Screen _NewImage(800, 600, 32)
image& = _LoadImage("1.png", 32)
W = _Width(image&): H = _Height(image&)
newimage& = _NewImage(W - 1, H - 1, 32)
_PutImage (W \ 2, 0)-(W, H), image&, newimage&, (W \ 2, 0)-(W, H) 'right half
_PutImage (0, 0)-(W \ 2, H), image&, newimage&, (W, 0)-(W \ 2, H) 'left half
_PutImage (100, 100), newimage& 'place done image
PutImage is enought for this use.
Thank you Petr... I tried your code with my image, and this is the output:
This is not what I am looking for...
This is my original image. I would like to paint two of them very close without problems. I don't know if it is possible in QB64... anyway thank you very much.
10 PRINT "Hola! "
20 GOTO 10
Posts: 3,974
Threads: 177
Joined: Apr 2022
Reputation:
219
02-28-2023, 05:41 PM
(This post was last modified: 02-28-2023, 05:42 PM by bplus.)
What if you faded the image you made with Photoshop with the image of the spaceship (I assume)?
I could test if I had spaceship image.
b = b + ...
Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
I played around with this for a while and this is the best I could come up with:
Code: (Select All) DIM Image AS LONG ' alpha image
DIM i AS INTEGER ' for/next loop counter
DIM Pulse AS INTEGER ' number of times to overlay image
DIM PulseDir AS INTEGER ' inc/dec pulse counter
Image = _LOADIMAGE("tam1-4.png", 32) ' load alpha image
ImageLeft = _NEWIMAGE(130, 288, 32) ' left image holder
ImageRight = _NEWIMAGE(130, 288, 32) ' right image holder
_PUTIMAGE (0, 0), Image, ImageLeft ' create left image
_PUTIMAGE (0, 0), Image, ImageRight, (74, 0)-(203, 287) ' create right image
SCREEN _NEWIMAGE(640, 480, 32) ' graphics screen
Pulse = 0 ' initialize variables
PulseDir = 1
DO ' begin pulse loop
_LIMIT 30 ' 30 frames per second
CLS
Pulse = Pulse + PulseDir ' increment/decrement pulse amount
IF Pulse > 10 OR Pulse < 1 THEN PulseDir = -PulseDir ' reverse pulse adder
FOR i = 1 TO Pulse ' loop the number of pulses
_PUTIMAGE (32, 0), Image ' overlay alpha image over and over
NEXT i
_PUTIMAGE (0, 0), ImageLeft ' overlay left image
_PUTIMAGE (130, 0), ImageRight ' overlay right image
_DISPLAY ' update screen
LOOP UNTIL _KEYDOWN(27) ' ESC to end
By playing around with the amount of left and right image used you can draw the white beams closer or farther apart. By overlaying the original image in between the two outer images you can create a pulsing effect showing your ion engines increasing/decreasing in power. This also softens the slightly darker line in between the left and right image that no matter how hard I try I can't get rid of.
I took your image and processed two of them overlapping side by side in a few paint programs I have. The result is always the same as what QB64 does, so QB64 is actually blending them properly.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 46
Threads: 9
Joined: Apr 2022
Reputation:
2
(02-28-2023, 05:59 PM)TerryRitchie Wrote: I played around with this for a while and this is the best I could come up with:
Code: (Select All) DIM Image AS LONG ' alpha image
DIM i AS INTEGER ' for/next loop counter
DIM Pulse AS INTEGER ' number of times to overlay image
DIM PulseDir AS INTEGER ' inc/dec pulse counter
Image = _LOADIMAGE("tam1-4.png", 32) ' load alpha image
ImageLeft = _NEWIMAGE(130, 288, 32) ' left image holder
ImageRight = _NEWIMAGE(130, 288, 32) ' right image holder
_PUTIMAGE (0, 0), Image, ImageLeft ' create left image
_PUTIMAGE (0, 0), Image, ImageRight, (74, 0)-(203, 287) ' create right image
SCREEN _NEWIMAGE(640, 480, 32) ' graphics screen
Pulse = 0 ' initialize variables
PulseDir = 1
DO ' begin pulse loop
_LIMIT 30 ' 30 frames per second
CLS
Pulse = Pulse + PulseDir ' increment/decrement pulse amount
IF Pulse > 10 OR Pulse < 1 THEN PulseDir = -PulseDir ' reverse pulse adder
FOR i = 1 TO Pulse ' loop the number of pulses
_PUTIMAGE (32, 0), Image ' overlay alpha image over and over
NEXT i
_PUTIMAGE (0, 0), ImageLeft ' overlay left image
_PUTIMAGE (130, 0), ImageRight ' overlay right image
_DISPLAY ' update screen
LOOP UNTIL _KEYDOWN(27) ' ESC to end
By playing around with the amount of left and right image used you can draw the white beams closer or farther apart. By overlaying the original image in between the two outer images you can create a pulsing effect showing your ion engines increasing/decreasing in power. This also softens the slightly darker line in between the left and right image that no matter how hard I try I can't get rid of.
I took your image and processed two of them overlapping side by side in a few paint programs I have. The result is always the same as what QB64 does, so QB64 is actually blending them properly. Thank you very much TerryRitchie!!! I think I will reuse your code
10 PRINT "Hola! "
20 GOTO 10
Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
No problem
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 46
Threads: 9
Joined: Apr 2022
Reputation:
2
In case anyone is interested, I am going to try to explain in my painful English what I have finally done to solve my problem.
I read the glow PNG and put it in a new image (long) variable (I will call it "source").
If this image's width is (i.e.) 100x100 pixels, I create a 2-dimension array that is 150x100 positions (because I'm going to paste one glow near to the other). I will call this array "destiny".
I read for the first time "source" image pixel by pixel with POINT, and I paste these values onto "destiny" array.
I read again "source" image, and I compare the values of "destiny" array located 50 positions to the right. From both valors, I paste the maximum one onto "destiny".
Finally, i read "destiny" array pixel by pixel, and I write them into another image variable, and then I put this image on the screen.
I hope I have explained myself well... this is my final result, and I like it
10 PRINT "Hola! "
20 GOTO 10
Posts: 46
Threads: 9
Joined: Apr 2022
Reputation:
2
03-03-2023, 09:23 AM
(This post was last modified: 03-03-2023, 09:24 AM by Ikerkaz.)
Another example, now with both images closer:
10 PRINT "Hola! "
20 GOTO 10
|