Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {Written by Justin Wright November 2011}
- {Include this text in a menu command. Set up the view and it will output a render file of sun animation}
- {This is free for all to use}
- {This is in a prelimnary state. USE AT OWN RISK!}
- PROCEDURE RenderSunAnimation;
- VAR
- iCount:INTEGER;
- iCount2:INTEGER;
- iReal:REAL;
- iQT:INTEGER;
- QTLongInt:LONGint;
- FileName:STRING;
- hHelidon:HANDLE;
- hLight:HANDLE;
- RenderLength:REAL;
- SunPos:REAL;
- Flip:INTEGER;
- RenderStart:INTEGER;
- RenderEnd:INTEGER;
- x1,y1:REAL;
- rNoNeed:REAL;
- rSunBright:REAL;
- bNoNeed:BOOLEAN;
- gLongitude,gLatitude:REAL;
- {SunPossition: I got this formular from the internet. It is not perfect but very close}
- FUNCTION SunPossition(DayNumber:REAL;Hour:REAL;Latitude:REAL;Longitude:REAL):HANDLE;
- VAR
- FractionalYear:REAL;
- Declination:REAL;
- TimeCorrection:REAL;
- SolarHourAngle:REAL;
- SunAzimuthAngle:REAL;
- SunZenithAngle:REAL;
- SunElevationAngle:REAL;
- BEGIN;
- Latitude:=Deg2Rad(Latitude);
- Longitude:=Deg2Rad(Longitude);
- FractionalYear:=(360/365.25)*(DayNumber + Hour/24);
- FractionalYear:=Deg2Rad(FractionalYear);
- 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);
- TimeCorrection:=0.004297+0.107029*cos(FractionalYear)-1.837877*sin(FractionalYear)-0.837378*cos(2*FractionalYear)-2.340475*sin(2*FractionalYear);
- SolarHourAngle:=(Hour-12)*15 + Rad2Deg(Longitude) + TimeCorrection;
- IF SolarHourAngle>180 Then SolarHourAngle:=SolarHourAngle-360;
- IF SolarHourAngle<-180 Then SolarHourAngle:=SolarHourAngle+360;
- SolarHourAngle:=Deg2Rad(SolarHourAngle);
- Declination:=Deg2Rad(Declination);
- SunZenithAngle:=(sin(Latitude)*sin(Declination))+(cos(Latitude)*cos(Declination)*cos(SolarHourAngle));
- SunZenithAngle:=Rad2Deg(ArcCos(SunZenithAngle));
- SunElevationAngle:=90-SunZenithAngle;
- SunAzimuthAngle:=(sin(Declination)-sin(Latitude)*cos(Deg2Rad(SunZenithAngle)))/(cos(Latitude)*sin(Deg2Rad(SunZenithAngle)));
- SunAzimuthAngle:=Rad2Deg(ArcCos(SunAzimuthAngle));
- SunAzimuthAngle:=SunAzimuthAngle;
- IF -SunElevationAngle > 0 THEN
- BEGIN;
- IF SolarHourAngle>0 THEN SunAzimuthAngle:=360-SunAzimuthAngle;
- hLight:=CreateLight(0,0,0,0,True,True);
- SetLightDirection(hLight,-SunAzimuthAngle,-SunElevationAngle);
- HRotate(hLight,0,0,GetSymRot(GetObject('TheNorth')));
- SunPossition:=hLight;
- END;
- END;
- PROCEDURE AnimateSun;
- BEGIN;
- {This first cycle is for Summer equanox}
- For iCount:= RenderStart to REnderEnd DO
- BEGIN
- iReal:=iCount/RenderLength;
- hLight:=SunPossition(355,iReal,gLongitude,gLatitude);
- IF hLight<>NIL THEN
- BEGIN;
- ReDraw;
- QTWriteFrame(QTLongInt);
- DelObject(hLight);
- Message('Rendering Frame:',iCount);
- END;
- END;
- {This second cycle is for Summer equanox}
- For iCount:= RenderStart to REnderEnd DO
- BEGIN
- iReal:=iCount/RenderLength;
- hLight:=SunPossition(355/2,iReal,gLongitude,gLatitude);
- IF hLight<>NIL THEN
- BEGIN;
- ReDraw;
- QTWriteFrame(QTLongInt);
- DelObject(hLight);
- Message('Rendering Frame:',iCount);
- END;
- END;
- END;
- {AnimateLightUp is not being used. It will fade in a light}
- PROCEDURE AnimateLightUp;
- Function LightUp(hLight:HANDLE):HANDLE;
- VAR
- iType:INTEGER;
- rBright:INTEGER;
- BEGIN;
- GetLightInfo(hLight,iType,rBright,bNoNeed,bNoNeed);
- SetLightInfo(hLight,iType,rBright+5,TRUE,TRUE);
- LightUp:=hLight;
- END;
- BEGIN;
- SetLightInfo(GetObject('TheSun'),0,0,TRUE,TRUE);
- hLight:=GetObject('TheSun');
- For iCount:=1 to 20 Do
- Begin;
- SetText(GetObject('TheTitle'),Concat((5*iCount)) );
- hLight:=LightUp(hLight);
- ReDraw;
- QTWriteFrame(QTLongInt);
- Message('LightUp Frame:',icount);
- End;
- END;
- BEGIN;
- gLatitude:=-36.25;
- gLongitude:=175;
- GetLightInfo(GetObject('TheSun'),rNoNeed,rSunBright,bNoNeed,bNoNeed);
- SetLightInfo(GetObject('TheSun'),0,rSunBright,FALSE,FALSE);
- {You need to place Text object in the drawings. This will allow you to name the animation}
- SetText(GetObject('TheTitle'),StrDialog('Title',''));
- {Place a VW 'North Arrow' In the drawing and name it 'TheNorth'. This next part will get the rotation of your 'TheNorth' Object}
- {The north will rotate the light object 'TheSun'}
- IF GetObject('TheNorth') <> NIL
- THEN
- BEGIN;
- RenderLength:=RealDialog('Length of Animation in secounds','1');
- RenderStart:=7*RenderLength;
- REnderEnd:=18*RenderLength;
- iQT:=QTInitialize;
- QTLongInt:=QTOpenMovieFile(StrDialog('NameMovie',''));
- QTSetMovieOptions(QTLongInt,24,100,True,True);
- AnimateSun;
- QTCloseMovieFile(QTLongInt);
- QTTerminate;
- Message('Done');
- END
- ELSE
- BEGIN;
- AlrtDialog('You Need to Place a North Arrow and Name it TheNorth. Place it now');
- GetPT(x1,y1);
- SetName(CreateCustomObjectN('North Arrow',x1,y1,0,FALSE),'TheNorth');
- AlrtDialog('Next, now rotate it to face north so I can work out where the sun will come from, and run the script again');
- END;
- SetLightInfo(GetObject('TheSun'),0,rSunBright,TRUE,TRUE);
- END;
- RUN(RenderSunAnimation);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement