[ALLY] Re: Starfield Animation
[1/2] from: cyphre::volny::cz at: 12-Apr-2001 12:18
WOW very cool!
I'll add it to SWIS demos ;-)
Regards
Cyphre
[2/2] from: arolls:bigpond:au at: 12-Apr-2001 18:19
Permission granted to add to demos or whatever...
rebol [
Title: "Starfield Animation"
File: %anim-stars.r
Date: 12-Apr-2001
Version: 1.0.0
Author: "Anton Rolls"
Language: 'English
Purpose: {}
ToDo: {
-
}
]
; http://users.bigpond.net.au/datababies/anton/rebol/graphics.r
do %graphics.r
img: make image! 250x250
SetTargetImage img
mid-x: to-integer (img/size/x / 2)
mid-y: to-integer (img/size/y / 2)
n-stars: 200
x: make block! n-stars
y: make block! n-stars
z: make block! n-stars
sx: make block! n-stars ;screen x position
sy: make block! n-stars ;screen y position
; initialize stars in random positions
repeat i n-stars [
insert x (random img/size/x) - mid-x
insert y (random img/size/y) - mid-y
insert z (random 2100) + 50
insert sx 0
insert sy 0
]
;calculate the array of x,y positions on the screen
calc-final: does [
repeat i n-stars [
poke sx i to-integer (mid-x + (x/:i * 1000 / z/:i))
poke sy i to-integer (mid-y + (y/:i * 1000 / z/:i))
]
]
calc-final
zoom: does [
repeat i n-stars [
poke z i z/:i - 10
if z/:i < 10 [poke z i 2100 + random 50]
]
]
clear-final: does [
SetPenColour black
repeat i n-stars [
plot-clip sx/:i sy/:i
]
]
draw-final: does [
repeat i n-stars [
col: to-integer 255 - (z/:i * 0.1)
SetPenColour to-tuple reduce [col col col]
plot-clip sx/:i sy/:i
]
]
lay: layout [
origin 0x0
pic: image img rate 40 feel [
engage: func [face action event][
switch action [
time [
; make changes
clear-final
zoom
calc-final
draw-final
show face
]
down [
;print action/offset
]
]
]
]
]
view lay