Advertisement
Assembly_

Solar Animation

Nov 21st, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 5.28 KB | None | 0 0
  1. {Written by Justin Wright November 2011}
  2. {Include this text in a menu command. Set up the view and it will output a render file of sun animation}
  3. {This is free for all to use}
  4. {This is in a prelimnary state. USE AT OWN RISK!}
  5.  
  6. PROCEDURE RenderSunAnimation;
  7. VAR
  8.     iCount:INTEGER;
  9.     iCount2:INTEGER;
  10.     iReal:REAL;
  11.     iQT:INTEGER;
  12.     QTLongInt:LONGint;
  13.     FileName:STRING;
  14.     hHelidon:HANDLE;
  15.     hLight:HANDLE;
  16.     RenderLength:REAL;
  17.     SunPos:REAL;
  18.     Flip:INTEGER;
  19.     RenderStart:INTEGER;
  20.     RenderEnd:INTEGER;
  21.     x1,y1:REAL;
  22.     rNoNeed:REAL;
  23.     rSunBright:REAL;
  24.     bNoNeed:BOOLEAN;
  25.     gLongitude,gLatitude:REAL;
  26.  
  27. {SunPossition: I got this formular from the internet. It is not perfect but very close}
  28. FUNCTION SunPossition(DayNumber:REAL;Hour:REAL;Latitude:REAL;Longitude:REAL):HANDLE;
  29.  
  30. VAR
  31.     FractionalYear:REAL;
  32.     Declination:REAL;
  33.     TimeCorrection:REAL;
  34.     SolarHourAngle:REAL;
  35.     SunAzimuthAngle:REAL;
  36.     SunZenithAngle:REAL;
  37.     SunElevationAngle:REAL;
  38.  
  39. BEGIN;
  40.  
  41.     Latitude:=Deg2Rad(Latitude);
  42.     Longitude:=Deg2Rad(Longitude);
  43.     FractionalYear:=(360/365.25)*(DayNumber + Hour/24);
  44.         FractionalYear:=Deg2Rad(FractionalYear);
  45.    
  46.    
  47.     Declination:=0.396372-22.91327*cos(FractionalYear)+4.02543*sin(FractionalYear)-0.387205*cos(2*FractionalYear)+0.051967*sin(2*FractionalYear)-0.154527*cos(3*FractionalYear) + 0.084798*sin(3*FractionalYear);
  48.     TimeCorrection:=0.004297+0.107029*cos(FractionalYear)-1.837877*sin(FractionalYear)-0.837378*cos(2*FractionalYear)-2.340475*sin(2*FractionalYear);
  49.     SolarHourAngle:=(Hour-12)*15 + Rad2Deg(Longitude) + TimeCorrection;
  50.        
  51.     IF SolarHourAngle>180 Then SolarHourAngle:=SolarHourAngle-360;
  52.     IF SolarHourAngle<-180 Then SolarHourAngle:=SolarHourAngle+360;
  53.    
  54.     SolarHourAngle:=Deg2Rad(SolarHourAngle);
  55.     Declination:=Deg2Rad(Declination);
  56.    
  57.     SunZenithAngle:=(sin(Latitude)*sin(Declination))+(cos(Latitude)*cos(Declination)*cos(SolarHourAngle)); 
  58.     SunZenithAngle:=Rad2Deg(ArcCos(SunZenithAngle));   
  59.  
  60.    
  61.     SunElevationAngle:=90-SunZenithAngle;
  62.    
  63.    
  64.     SunAzimuthAngle:=(sin(Declination)-sin(Latitude)*cos(Deg2Rad(SunZenithAngle)))/(cos(Latitude)*sin(Deg2Rad(SunZenithAngle)));
  65.     SunAzimuthAngle:=Rad2Deg(ArcCos(SunAzimuthAngle));
  66.     SunAzimuthAngle:=SunAzimuthAngle;
  67.    
  68.     IF -SunElevationAngle > 0 THEN
  69.         BEGIN; 
  70.             IF SolarHourAngle>0 THEN SunAzimuthAngle:=360-SunAzimuthAngle;
  71.             hLight:=CreateLight(0,0,0,0,True,True);
  72.             SetLightDirection(hLight,-SunAzimuthAngle,-SunElevationAngle);     
  73.             HRotate(hLight,0,0,GetSymRot(GetObject('TheNorth')));
  74.             SunPossition:=hLight;
  75.         END;
  76. END;
  77.  
  78.  
  79. PROCEDURE AnimateSun;
  80.  
  81. BEGIN;
  82. {This first cycle is for Summer equanox}
  83.                 For iCount:= RenderStart to REnderEnd DO
  84.                             BEGIN
  85.                             iReal:=iCount/RenderLength;
  86.                             hLight:=SunPossition(355,iReal,gLongitude,gLatitude);
  87.                                 IF hLight<>NIL THEN
  88.                                     BEGIN;
  89.                                         ReDraw;
  90.                                         QTWriteFrame(QTLongInt);
  91.                                         DelObject(hLight);
  92.                                         Message('Rendering Frame:',iCount);        
  93.                                     END;
  94.                             END;
  95. {This second cycle is for Summer equanox}                  
  96.                 For iCount:= RenderStart to REnderEnd DO
  97.                             BEGIN
  98.                             iReal:=iCount/RenderLength;
  99.                             hLight:=SunPossition(355/2,iReal,gLongitude,gLatitude);
  100.                             IF hLight<>NIL THEN
  101.                                     BEGIN;
  102.                                         ReDraw;
  103.                                         QTWriteFrame(QTLongInt);
  104.                                         DelObject(hLight);
  105.                                         Message('Rendering Frame:',iCount);        
  106.                                     END;
  107.                             END;
  108. END;               
  109.  
  110.  
  111. {AnimateLightUp is not being used. It will fade in a light}
  112. PROCEDURE AnimateLightUp;
  113. Function LightUp(hLight:HANDLE):HANDLE;
  114. VAR
  115. iType:INTEGER;
  116. rBright:INTEGER;
  117.  
  118. BEGIN;
  119. GetLightInfo(hLight,iType,rBright,bNoNeed,bNoNeed);
  120. SetLightInfo(hLight,iType,rBright+5,TRUE,TRUE);
  121. LightUp:=hLight;
  122. END;
  123.  
  124. BEGIN;
  125.                 SetLightInfo(GetObject('TheSun'),0,0,TRUE,TRUE);
  126.                 hLight:=GetObject('TheSun');
  127.                 For iCount:=1 to 20 Do
  128.                     Begin;
  129.                     SetText(GetObject('TheTitle'),Concat((5*iCount)) );
  130.                     hLight:=LightUp(hLight);               
  131.                     ReDraw;
  132.                     QTWriteFrame(QTLongInt);
  133.                     Message('LightUp Frame:',icount);
  134.                     End;
  135. END;       
  136.  
  137. BEGIN;
  138. gLatitude:=-36.25;
  139. gLongitude:=175;
  140.  
  141. GetLightInfo(GetObject('TheSun'),rNoNeed,rSunBright,bNoNeed,bNoNeed);
  142. SetLightInfo(GetObject('TheSun'),0,rSunBright,FALSE,FALSE);
  143.  
  144. {You need to place Text object in the drawings. This will allow you to name the animation}
  145. SetText(GetObject('TheTitle'),StrDialog('Title',''));
  146.  
  147. {Place a VW 'North Arrow' In the drawing and name it 'TheNorth'. This next part will get the rotation of your 'TheNorth' Object}
  148. {The north will rotate the light object 'TheSun'}
  149.  
  150. IF GetObject('TheNorth') <> NIL
  151.     THEN
  152.         BEGIN; 
  153.             RenderLength:=RealDialog('Length of Animation in secounds','1');
  154.             RenderStart:=7*RenderLength;
  155.             REnderEnd:=18*RenderLength;                
  156.             iQT:=QTInitialize;
  157.             QTLongInt:=QTOpenMovieFile(StrDialog('NameMovie',''));
  158.             QTSetMovieOptions(QTLongInt,24,100,True,True);
  159.            
  160.             AnimateSun;
  161.  
  162.             QTCloseMovieFile(QTLongInt);
  163.             QTTerminate;
  164.             Message('Done');
  165.         END
  166.     ELSE
  167.     BEGIN;
  168.         AlrtDialog('You Need to Place a North Arrow and Name it TheNorth. Place it now');
  169.         GetPT(x1,y1);
  170.         SetName(CreateCustomObjectN('North Arrow',x1,y1,0,FALSE),'TheNorth');
  171.         AlrtDialog('Next, now rotate it to face north so I can work out where the sun will come from, and run the script again');
  172.     END;
  173.  
  174. SetLightInfo(GetObject('TheSun'),0,rSunBright,TRUE,TRUE);
  175. END;
  176. RUN(RenderSunAnimation);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement