Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating images with transparency
#1
In response to http://www.naalaa.com/community/showthread.php?tid=74, I explained that 'set pixel' can be used for creating images with transparency. Here's a small example where I do just that:

Code:
import "Keycodes.lib"

' Create a fuzzy brush.
brushSize = 59

create image 1, brushSize, brushSize
set image 1
radius# = float(brushSize)*0.5
for y = 0 to brushSize - 1
    for x = 0 to brushSize - 1
        dx# = float(x) - radius
        dy# = float(y) - radius
        d# = sqr(dx*dx + dy*dy)
        alpha# = max(1.0 - d/radius, 0.0)
        set color 255, 255, 255, int(alpha*255.0)
        set pixel x, y
    next
next
set image primary

set redraw off
do
    ' Draw some random fuzzy circles.
    for i = 1 to 100
        set color rnd(255), rnd(255), rnd(255), rnd(64)
        draw image 1, rnd(640) - brushSize/2, rnd(480) - brushSize/2
    next
    ' Clear screen with an alpha value of 4.
    set color 0, 0, 0, 12
    cls
    scroll 0, -1
    ' Draw brush at mouse position.
    set color 255, 255, 255
    draw image 1, mousex() - width(1)/2, mousey() - height(1)/2

    ' Redraw and wait.
    redraw
    wait 16
until keydown(VK_SPACE, true)
Reply
#2
Another one, just about the same things but looks kind of fun:

Code:
import "Keycodes.lib"

' Create a fuzzy brush.
brushSize = 59

create image 1, brushSize, brushSize
set image 1
radius# = float(brushSize)*0.5
for y = 0 to brushSize - 1
    for x = 0 to brushSize - 1
        dx# = float(x) - radius
        dy# = float(y) - radius
        d# = sqr(dx*dx + dy*dy)
        alpha# = max(1.0 - d/radius, 0.0)
        set color 255, 255, 255, int(alpha*255.0)
        set pixel x, y
    next
next
set image primary

set redraw off
set color 64, 8, 0
cls
do
    ' Draw some random fuzzy circles.
    set additive true
    for i = 1 to 100
        v = rnd(255)
        set color v, v/2, 0, rnd(128)
        clear transformation
        translate rnd#(640.0), rnd#(480.0)
        scale 0.1 + rnd#(2.0), 0.1 + rnd#(2.0)
        draw image 1
    next
    set additive false
    ' Clear screen with an alpha value of 12.
    set color 64, 8, 0, 12
    cls
    scroll 0, -1

    ' Redraw and wait.
    redraw
    wait 16
until keydown(VK_SPACE, true)
Reply
#3
Uhm ... and then this happened. I call it "The inside of an intergalactic plasma frog"

Code:
import "Keycodes.lib"

' Create a fuzzy brush.
brushSize = 59

create image 1, brushSize, brushSize
set image 1
radius# = float(brushSize)*0.5
for y = 0 to brushSize - 1
    for x = 0 to brushSize - 1
        dx# = float(x) - radius
        dy# = float(y) - radius
        d# = sqr(dx*dx + dy*dy)
        alpha# = max(1.0 - d/radius, 0.0)
        set color 255, 255, 255, int(alpha*255.0)
        set pixel x, y
    next
next
set image primary

set redraw off

create image 2, 640, 480
set image 2
set color 64, 8, 0
cls
set image primary

a# = 0.0
a2# = 0.0
do
    ' Draw some random fuzzy circles.
    set image 2
    set additive true
    for i = 1 to 100
        intens = rnd(255)
        set color rnd(64), intens/2, intens, rnd(128)
        clear transformation
        translate rnd#(640.0), rnd#(480.0)
        scale 0.1 + rnd#(2.0), 0.1 + rnd#(2.0)
        draw image 1
    next
    set additive false
    ' Clear screen with an alpha value of 12.
    set color 64, 8, 0, 12
    cls
    scroll 4, 2
    set image primary

    ' Raster effect
    set color 255, 255, 255, 0
    dv# = 1.0/480.0
    dv = dv*(0.5 + sin(a*1.5)*0.25)
    v# = 0.0
    dummy# = (1.0 + sin(a))*0.5
    for y = 0 to 479
        dx# = 64.0*(1.0 + sin(float(y) + a#))
        draw hraster 2, y, -int(dx), 640 + int(dx), dummy, v, 1.0 - dummy, v
        v = v + dv
    next
    a2 = a2 + 1.2
    a = a + sin(a2)*2.0

    ' Redraw and wait.
    redraw
    wait 16
until keydown(VK_SPACE, true)


This is a perfect example of how terrible I am at explaining simple stuff - I always get carried away *sigh*
Reply
#4
Hi Marcus

Nice examples. Thanks for sharing.[Image: smile.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)