### Author Topic: Star-field  (Read 6336 times)

#### GEEK

• Jr. Member
• Posts: 83
• want to learn c++, if you want to teach me, pm me!
##### Star-field
« on: 11. February 2014, 19:39:06 »
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?
« Last Edit: 11. February 2014, 19:41:04 by GEEK »

#### Cosmo

• Guest
##### Re: Star-field
« Reply #1 on: 12. February 2014, 11:31:27 »
Hi Geek,
Code: [Select]
--'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

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)
redraw()
until k==27
closewindow()

#### Cosmo

• Guest
##### Re: Star-field
« Reply #2 on: 12. February 2014, 12:16:16 »
another starfield.
Code: [Select]
--'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={}

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()
« Last Edit: 12. February 2014, 12:20:05 by Cosmo »

#### Cosmo

• Guest
##### Re: Star-field
« Reply #3 on: 12. February 2014, 16:56:01 »
And once again.
Code: [Select]
--'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 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)

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)
color(0x9C,0x5A,0xEF)
drawtext(2+x*14,y[x],letter)
color(0,255,0)
drawtext(2+x*14,5+y[x],letter)
end

redraw()
until k==27
closewindow()
« Last Edit: 12. February 2014, 17:13:50 by Cosmo »

#### GEEK

• Jr. Member
• Posts: 83
• want to learn c++, if you want to teach me, pm me!
##### Re: Star-field
« Reply #4 on: 12. February 2014, 20:30:25 »
wow!  that's sooo coool!
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

#### Cosmo

• Guest
##### Re: Star-field
« Reply #5 on: 12. February 2014, 20:36:50 »
Hi Geek,

stripes are possible with alphachannel, but unfortunately, Egsl alphachannel doesn't it.
« Last Edit: 13. February 2014, 00:08:08 by Cosmo »

#### GEEK

• Jr. Member
• Posts: 83
• want to learn c++, if you want to teach me, pm me!
##### Re: Star-field
« Reply #6 on: 12. February 2014, 22:18:13 »
ok, thanks anyway!

#### GEEK

• Jr. Member
• Posts: 83
• want to learn c++, if you want to teach me, pm me!
##### Re: Star-field
« Reply #7 on: 12. February 2014, 22:38:47 »
Ow, the documentation says that egsl has alpha to...

#### Cosmo

• Guest
##### Re: Star-field
« Reply #8 on: 13. February 2014, 00:00:51 »
Hi Geek,

Egsl has alpha, I know.
But what I meant was, that it doesn't work!  You cannot get stripes with EGSL_ALPHACHANNEL!

#### Cosmo

• Guest
##### Re: Star-field
« Reply #9 on: 13. February 2014, 00:05:09 »
If you would peek into the source code, you would see that I used alphachannel!

#### GEEK

• Jr. Member
• Posts: 83
• want to learn c++, if you want to teach me, pm me!
##### Re: Star-field
« Reply #10 on: 13. February 2014, 00:13:03 »
Yes, just saw that, sry.
can i ask you why you used "alphachannel(200)" then?
if i delete it, nothing changes...

repeat
k=getkey()
cls()
alphachannel(200)
redraw()
until k==27
closewindow()

and is it possible witout alphachannel? just stripes, pure white?
« Last Edit: 13. February 2014, 00:15:51 by GEEK »

#### Cosmo

• Guest
##### Re: Star-field
« Reply #11 on: 13. February 2014, 00:28:29 »
Quote
and is it possible witout alphachannel? just stripes, pure white?

I have tried, but without success. alphachannel in the source code is a holdover, I forgot to remove.
Alphachannel (50)  gets a darker white, but not alpha.

#### GEEK

• Jr. Member
• Posts: 83
• want to learn c++, if you want to teach me, pm me!
##### Re: Star-field
« Reply #12 on: 13. February 2014, 00:44:22 »
ok, going to mess a bit with that code, maybe i find a solution, thanks for the help!

#### Cosmo

• Guest
##### Re: Star-field
« Reply #13 on: 15. February 2014, 22:49:35 »
Hi Lelldorin,

Okay, you got it

#### GEEK

• Jr. Member
• Posts: 83
• want to learn c++, if you want to teach me, pm me!
##### Re: Star-field
« Reply #14 on: 16. February 2014, 02:54:47 »
Hi Lelldorin