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


Background Shifting in a Circle Motion
06-15-2014, 03:51 AM (This post was last modified: 07-18-2014 01:27 PM by Waltersmind.)
Post: #1
 (Print Post)
Background Shifting in a Circle Motion
Here is a demo I created that demonstrates how to move the background image in a circular motion, like you might see in a game.

Code Snippet: [Select]
ScreenWidth& = 1024
ScreenHeight& = 600

ScreenImage1& = _NEWIMAGE(ScreenWidth&, ScreenHeight&, 32)
ScreenBackBuffer& = _NEWIMAGE(ScreenWidth&, ScreenHeight&, 32)

' ### Change the size of image1& to change the size of the tile.
image1& = _NEWIMAGE(128, 128, 32)

SCREEN ScreenImage1&

StartingPointX& = 0
StartingPointY& = 0
Radius& = 800
Angle! = 0
AngleInc! = 0.5
Degree! = 3.141592654 / 180

_DEST (image1&)
LINE (0, 0)-(_WIDTH(image1&), _HEIGHT(image1&)), _RGB(255, 255, 255), BF
GradientCircle _WIDTH(image1&) / 2, _HEIGHT(image1&) / 2, _HEIGHT(image1&) - _HEIGHT(image1&) / 4, _RGB(0, 255, 0), _RGB(0, 128, 0)

_DEST (ScreenImage1&)

text$ = "Background image shifting in a circler motion..."
textX = (ScreenWidth& - _PRINTWIDTH(text$)) / 2
textY = (ScreenHeight& - _FONTHEIGHT) / 2
_PRINTMODE _KEEPBACKGROUND

DO

   _LIMIT 60

   ' ### Here we need to get the starting point of the top left edge of the rectangler image we will use for the background.
   ' ### If the starting point is outside the image1& dimensions, we must "normalize" it to keep it inside. That way, the
   ' ### background image completely fills the screen and the edges will not be shown. We keep the starting point inside the
   ' ### dimensions of image1& since we are tiling image1& on the background image.

   StartingPointX& = (Radius& * SIN(Angle! * Degree!)) MOD _WIDTH(image1&)
   StartingPointY& = (Radius& * COS(Angle! * Degree!)) MOD _HEIGHT(image1&)
   Angle! = Angle! + AngleInc!

   ' ### The trick here is to paint a rectangular area, the size of the screen or larger, filled with the graphic from image1&.
   FOR y = -_HEIGHT(image1&) TO (ScreenHeight& + _HEIGHT(image1&)) STEP _HEIGHT(image1&)
       FOR x = -_WIDTH(image1&) TO (ScreenWidth& + _WIDTH(image1&)) STEP _WIDTH(image1&)
           _PUTIMAGE (x + StartingPointX&, y - StartingPointY&), image1&
       NEXT
   NEXT

   circlex2 = (ScreenWidth& / 2 - 50) * SIN((360 - (Angle! MOD 360)) * Degree!)
   circley2 = (ScreenHeight& / 2 - 50) * COS((360 - (Angle! MOD 360)) * Degree!)

   _PRINTSTRING (textX, textY), text$

   _DISPLAY
   IF INKEY$ <> "" THEN SYSTEM

LOOP WHILE INKEY$ = ""
SYSTEM

'##############################################################################
'#                                                                            #
'# GradientCircle(X-Coordinate, Y-Coordinate, Radius, InnerCircleColor,       #
'#                OuterCircleColor)                                           #
'#                                                                            #
'##############################################################################
SUB GradientCircle (x1 AS INTEGER, y1 AS INTEGER, radius AS INTEGER, innerColor AS LONG, outerColor AS LONG)

redInc! = -(_RED32(outerColor) - _RED32(innerColor)) / radius
greenInc! = -(_GREEN32(outerColor) - _GREEN32(innerColor)) / radius
blueInc! = -(_BLUE32(outerColor) - _BLUE32(innerColor)) / radius
alphaInc! = -(_ALPHA32(outerColor) - _ALPHA32(innerColor)) / radius

colorInc = 0
FOR r = radius TO 0 STEP -2
   CIRCLE (x1, y1), r, _RGBA(_RED32(outerColor) + (redInc! * colorInc), _GREEN32(outerColor) + (greenInc! * colorInc), _BLUE32(outerColor) + (blueInc! * colorInc), _ALPHA(outerColor) + (alphaInc! * colorInc))
   PAINT (x1, y1), _RGBA(_RED32(outerColor) + (redInc! * colorInc), _GREEN32(outerColor) + (greenInc! * colorInc), _BLUE32(outerColor) + (blueInc! * colorInc), _ALPHA(outerColor) + (alphaInc! * colorInc))
   colorInc = colorInc + 2
NEXT

END SUB

   

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
08-20-2017, 05:07 AM
Post: #2
 (Print Post)
RE: Background Shifting in a Circle Motion
Hi! Smile
Nice demo.
But on line 25, the spelling should be "circular" instead of "circler".
Find all posts by this user
Like Post
08-20-2017, 05:18 AM
Post: #3
 (Print Post)
RE: Background Shifting in a Circle Motion
That's a pretty cool demo... almost totally destroyed my optic nerves... but still pretty cool... Big Grin

J

May your journey be free of incident.

Live long and prosper.
Find all posts by this user
Like Post
08-20-2017, 12:18 PM
Post: #4
 (Print Post)
RE: Background Shifting in a Circle Motion
@Ashish

You are quite correct on the spelling, but there is a little secret about that misspelling. I did it on purpose to see how many people were actually paying attention to my work. You are the first person to bring it up after all these years. Too funny. Good job.

@Johnno

Yes, it is hypnotizing to look at. I actually created that demo to recreate an video game effect that I saw in the old DOS days, as well as some Window's games I purchased some years ago (ie: Jazz Jackrabbit). However, the rotations in those games were a bit slower.

The effects were done on the main title screen and had overlaying menus on them.


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