Plotting to window

Just starting out? Need help? Post your questions and find answers here.
PowerSoft
User
User
Posts: 65
Joined: Sun Aug 16, 2015 2:54 pm

Plotting to window

Post by PowerSoft »

Working to code a Planetarium.
Have some base code to open a main screen.
After opening the main screen I need to do some drawings to it.
The routines are stored an a separated file

Where should I put in the procedure call "drawPlanetarium" to get it running? :(

Thanks for any help :lol:

Code: Select all

XIncludeFile "Planetarium.pb"

Enumeration
  #Sun
  #Moon
  ;-------------------
  #Mouse
EndEnumeration


Structure PlanetStructure
  SpriteNo.i
  Name$
  Size.i
  Radius.i
  Speed.f
  Angle.f
  X.i
  Y.i
  Ra.d
  Decl.d
EndStructure

NewList PlanetList.PlanetStructure()


If InitSprite() = 0
  MessageRequester("Error", "Can't open screen & sprite environment!", 0)
  End
EndIf

If OpenWindow(0, 0, 0, 800, 600, "Planetarium", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  If OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
    
    
    CreateSprite(#Mouse, 100, 40)    
    
    Repeat
      ; Es ist sehr wichtig, alle im Queue befindlichen Ereignisse während jedes Frames abzuarbeiten
      ;
      Repeat
        Event = WindowEvent()
      
        Select Event 
          Case #PB_Event_Gadget
            
          
          Case #PB_Event_CloseWindow
            Exit = #True
            
        EndSelect
      Until Event = 0
  
      FlipBuffers()
      ClearScreen(RGB(0, 0, 0))
      
    
     

      ;StopDrawing()
      
      ForEach PlanetList()
        PlanetList()\Angle - PlanetList()\Speed
        If PlanetList()\Angle < 0
          PlanetList()\Angle + 6.28
        EndIf
        PlanetList()\X = MidPoint - PlanetList()\Size / 2 + (Sin(PlanetList()\Angle) * PlanetList()\Radius)
        PlanetList()\Y = MidPoint - PlanetList()\Size / 2 + (Cos(PlanetList()\Angle) * PlanetList()\Radius)
        DisplaySprite(PlanetList()\SpriteNo, PlanetList()\X, PlanetList()\Y)
        MouseX = WindowMouseX(0)
        MouseY = WindowMouseY(0)
        If MouseX > PlanetList()\X And MouseX < PlanetList()\X + PlanetList()\Size
          If MouseY > PlanetList()\Y And MouseY < PlanetList()\Y + PlanetList()\Size
            ;Debug PlanetList()\Name$
            If StartDrawing(SpriteOutput(#Mouse))
              Box(0, 0, 100, 100, 0)
              DrawText(0, 0, PlanetList()\Name$,        RGB(255,255,255)) ; name of planet
              DrawText(0,12, ("Ra="+StrD(PlanetList()\Ra)),   RGB(255,255,255)) ; position of sun
              DrawText(0,24, ("Decl="+StrD(PlanetList()\Decl)), RGB(255,255,255)) ; position of sun
              StopDrawing()
              DisplayTransparentSprite(#Mouse, MouseX + 15, MouseY)
            EndIf
          EndIf
        EndIf        
      Next
      
 
      
    Until Exit
  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
  EndIf
EndIf

Code: Select all

; routines

Global.i LX,LY ; coordinates of element

Procedure AltAz(a.d, h.d, xMax.i, yMax.i)
  Define.d PixPerRad,CentralAngle,x,y,az,alt
  PixPerRad = xMax / 2
  az = a * #PI / 180.0
  alt = h * #PI /180.0
  CentralAngle=ACos(Cos(alt)*Cos(az))
  y=CentralAngle*PixPerRad*Sin(alt)/Sin(CentralAngle)
  y=yMax-y
  x=CentralAngle*PixPerRad*Cos(alt)*Sin(az)/Sin(CentralAngle)
  x=x+xMax/2
  LX=Int(x)
  LY=Int(y)
EndProcedure

Procedure drawPlanetarium()
  For angle=15 To 60 Step 15
    For azimuth=-180 To 180
      AltAz(azimuth, angle, xMax, yMax)
      Plot(LY, LY, RGB(128,255,0))
    Next
  Next
  
  For azimuth=-75 To 75 Step 15
    For h=0 To 90
      If h=0
        AltAz(azimuth,1,xMax,yMax)
        Plot(LY, LY, RGB(128,255,0))
      Else
        AltAz(azimuth,h,xMax,yMax)
        Plot(LY, LY, RGB(128,255,0))
      EndIf
    Next
  Next      
EndProcedure

OS X 10.10.5 PB 5.31(x64)