% FLYING THROUGH SPACE, By Peter Watt
%I put commenting in for those that like green
% this is my version of the classic windows screen saver Flying Through
% space
% mine is better than windows because you can change the star colour
% and it follows the mouse
% code is kind of rough because i've butcherd through a lot of this to
% make is less lines than it used to be, (more than 200 lines long
%without comments), it still does the same thing that it did before
% mabey even better
% CONSTANTS
const NUM_OF_STARS := 100 % you can change this if your computer
%lags or if you want more or less stars
const MAX_DIS := 200 % controls how far off the screen the star can go
const PROX := 10
const MIDX := maxx div 2
const MIDY := maxy div 2
const SPEED := 10 % if you change this one the program gets messed
const MOUSE_RANGE := 300 % if you make this lower the stars will
%follow the mouse more
%%%%%%VARIABLES%%%%%%% (no duh)
var DelayFactor : nat2 := 300 % delay decreaser
var Xm, Ym, Click : int % mouse
var Key : array char of boolean % nuff said
var Rc : int % random color var
var Length : array 1 .. NUM_OF_STARS of real4 % distance between each
% star
% I could have used the Math.Distance subprogram but my computer is
%messed and
% doesn't allow it
var X : array 1 .. NUM_OF_STARS of int % the x co-ordinate of each star
var Dx : array 1 .. NUM_OF_STARS of int % holds how fast the star moves
% horazontally
var Y : array 1 .. NUM_OF_STARS of int % the Y co-ordinate of each star
var Dy : array 1 .. NUM_OF_STARS of int % like Dx but for the Y
var SX : array 1 .. NUM_OF_STARS of int % used to find the slope
%between the star and the mouse
var SY : array 1 .. NUM_OF_STARS of int % same as SX (almost)
var Size : array 1 .. NUM_OF_STARS of int % holds how big each star is
% if a star is big it looks
%closer (used to give a felling of depth)
var Size2 : array 1 .. NUM_OF_STARS of real % used to increment the
%star size
var C : array 1 .. NUM_OF_STARS of int
%%%%%MAIN%%%%%%%%%
setscreen ("graphics:max,max,nobuttonbar,offscreenonly,nocursor")
% the nocursor parameter dosen't work on my computer (then again it's
%7 years old please tell me if you have the same problem)
% this section initializes each var for each star
% that last line had a ryme
Rc := 0
for Index : 1 .. NUM_OF_STARS
randint (X (Index), 1, maxx)
randint (Y (Index), 1, maxy)
Dx (Index) := 0
Dy (Index) := 0
Size2 (Index) := 1
Size (Index) := 1
randint (C (Index), 1, 15)
end for
colorback (7)
cls
loop
Input.KeyDown (Key)
% changes star color if space bar is pressed
if Key (' ') then
loop
randint (Rc, 0, 15)
exit when Rc not= 7
end loop
end if
mousewhere (Xm, Ym, Click)
%
%
% it is in a for because to repeat every thing for every star
for Index : 1 .. NUM_OF_STARS
% this finds the length and slope between the star and the mouse
% this is were the Math.Distance sub-prog would have been nice
Length (Index) := sqrt ((X (Index) - Xm) ** 2 + (Y (Index) - Ym) ** 2)
SX (Index) := X (Index) - Xm
SY (Index) := Y (Index) - Ym
% this for structure is used to fond the direction that the stars should
%be moving in based on the slope and length
if Length (Index) > PROX then
Dx (Index) := SX (Index) div (Length (Index) div SPEED)
Dy (Index) := SY (Index) div (Length (Index) div SPEED)
end if
% the size of the star is incresed to make it seem like it is
% coming closer, it only increases by .07 because i didnt want them
%to get to big to fast
Size2 (Index) := Size2 (Index) + .07 % if you think .07 is to slow
%then by all means change it
Size (Index) := round (Size2 (Index)) % can't use a real in a draw
%command oviosly
% this section moves the stars and reposistions them if they go
% offscreen
X (Index) := X (Index) + (Dx (Index))
Y (Index) := Y (Index) + (Dy (Index))
% this if is used to check if the stars are on screen
if X (Index) > maxx + MAX_DIS or X (Index) < -MAX_DIS or
Y (Index) > maxy + MAX_DIS or Y (Index) < -MAX_DIS then
% if they aren't then the co-ordinates for the star are randomized
loop
randint (X (Index), Xm - MOUSE_RANGE, Xm + MOUSE_RANGE)
randint (Y (Index), Ym - MOUSE_RANGE, Ym + MOUSE_RANGE)
Length (Index) := sqrt ((X (Index) - Xm) ** 2 + (Y (Index) - Ym) ** 2)
exit when Length (Index) > 4
end loop
% this brings makes the star seem far away again
Size2 (Index) := 1
Size (Index) := 1
end if
% and of course this draw command draws the star , try
%commenting it out and see what happens
drawfilloval (X (Index), Y (Index), Size (Index), Size (Index), Rc)
% okay if you want th stars to be different colours then uncomment
% the nex line
%drawfilloval (X (Index), Y (Index), Size (Index), Size (Index), C (Index))
end for
% this section is used to make it appear as though the stars are
%speeding up you can comment it out if you think it laggs the program
%or it looks bad
%
if DelayFactor > 0 then
DelayFactor := DelayFactor - 10
end if
delay (DelayFactor)
% okay this for structure i got from Adam Bielinski (from his forces
%engine witch was very cool)
% what it does is blurs the screen by drawing random lines that are
%the same colour as the background and gives a cool effect try
%replacing cls with this block to get the blur effect
for Blur : 1 .. 300
drawline (Rand.Int (1, 800) * 2 - 400, Rand.Int (1, 600) * 2 - 300,
Rand.Int (1, 800) * 2 - 400,
Rand.Int (1, 600) * 2 - 300, 7)
end for
View.Update
%cls % clears screen (only do this if you don't wish to use the blur)
end loop
% i would lIke to apologize for the inCorrect grammEr and spelling in this
%program
|