Computer Science Canada

Transparency... Is it Possible??

Author:  eggplant_burger [ Tue Jul 01, 2003 11:28 am ]
Post subject:  Transparency... Is it Possible??

I was just wondering if it is possible to have transparent images in Turing. Like if I want to have a sort of watermark picture behind text. This is using a picture from a file.

Author:  Andy [ Tue Jul 01, 2003 11:52 am ]
Post subject: 

ya it is possible but it looks really bad, when ur drawing the picture, instead of using picCopy or picMerge use picXor and that should make the pic somewhat transparent...

Author:  Mazer [ Tue Jul 01, 2003 12:01 pm ]
Post subject: 

yeah... or not. Razz

here's something my friend did that seemed to work quite well for his game. draw whatever you want to be transparent as if it weren't transparent. now, as you may know, all white areas in your picture are transparent by default when the pic is drawn with picMerge. so here's the idea: draw white pixels in a checkerboard pattern over the area that needs to be semi-transparent. it's far from being perfect, of course, but then so is turing. so... to quote penny-arcade, when life gives you shit, make shit-ade.

Author:  Mazer [ Tue Jul 01, 2003 12:11 pm ]
Post subject: 

example

Author:  SilverSprite [ Tue Jul 01, 2003 12:53 pm ]
Post subject: 

thats pretty cool..

Author:  Andy [ Tue Jul 01, 2003 2:04 pm ]
Post subject: 

hmmm hey mazer, what would happen if u used picXor for ur example?

Author:  Mazer [ Tue Jul 01, 2003 8:15 pm ]
Post subject: 

i dunno... try it! Very Happy

i know that for the old version of my game i thought for some reason that it'd be better to use picXor for the pictures instead of clearing the screen after every frame. it was kinda weird because when two ships flew over each other it'd look like the same ship with a different colour.

Author:  Tony [ Tue Jul 01, 2003 11:06 pm ]
Post subject: 

thats cuz picXor kind of overwrites background color with another color by doing some math operation so drawing it twice would result in original background color... or so I understand Confused

ether way, it sucks.

Author:  eggplant_burger [ Wed Jul 02, 2003 2:48 am ]
Post subject: 

wow, I just posted that yesterday, and I already got an answer... You guys rock. Thanks a lot, anyways.

Author:  PaddyLong [ Wed Jul 02, 2003 9:13 am ]
Post subject: 

hmm, might it also work to find a middle colour (like avg of the r, g and b values) for each pixel?

which could also work for varying degrees of transparency...

Author:  Andy [ Wed Jul 02, 2003 9:23 am ]
Post subject: 

ya actually paddylong's idea is pretty good, except its realy slow...

Author:  PaddyLong [ Wed Jul 02, 2003 10:18 am ]
Post subject: 

here is the function to do it
code:

function calcPixel (colr1, colr2, trans : int) : int
    var colours : array 1 .. 3, 1 .. 3 of real
    RGB.GetColour (colr1, colours (1, 2), colours (2, 2), colours (3, 2))
    RGB.GetColour (colr2, colours (1, 3), colours (2, 3), colours (3, 3))
    for rgb : 1 .. 3
        colours (rgb, 1) := (colours (rgb, 2) * ((100 - trans) / 100 * 2) + colours (rgb, 3) * (trans / 100 * 2)) / 2
    end for
    result RGB.AddColour (colours (1, 1), colours (2, 1), colours (3, 1))
end calcPixel


but as dodge said, it is very slow because it has to be done per pixel

here is a demo of it (for those who are too lazy to whip up their own Razz)....
code:

function calcPixel (colr1, colr2, trans : int) : int
    var colours : array 1 .. 3, 1 .. 3 of real
    RGB.GetColour (colr1, colours (1, 2), colours (2, 2), colours (3, 2))
    RGB.GetColour (colr2, colours (1, 3), colours (2, 3), colours (3, 3))
    for rgb : 1 .. 3
        colours (rgb, 1) := (colours (rgb, 2) * ((100 - trans) / 100 * 2) + colours (rgb, 3) * (trans / 100 * 2)) / 2
    end for
    result RGB.AddColour (colours (1, 1), colours (2, 1), colours (3, 1))
end calcPixel

procedure drawBox (x, y, xsize, ysize, colr, trans : int)
    for q : x .. x + xsize
        for w : y .. y + ysize
            drawdot (q, w, calcPixel (whatdotcolour (q, w), colr, trans))
        end for
    end for
end drawBox

drawBox (0, 0, 50, 50, 9, 100)
drawBox (25, 25, 50, 50, 14, 50)

Author:  PaddyLong [ Wed Jul 02, 2003 1:09 pm ]
Post subject: 

here's a better demo that I just thought of when I was walking on the stairs

code:

function calcPixel (colr1, colr2, trans : int) : int
    var colours : array 1 .. 3, 1 .. 3 of real
    RGB.GetColour (colr1, colours (1, 2), colours (2, 2), colours (3, 2))
    RGB.GetColour (colr2, colours (1, 3), colours (2, 3), colours (3, 3))
    for rgb : 1 .. 3
        colours (rgb, 1) := (colours (rgb, 2) * ((100 - trans) / 100 * 2) + colours (rgb, 3) * (trans / 100 * 2)) / 2
    end for
    result RGB.AddColour (colours (1, 1), colours (2, 1), colours (3, 1))
end calcPixel

procedure drawBox (x, y, xsize, ysize, colr, trans : int)
    for q : x .. x + xsize
        for w : y .. y + ysize
            drawdot (q, w, calcPixel (whatdotcolour (q, w), colr, trans))
        end for
    end for
    View.Update
end drawBox

setscreen ("offscreenonly")
loop
    drawBox (Rand.Int (0, maxx - 50), Rand.Int (0, maxy - 50), 50, 50, Rand.Int (8, 14), 50)
end loop

Author:  Homer_simpson [ Wed Jul 02, 2003 2:55 pm ]
Post subject: 

here's a better demo
code:
function calcPixel (colr1, colr2, trans : int) : int
    var colours : array 1 .. 3, 1 .. 3 of real
    RGB.GetColour (colr1, colours (1, 2), colours (2, 2), colours (3, 2))
    RGB.GetColour (colr2, colours (1, 3), colours (2, 3), colours (3, 3))
    for rgb : 1 .. 3
        colours (rgb, 1) := (colours (rgb, 2) * ((100 - trans) / 100 * 2) + colours (rgb, 3) * (trans / 100 * 2)) / 2
    end for
    result RGB.AddColour (colours (1, 1), colours (2, 1), colours (3, 1))
end calcPixel

procedure drawtransdot (x, y, colr, trans : int)

    drawdot (x, y, calcPixel (whatdotcolour (x, y), colr, trans))

    View.Update
end drawtransdot
cls
var picf := Pic.FileNew ("house.jpg")
Pic.Draw (picf, 0, 0, picCopy)
var picc : array 1 .. Pic.Width (picf), 1 .. Pic.Height (picf) of int
for x : 1 .. upper (picc, 1)
    for y : 1 .. upper (picc, 2)
        picc (x, y) := whatdotcolor (x, y)
    end for
end for
drawfillbox (200, 200, 250, 250, 12)
drawfillbox (300, 300, 250, 250, 9)
drawfillbox (250, 250, 300, 200, 14)
var xx, yy := 200
for x : 1 .. upper (picc, 1)
    for y : 1 .. upper (picc, 2)
        drawtransdot (x + xx, y + yy, picc (x, y), 50)
    end for
end for


your also gonna need a picture... i used this one...

Author:  Nitro [ Wed Jul 02, 2003 3:05 pm ]
Post subject:  hmmm...

What if I loaded in a 16m color .jpg....how would I find the RGB values of one of those pixels?

Author:  Homer_simpson [ Wed Jul 02, 2003 3:06 pm ]
Post subject: 

hmmm... i think turing automatically turns 16ms too 256 colors i'm not sure... =/

Author:  PaddyLong [ Wed Jul 02, 2003 3:07 pm ]
Post subject: 

yeah... because even if you tried to use like RGB.AddColour and put it into the array... you would still need to use whatdotcolour.

of course, the other option would be to write a jpg decoder if you are know enough about jpgs to do so mehehe

Author:  Tony [ Wed Jul 02, 2003 3:27 pm ]
Post subject: 

I though Turing (v4) loads .jpg Confused

Author:  PaddyLong [ Wed Jul 02, 2003 5:06 pm ]
Post subject: 

it does... but he wants 16m colour jpgs.. turing only does 256 colours

Author:  krishon [ Wed Jul 02, 2003 5:28 pm ]
Post subject: 

it does? probably cuz i haven't used it in a while...when i made my game i had to use bitmaps...very, very old school...well not that old skool

Author:  Mazer [ Wed Jul 02, 2003 8:33 pm ]
Post subject: 

you can load a picture in turing with as many colours as you want. you can draw that picture in turing without any colour loss. but if you want to do anything with the pixels that the picture is composed of, you'll only be using 256 colours. turing will just find the closest matching colour from the 256 palette. example:
draw a pic in turing (a 24bit bitmap for example). now go over every pixel in the picture using a double for loop and draw the pixel using whatdotcolour as the colour.

code:

% draw the picture at (0, 0)

for x : 0 .. picturewidth
    for y : 0 .. pictureheight
        drawdot (x, y, whatdotcolour (x, y))
    end for
end for


now you'll have the same picture except it's drawn in 256 colours. and quite likely to look quite ugly. maybe even fugly.

Author:  PaddyLong [ Wed Jul 02, 2003 9:48 pm ]
Post subject: 

that's what I was talking about when I said

yeah... because even if you tried to use like RGB.AddColour and put it into the array... you would still need to use whatdotcolour.

Author:  netninja [ Fri Feb 13, 2004 8:50 am ]
Post subject: 

I think .png's can have transperant backrounds, and that 'would' work in turing, but turing doesnt work with png's with now, Anyway, Ive seen someone in my school make a spaceship game like star trek, and the ships overlapped each other, and you couldnt see any leftover color from the spaceship, it was a solid ship, not a ship encased into a rectangle. I'll ask him as soon as possible how he did it. But I hope the future holds png support for turing, it would make our lives much easier.

One thing you could do to make part of your pictures transparent is, you could make a color transparent, by using the Pic.SetTransparentColor, which chooses the color thats transparent on the picture. Its prolly the easiest way, but ill ask that guy what he did anyway. So just draw your ship or character, and make the rest of the rectangle brightgreen for example, and declare that brightgreen is transparent. Lol, its a funny way of doing things although.

var shippic : int := Pic.FileNew ("ship.bmp")
Pic.SetTransparentColor (shippic, brightgreen)

Simple as that Very Happy, and ya, fer sure some of those other methods are defintely slow as hell.

Author:  recneps [ Fri Feb 13, 2004 4:08 pm ]
Post subject: 

Just go into wordperfect or word or whatever, and ceate a watermark on that page, then print screen key Very Happy then go in paint, and crop it down Wink


: