Retrogamecoding(.org) > EGSL
Star-field
GEEK:
Hello! :)
I'm looking for some code to make this: (picture)
I want to make a starfield screensaver in lua, but i'm not a genius in math :\
does someone want to help me?
Thanks in advanse
Cosmo:
Hi Geek,
--- Code: -----'by Peter Wirbelauer
openwindow(640,480,0,"Stars")
setframetimer(60)
function rand(minZahl,maxZahl)
maxZahl = (maxZahl-minZahl)
return int(rnd()*maxZahl+minZahl)
end
local col=0;sx=0;sy=0;anz=5000;speed=2;xscreen=640;yscreen=480
local xstern ={}
local ystern ={}
local zstern ={}
for i=0,anz do
xstern[i] = rand(-(xscreen/2), (xscreen/2))*128
ystern[i] = rand(-(yscreen/2), (yscreen/2))*128
zstern[i] = rand(speed,255)
end
function updatestars()
local i,co
for i=0,anz do
zstern[i] = zstern[i] - speed
if zstern[i] <= speed then zstern[i] = 255; end
sx = (xstern[i] / zstern[i]) + (xscreen/2)
sy = (ystern[i] / zstern[i]) + (yscreen/2)
co = (300 -zstern[i])*.8
alphachannel(250)
color(co,co,co)
box(sx,sy,sx+2,sy+2)
end
end
repeat
k=getkey()
cls()
alphachannel(200)
updatestars()
redraw()
until k==27
closewindow()
--- End code ---
Cosmo:
another starfield.
--- Code: -----'by Peter Wirbelauer
openwindow(640,480,0,"Retro-Stars")
setframetimer(60)
colorkey(0,0,0)
function rand(minZahl,maxZahl)
maxZahl = (maxZahl-minZahl)
return int(rnd()*maxZahl+minZahl)
end
function sprite(id,x,y,w,h,fx)
drawimage(w*fx,0,w,h,x,y,id)
end
local np=500; j=0; z=0; p=0; v=0
local px={}
local py={}
local pz={}
p = loadimage("png/phoenix.png")
for j=0,np do
px[j] = rand(0,639)
py[j] = rand(0,479)
pz[j] = rand(65536,16777215)
end
repeat
k=getkey()
cls()
for j=0,np do
px[j] = px[j] -1
if px[j] <0 then
px[j] = 640
py[j] = rand(0,479)
end
color(pz[j],pz[j],pz[j])
box(px[j],py[j], px[j]+2,py[j]+2)
end
sprite(p,(640-128)/2,(480-128)/2,128,128,z)
v = v+0.2
if v >=1 then
v = 0
z = z+1
if z==10 then z=0; end
end
redraw()
until k==27
closewindow()
--- End code ---
Cosmo:
And once again.
--- Code: -----'by Peter Wirbelauer
openwindow(640,480,0,"Retro-Stars")
setframetimer(60)
function rand(minZahl,maxZahl)
maxZahl = (maxZahl-minZahl)
return int(rnd()*maxZahl+minZahl)
end
local rad = math.rad
local z = "HELLO AND WELCOME IN THE SUPER PROGRAMMING!"; letter=0
local fok, xp, yp, i, tl, x, m = 160,0,0,0,0,0,0
local x3DSterne ={}
local y3DSterne ={}
local z3DSterne ={}
local y ={}
local angle ={}
tl = len(z)
m=loadmusic("music/b.mod")
playmusic(m,128,-1)
for i=0,tl do
angle[i] = 360-i*(360/tl)
y[i] = 240
end
for i=0,799 do
x3DSterne[i] = rand (1,440)
y3DSterne[i] = rand (1,380)
z3DSterne[i] = rand (1,500)
end
repeat
k=getkey()
alphachannel(150)
cls()
for i=0,799 do
xp = (x3DSterne[i] * fok) / (z3DSterne[i] + fok) + 5
yp = (y3DSterne[i] * fok) / (z3DSterne[i] + fok) + 5
color(255,255,255)
box(xp,yp, 2+xp,2+yp)
xp = (-x3DSterne[i] * fok) / (z3DSterne[i] + fok) + 630
yp = (-y3DSterne[i] * fok) / (z3DSterne[i] + fok) + 470
box(xp,yp,2+xp,2+yp)
xp = (-x3DSterne[i] * fok) / (z3DSterne[i] + fok) + 630
yp = ( y3DSterne[i] * fok) / (z3DSterne[i] + fok) + 8
box(xp,yp,2+xp,2+yp)
xp = ( x3DSterne[i] * fok) / (z3DSterne[i] + fok) + 5
yp = (-y3DSterne[i] * fok) / (z3DSterne[i] + fok) + 470
box(xp,yp,2+xp,2+yp)
z3DSterne[i] = z3DSterne[i] -1
if z3DSterne[i] <=0 then
z3DSterne[i] = 500
end
end
alphachannel(255)
for x=1,tl do
angle[x] = angle[x] +1
if angle[x] == 360 then angle[x] =0; end
letter = mid(z, x ,1)
y[x] = y[x] + sin(rad(angle[x]*4))
color(0x9C,0x5A,0xEF)
drawtext(2+x*14,y[x],letter)
y[x] = y[x] + cos(rad(angle[x]*2))
color(0,255,0)
drawtext(2+x*14,5+y[x],letter)
end
redraw()
until k==27
closewindow()
--- End code ---
GEEK:
wow! :o that's sooo coool! 8)
thank you!
do you think you can give it the stripes effect?
that the stars like in the example are stripes?
I'm glad with this examples to! great ;)
Navigation
[0] Message Index
[#] Next page
Go to full version