Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Scaling and Rotating
#3
Cool!

You can also use the raster commands for scaling, flipping and 90 degree rotations. The problem is that 'draw hraster' and 'draw vraster' were created with nothing but raycasting and mode7 in mind (they draw textured horizontal and vertical lines). They treat the alpha channel as "fog density". But as long as you don't need to do colorized/additive drawing and the image data only contains pixels with full opacity or full transparency it works.

Code:
#win32

set window "Raster scaling", 640, 480
set redraw off

img = loadimage("weird.png")

a = 0 ' angle for sin scale effect.
while not keydown(KEY_ESCAPE)   
    a = (a + 0.01)%(PI*2)
    ' calculate width and height.
    w = (0.25 + 0.75*(1.0 + sin(a)))*width(img)
    h = (0.25 + 0.75*(1.0 + sin(a)))*height(img)

    set color 0, 0, 0
    cls
    ' draw centered.
    DrawImageScaled(img, (width(primary) - w)/2, (height(primary) - h)/2, w, h)

    DrawImageRotated90(img, 0, 0)
    redraw
    fwait 60
wend

function DrawImageScaled(img, x, y, w, h)
    if w <= 0 or h <= 0  return
    set color 255, 255, 255, 0
    du = 1/w
    u = 0
    for x = x to x + w - 1
        draw vraster img, x, y, y + h - 1, u, 0, u, 1
        u = u + du
    next
endfunc

function DrawImageRotated90(img, x, y)
    set color 255, 255, 255, 0
    dv = 1/height(img)
    v = 1
    for x = x to x + height(img) - 1
        draw vraster img, x, y, y + width(img) - 1, 0, v, 1, v
        v = v - dv
    next   
endfunc

Full support for drawing transformed images (scaling + rotating) is at the absolute top of my todo list. It'll run faster than this solution.


Attached Files
.zip   raster_scaling.zip (Size: 120.97 KB / Downloads: 8)
Reply


Messages In This Thread
Simple Scaling and Rotating - by 1micha.elok - 02-28-2024, 11:57 AM
RE: Simple Scaling and Rotating - by kevin - 02-28-2024, 04:36 PM
RE: Simple Scaling and Rotating - by Marcus - 02-28-2024, 04:51 PM
RE: Simple Scaling and Rotating - by johnno56 - 02-28-2024, 06:08 PM
RE: Simple Scaling and Rotating - by aliensoldier - 02-28-2024, 09:58 PM
RE: Simple Scaling and Rotating - by 1micha.elok - 02-29-2024, 11:07 AM
RE: Simple Scaling and Rotating - by johnno56 - 03-01-2024, 04:33 AM
RE: Simple Scaling and Rotating - by 1micha.elok - 03-04-2024, 01:11 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)