%Created by Adam Bielinski
%Just a simple program that imitates the windows screensaver
%it looks better, and the center is at the mouse, and not the center of the screen
%if you want, you can change these two variables to resize the effective screen
const X_SCREEN := 1024
const Y_SCREEN := 768
View.Set ("noecho")
View.Set ("nobuttonbar")
View.Set ("title:Stars 3D by Adam Bielinski")
setscreen ("graphics:" + intstr (X_SCREEN) + ";" + intstr (Y_SCREEN))
View.Set ("position:centre,middle")
View.Set ("offscreenonly")
drawfillbox (-10, -10, X_SCREEN, Y_SCREEN, black)
%number of stars. if you're getting a slowdown, decrease this
const NUM_STARS := 800
%initial speed ratio of the stars (make 0.95 for a cool effect)
%this is left 1 now because it is not needed
const STAR_SPEED := 1
%how fast the stars grow in size
const STAR_LIFE := 1.018
%how relatively big the stars are
const STAR_SIZE := 6
%how fast the stars fly away fromt the center
const STAR_ACC := 0.1
type point_type :
record
x : real
y : real
life : real
end record
var stars : array 1 .. NUM_STARS of point_type
%this is the initialatation stuff. It just puts them around on the screen at random
for lp : 1 .. NUM_STARS
stars (lp).x := Rand.Int (1, X_SCREEN)
stars (lp).y := Rand.Int (1, Y_SCREEN)
stars (lp).life := 0
end for
procedure DrawStar (x, y, life : real)
%sinxe the shades of gray are nubmers 16 to 31, this finds the color that is needed for the first oval
const temp_clr := round ((life) mod 15 + 16)
const temp_size := floor (life / 15)
%this oval is the oval that makes the change in size smooth
%it does this by being a shade of gray that makes the other oval appear slightly larger
Draw.Oval (round (x), round (y),
temp_size + 1, temp_size + 1, temp_clr)
if temp_size >= 1 then
Draw.FillOval (round (x), round (y),
temp_size, temp_size, white)
end if
end DrawStar
var mouse_x, mouse_y, button : int := 0
var last_time : real := Time.Elapsed
loop
Mouse.Where (mouse_x, mouse_y, button)
for lp : 1 .. NUM_STARS
%this stuff moves the stars, and increases their "life"
stars (lp).x := (stars (lp).x - mouse_x) * STAR_SPEED * (stars (lp).life * STAR_ACC + 1) + mouse_x
stars (lp).y := (stars (lp).y - mouse_y) * STAR_SPEED * (stars (lp).life * STAR_ACC + 1) + mouse_y
stars (lp).life := (stars (lp).life + 1) * STAR_LIFE - 1
%this draws the star
DrawStar (stars (lp).x, stars (lp).y, (stars (lp).life * STAR_SIZE) ** 2)
%if the star is outside the screen, reinitialize it
if stars (lp).x < 0 or stars (lp).x > X_SCREEN or stars (lp).y < 0 or stars (lp).y > Y_SCREEN then
stars (lp).x := Rand.Real * X_SCREEN
stars (lp).y := Rand.Real * Y_SCREEN
stars (lp).life := 0
end if
end for
View.Update
drawfillbox (-10, -10, X_SCREEN, Y_SCREEN, black)
loop
exit when Time.Elapsed - last_time > 30
end loop
last_time := Time.Elapsed
end loop
|