﻿ Background Shifting in a Circle Motion
YOUR JOYFUL MEMBERSHIP CREDENTIALS HAVE NOT BEEN IDENTIFIED. PLEASE ENTER YOUR CREDENTIALS OR JOIN OUR JOYFUL COMMUNITY.

 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)
 Waltersmind (Admin) Library Director / Administrator Posts: 928 Likes Given: 163 Likes Received: 198 in 167 posts Joined: Jun 2014
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```

Dedicated to working with computer programming hobbyists, tinkerers, amateurs, and enthusiasts.
08-20-2017, 05:07 AM
Post: #2
(Print Post)
 KingAshish Member Posts: 56 Likes Given: 46 Likes Received: 10 in 7 posts Joined: Nov 2016 Country of Origin::
Hi!
Nice demo.
But on line 25, the spelling should be "circular" instead of "circler".
08-20-2017, 05:18 AM
Post: #3
(Print Post)
 johnno56 Member Posts: 160 Likes Given: 6 Likes Received: 30 in 27 posts Joined: Apr 2017 Country of Origin::
That's a pretty cool demo... almost totally destroyed my optic nerves... but still pretty cool...

J

May your journey be free of incident.

Live long and prosper.
08-20-2017, 12:18 PM
Post: #4
(Print Post)
 Waltersmind (Admin) Library Director / Administrator Posts: 928 Likes Given: 163 Likes Received: 198 in 167 posts Joined: Jun 2014
@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

Dedicated to working with computer programming hobbyists, tinkerers, amateurs, and enthusiasts.
 « Next Oldest | Next Newest »

Forum Jump:

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