You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


Bad TV Reception (Simple) using _MEM commands
08-21-2017, 04:02 AM (This post was last modified: 08-21-2017 04:04 AM by Waltersmind.)
Post: #1
 (Print Post)
Bad TV Reception (Simple) using _MEM commands
While speaking to Ashish about them _MEM commands, I told him that I had some demos I wrote using those instructions, but I never published them. Matter of fact, I have tons of demos I have never posted before, anywhere, and I told Ashish that I would start sharing them with the community.

Well, one demo I found buried deep in my treasure chest of code demos, was a attempt at recreating bad reception on older cathode ray tube television screens from the old days (one's I grew up with). This demo was created a few years ago (can't remember exactly when), but it was a recreation of one I created in JavaScript when HTML5 first came into play. That was my first graphics test I done with the HTML5 Canvas element. The JavaScript version was much more complex, as well as faster than the QB64 version, and it ran on a bigger screen size then this demo. I don't know why the JavaScript version was better, but I believe it had to do with how direct access to the images memory was implemented between the two languages.

This version of the demo only fades color from normal to greyscale, and it adds a lot of static to the image. On my machine, it runs around 20-30 frames a second.

All of this magic is done with the _MEM commands.

Here are some screenshots:

                   


Here is the source code:

Code Snippet: [Select]
CONST Degrees = 0.0174532925

DIM MainWindow AS LONG '                This image is our primary window.
DIM BackBuffer AS LONG '                This image will hold our updating image.

DIM ImageSrcBuffer AS _MEM '               This buffer will allow quick access to our BackBuffer data.
DIM ImageDstBuffer AS _MEM

DIM CurrentOffset AS _UNSIGNED LONG
DIM MaxOffset AS _UNSIGNED LONG

DIM ScreenWidth AS INTEGER '            This is how wide we want our display window and BackBuffer to be.
DIM ScreenHeight AS INTEGER '            This is how height we want our display window and BackBuffer to be.

DIM Red AS INTEGER '                      Red color component
DIM Green AS INTEGER '                    Green color component
DIM Blue AS INTEGER '                     Blue color component
DIM Alpha AS INTEGER '                    Alpha color component
DIM Gray AS INTEGER
DIM OriginalColor AS _UNSIGNED LONG
DIM NewColor AS _UNSIGNED LONG

DIM MaxAdd AS _UNSIGNED INTEGER '
DIM HalfMax AS _UNSIGNED INTEGER '
DIM Monochrome AS INTEGER '

ScreenWidth = 500
ScreenHeight = 400

MainWindow = _NEWIMAGE(ScreenWidth, ScreenHeight, 32)
BackBuffer = _NEWIMAGE(ScreenWidth, ScreenHeight, 32)

SCREEN MainWindow
_TITLE "The Joyful Programmer's - Bad TV Reception (Simple)"

' *** Get BackBuffer data
ImageSrcBuffer = _MEMIMAGE(BackBuffer)
ImageDstBuffer = _MEMIMAGE(MainWindow)

_DEST BackBuffer

MaxOffset = ScreenWidth * ScreenHeight * 4

DO

    _LIMIT 30

    '$CHECKING:OFF

    CurrentOffset = 0

    ' *** Draw some stuff to our backbuffer
    FOR I = 0 TO 0
        LINE (RND * ScreenWidth, RND * ScreenHeight)-(RND * ScreenWidth, RND * ScreenHeight), _RGB(RND * 256, RND * 256, RND * 256), BF
    NEXT

    MaxAdd = RND * 256
    HalfMax = MaxAdd / 2


    DO
        _MEMGET ImageSrcBuffer, ImageSrcBuffer.OFFSET + CurrentOffset, OriginalColor

        Red = _RED32(OriginalColor)
        Green = _GREEN32(OriginalColor)
        Blue = _BLUE32(OriginalColor)

        Gray = Red * 0.3 + Green * 0.59 + Blue * 0.11

        Monochrome = INT(RND * MaxAdd) - HalfMax

        Red = Red + Monochrome: IF Red > 255 THEN Red = 255
        Green = Green + Monochrome: IF Green > 255 THEN Green = 255
        Blue = Blue + Monochrome: IF Blue > 255 THEN Blue = 255
        Gray = Gray + Monochrome: IF Gray > 255 THEN Gray = 255

        IF (MaxAdd > 196) THEN
            NewColor = _RGB32(Gray, Gray, Gray)
        ELSE
            NewColor = _RGB32(Red, Green, Blue)
        END IF

        _MEMPUT ImageDstBuffer, ImageDstBuffer.OFFSET + CurrentOffset, NewColor

        CurrentOffset = CurrentOffset + 4

    LOOP UNTIL CurrentOffset = MaxOffset

    $CHECKING:ON

    _DISPLAY
    k& = _KEYHIT

LOOP UNTIL k& = 27

SYSTEM


Walter Whitman
The Joyful Programmer

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Rubix's Magic
QB64 Member Project - Basic Dithering
QB64 Member Project - Qubic
QB64 Member Project - Color Rotating Text
QB64 Member Project - Overboard
QB64 Member Project - Foursight
QB64 Member Project - Connect Four
QB64 Member Project - Othello
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Dakapo
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Martin Fractals version two
QB64 Member Project - Touche
QB64 Member Project - Kings Court
QB64 Member Project - Dreamy Clock
QB64 Member Project - Pivet version one
QB64 Member Project - Swirl
QB64 Member Project - Kings Vallery version two
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - OpenGL Triangles
QB64 Member Project - 9 Board
QB64 Member Project - Quarto
QB64 Member Project - Algeria Weather
QB64 Member Project - Splatter
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Point Blank
QB64 Member Project - Exit
QB64 Member Project - Input
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Domain
QB64 Member Project - Spiro Roses
QB64 Member Project - ARB Checkers
QB64 Member Project - Line Thickness
QB64 Member Project - Inside Moves
QB64 Member Project - Color Triangles
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Martin Fractals version one
QB64 Member Project - Score 4
QB64 Member Project - Isolation
QB64 Member Project - Sabotage
QB64 Member Project - Full Color LED Sign
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Bowditch curve
QB64 Member Project - Blokus
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Pivot version two
QB64 Member Project - Rotating Background
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - Amazon