Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Transparency... Is it Possible??
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
eggplant_burger




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Tue Jul 01, 2003 11:52 am   Post subject: (No 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...
Mazer




PostPosted: Tue Jul 01, 2003 12:01 pm   Post subject: (No 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.
Mazer




PostPosted: Tue Jul 01, 2003 12:11 pm   Post subject: (No subject)

example
SilverSprite




PostPosted: Tue Jul 01, 2003 12:53 pm   Post subject: (No subject)

thats pretty cool..
Andy




PostPosted: Tue Jul 01, 2003 2:04 pm   Post subject: (No subject)

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




PostPosted: Tue Jul 01, 2003 8:15 pm   Post subject: (No 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.
Tony




PostPosted: Tue Jul 01, 2003 11:06 pm   Post subject: (No 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
eggplant_burger




PostPosted: Wed Jul 02, 2003 2:48 am   Post subject: (No subject)

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




PostPosted: Wed Jul 02, 2003 9:13 am   Post subject: (No 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...
Andy




PostPosted: Wed Jul 02, 2003 9:23 am   Post subject: (No subject)

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




PostPosted: Wed Jul 02, 2003 10:18 am   Post subject: (No 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)
PaddyLong




PostPosted: Wed Jul 02, 2003 1:09 pm   Post subject: (No 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
Homer_simpson




PostPosted: Wed Jul 02, 2003 2:55 pm   Post subject: (No 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...



house.jpg
 Description:
 Filesize:  28.21 KB
 Viewed:  5106 Time(s)

house.jpg


Nitro




PostPosted: 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?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 24 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: