Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drawing Tools Subs or Functions with Demo
#19
Fade From One Image to Another
Code: (Select All)
Screen _NewImage(320, 300, 32)
YDI& = _NewImage(_Width, _Height, 32)
snap& = _NewImage(_Width, _Height, 32)
Cls
For i = 1 To 40
    Line (Rnd * _Width, Rnd * _Height)-Step(Rnd * 50, Rnd * 50), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255, Rnd * 255), BF
Next
_PutImage , 0, snap&
Color _RGB32(0, 0, 255), &HFF000000
Cls
_PutImage , snap&, 0
Color &HFFFFFFFF
Locate 2, 5: Print "First image, press any..."
Sleep
Cls
Color &HFF3333FF
Locate 10, 17
Circle (171, 150), 60, &HFFFFAA00
Print "You did it!"
_PutImage , 0, YDI&
Cls
_PutImage , YDI&, 0
Color &HFFFFFFFF
Locate 2, 5: Print "2nd image, press any for fade from first to 2nd images..."
Sleep
Cls
For i = 0 To 100 ' demo gives you control over how fast to transition
    Cls
    fade snap&, YDI&, i / 100
    _Display
    _Limit 50 ' 2 secs is good fade time
Next
Beep

Sub fade (img1&, img2&, frac!) ' from img 1 to img 2
    For y = 0 To _Height(img1&)
        For x = 0 To _Width(img1&)
            _Source img1&: p1~& = Point(x, y)
            _Source img2&: p2~& = Point(x, y)
            PSet (x, y), Ink~&(p1~&, p2~&, frac!)
        Next
    Next
End Sub

Sub cAnalysis (c As _Unsigned Long, outRed, outGrn, outBlu, outAlp)
    outRed = _Red32(c): outGrn = _Green32(c): outBlu = _Blue32(c): outAlp = _Alpha32(c)
End Sub

Function Ink~& (c1 As _Unsigned Long, c2 As _Unsigned Long, fr##)
    Dim R1, G1, B1, A1, R2, G2, B2, A2
    cAnalysis c1, R1, G1, B1, A1
    cAnalysis c2, R2, G2, B2, A2
    Ink~& = _RGB32(R1 + (R2 - R1) * fr##, G1 + (G2 - G1) * fr##, B1 + (B2 - B1) * fr##, A1 + (A2 - A1) * fr##)
End Function

For a 2nd demo, I used Fade 2 Images for Kaleidoscope, fading from first image to next. A little blip when next image is fully shown:


Code: (Select All)
_Title "Kaleidoscope 2 fade to next" 'b+ mod 2022-05-25
' it so obvious to use maptriangle!
Randomize Timer
Dim Shared sH, sW, sHd2, sWd2
sH = 700: sW = 700: sHd2 = sH / 2: sWd2 = sW / 2
Screen _NewImage(700, 700, 32)
_ScreenMove 290, 0

last& = _NewImage(sW, sH, 32)
nextImg& = _NewImage(sW, sH, 32)
Do Until _KeyDown(27)
    _Dest nextImg&
    If Rnd > .1 Then Line (0, 0)-(sW - 1, sH - 1), _RGB32(0, 0, 0, 10), BF Else Cls
    n = (n + 1) Mod 30 + 3
    'If n Mod 2 Then n = n + 1
    ReDim px(0 To n - 1), py(0 To n - 1)
    circleDivN = _Pi(2 / n)
    For i = 0 To n - 1
        px(i) = sWd2 + sHd2 * Cos(i * circleDivN)
        py(i) = sHd2 + sHd2 * Sin(i * circleDivN)
    Next
    For i = 1 To 700
        Line (Rnd * sW, Rnd * sH)-Step(Rnd * 5, Rnd * 5), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), BF
        Circle (Rnd * sW, Rnd * sH), Rnd * 8 + 2, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
    Next
    For i = 1 To 30
        w = Rnd * 700
        Line (sWd2 - w / 2, Rnd * sH)-Step(w, Rnd * 5), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), BF
    Next
    For s = 0 To n - 1
        For i = 0 To n - 1
            _MapTriangle (sWd2, sHd2)-(px((i + s) Mod n), py((i + s) Mod n))-(px((i + 1 + s) Mod n), py((i + 1 + s) Mod n)), nextImg& To(sWd2, sHd2)-(px((i + 2 + s) Mod n), py((i + 2 + s) Mod n))-(px((i + 1 + s) Mod n), py((i + 1 + s) Mod n)), nextImg&
        Next
    Next
    _Dest 0 ' back to screen
    For f = 1 To 25
        fade last&, nextImg&, f / 25
        _Display
        _Limit 100
    Next
    Sound 1100, 1
    If last& Then _FreeImage last&
    last& = _CopyImage(nextImg&)
Loop

Sub fade (img1&, img2&, frac!) ' from img 1 to img 2
    For y = 0 To _Height(img1&)
        For x = 0 To _Width(img1&)
            _Source img1&: p1~& = Point(x, y)
            _Source img2&: p2~& = Point(x, y)
            PSet (x, y), Ink~&(p1~&, p2~&, frac!)
        Next
    Next
End Sub

Sub cAnalysis (c As _Unsigned Long, outRed, outGrn, outBlu, outAlp)
    outRed = _Red32(c): outGrn = _Green32(c): outBlu = _Blue32(c): outAlp = _Alpha32(c)
End Sub

Function Ink~& (c1 As _Unsigned Long, c2 As _Unsigned Long, fr##)
    Dim R1, G1, B1, A1, R2, G2, B2, A2
    cAnalysis c1, R1, G1, B1, A1
    cAnalysis c2, R2, G2, B2, A2
    Ink~& = _RGB32(R1 + (R2 - R1) * fr##, G1 + (G2 - G1) * fr##, B1 + (B2 - B1) * fr##, A1 + (A2 - A1) * fr##)
End Function
b = b + ...
Reply


Messages In This Thread
RE: Drawing Tools Subs or Functions with Demo - by bplus - 05-25-2022, 09:09 PM



Users browsing this thread: 2 Guest(s)