Planet Animation

Previous topic - Next topic

Norby

I am new to GL Basic.  I like to try out different languages.

I created the following program, but when I run the code, the screen appears, then closes.  Nothin appears or happens but it appears and disappears.

Could anyone explain to me what I am doin wrong?

Code (glbasic) Select


// --------------------------------- //
// Project: Time Bot
// Start: Sunday, June 14, 2015
// IDE Version: 12.308
// --------------------------------- //

// Note: Program Uptime: Uptime# = GETTIMERALL()
// PRINT Msg$, X, Y

SEEDRND GETTIMERALL()

SETSCREEN 640, 400, 0
CLEARSCREEN RGB(0, 0, 0)

LOADANIM "Font.png", FontSprite, 8, 16
LOADSPRITE "Sun.png", SunSprite
LOADSPRITE "Moon.png", MoonSprite

// Global Variables
GLOBAL SunSprite=1
GLOBAL MoonSprite=2
GLOBAL FontSprite=3

GLOBAL Angle = 0
GLOBAL Planet = 318
GLOBAL Reds = 0
GLOBAL Greens = 0
GLOBAL Blues = 0
GLOBAL Increment = .004365 * 3
GLOBAL NumStars = 1000

GLOBAL StarRad[]
GLOBAL StarAngle[]

DIM StarRad[NumStars]
DIM StarAngle[NumStars]

LOCAL X, Y
FOR i = 1 TO NumStars
  X = (RND(640) - 320)
  Y = (RND(400) - 200)
  // Convert StarX, StarY
  StarRad[i] = X
  StarAngle[i] = Y
NEXT

GLOBAL StarIncrement = Increment / 5

LOCAL Touch$
LOCAL Quit = 0
WHILE Quit=0
  GOSUB SkyUpdate
  Touch$ = INKEY$()
  IF Touch$="Q" THEN Quit = 1
WEND
END

SUB SkyUpdate:
LOCAL StarX, StarY
LOCAL SunX, SunY
LOCAL MoonX, MoonY
LOCAL Time$, Hours, Minutes, Seconds, Timer

Greens = 255 * .5 * SIN(Angle)
IF Greens < 0 THEN Greens = 0

Blues = 255 * 1 * SIN(Angle)
IF Blues < 0 THEN Blues = 0
DRAWRECT 0, 0, 640, 400, RGB(0, Greens, Blues)

// Rotate AND redraw stars.
FOR i = 1 TO NumStars
   StarX = StarRad[i] * COS(StarAngle[i])
   StarY = StarRad[i] * SIN(StarAngle[i]) - 200
   // Convert X,Y

   SETPIXEL StarX, StarY, RGB(150, 150, 200)
   StarAngle[i] = StarAngle[i] + StarIncrement
NEXT

// Draw the Sun
SunX = Planet * COS(Angle)
SunY = Planet * SIN(Angle) + 158
// Convert X, Y

ZOOMSPRITE SunSprite, SunX, SunY, 2, 2

// Draw the Moon
MoonX = Planet * COS(Angle + 3.14159)
MoonY = Planet * SIN(Angle + 3.14159) + 158
//Convert X, Y

ZOOMSPRITE MoonSprite, MoonX, MoonY, 2, 2

// Roate the sun/moon angle.
Time$ = PLATFORMINFO$("TIME")
Hours# = 3600 * LEFT$(Time$, 2)
Minutes# = 60 * MID$(Time$, 3, 2)
Seconds# = RIGHT$(Time$, 2)
Timer = Hours + Minutes + Seconds

Angle = (2 * 3.14159) * (Timer / 86400) - 3.14159 / 2

SHOWSCREEN
RETURN

ENDSUB


MrTAToad

#1
You are getting this error message (well, you would if you ran in debug  mode :) ) :

Quotebounds: [1000]
access: [1000]
error: 9
"C:\Users\Me\Documents\GLBasic\Test Programs\Test\moo.gbas"(44) error : Out of DIM array

which means you are trying to access part of an array that hasn't been defined.

You should be using :

Code (glbasic) Select
FOR i = 0 TO NumStars-1

for all array accessing (in GLBasic, array indicies start at 0, not 1)[/code]

To start with you'll end up with a program that looks like the included picture.

"How do I get rid of the black bits", I hear you cry.  Quite simple : You have two choices : either add an alpha layer to your graphics, or put
Code (glbasic) Select
SETTRANSPARENCY 0 before your first loading command.

You then end up with the second picture.

MrTAToad

By the way, you might be interested in the free Programmer's Reference Guide (and other books) at http://triority.uk/books.html.  You've got until July 12th to download it as I'm closing the website.

Paul Smith

Your sites not been  up that long,  if you need your books hosting let me know. I have an old freedom2serve account that still works 5 years after I left.(tiscali and talktalk aquired them and killed them off).

Sent from my M470BSE using Tapatalk

Amstrad CPC 6128, ATARI STE.
Acer  SW5-173 & AMD RYZEN 7,RTX 3060TI

MrTAToad

It's been a year now - I'm getting rid of it mainly because I would have to start paying for it :)

The PRM is available on other sites - free-ebooks
Net being one

CW

Thank you for the GLB Programer's Reference Book, MapChap. It is a valuable resource that I will reference often. The section on 3D graphics is especially interesting to me.

-CW

erico

Yep, the books are awesome, I bought 2 of them online, digital versions, got both printed locally. :good:

Welcome Norby, was the info helpfull? Did you get around it?

MrPlow

Welcome to the Wonderous world of GLB!! :)
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

MrTAToad

Glad you like the books!

Ian Price

Did you scare him off? :(
I came. I saw. I played.

MrTAToad