### Author Topic: Fog  (Read 5593 times)

#### Cosmo

• Guest
##### Fog
« on: February 06, 2014, 11:12:40 AM »
Hello,

A little bit fog.
Code: [Select]
--' by peter wirbelauer.
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

screen(800,600,0,"fog")
backcolor(0,0,0)
setframetimer(200)

local i,t,xres,yres,u,fz,h,w = 0,0,800,600,0,0,0,0
local cloudx={}
local cloudy={}
local clouds={}
w = screenwidth() /2
h = screenheight()/2

for i=1,250 do
cloudx[i]=rand(1,xres-2)
cloudy[i]=rand(1,yres-2)
clouds[i]=rand(1,4)
end

function move_clouds()
for i=1,250 do
alphachannel(35)
color(200,200,200)
fillcircle(cloudx[i],cloudy[i],90)
cloudx[i] = cloudx[i]+clouds[i]
if cloudx[i] > xres+128 then
cloudx[i] = -128
cloudy[i] = rand(1,yres -2)
clouds[i] = rand(1,4)
end
end
end

repeat
t=getkey()
cls()
alphachannel(255)
sprite(u,w,h,199,85,fz)
move_clouds()
fz=fz+1
if fz==8 then fz=0;end
redraw()
until t==27
closewindow()
« Last Edit: February 06, 2014, 11:33:33 AM by Cosmo »

#### Cosmo

• Guest
##### Re: Fog
« Reply #1 on: February 07, 2014, 11:59:01 AM »
Hello,

Another idea.

Code: [Select]
screen(640,480,0,"Jelly")
setframetimer(60)
backcolor(0,0,200)

local frames,index,n,i = 1,0,60,0
local mx={}
local my={}

for i=1,60 do
mx[60]=0
my[60]=0
end

repeat
k=getkey()
clearscreen()
alphachannel(60)
mx[frames] = mousex()-30
my[frames] = mousey()-30
for i=1,n do
index = math.fmod(frames+i,60)
color(240,255,255)
ellipse(mx[index],my[index],i,i)
end

frames=frames +1
if frames==60 then frames=1; end

sync()
until k==27
closewindow()
« Last Edit: February 08, 2014, 12:38:30 PM by Cosmo »

#### GEEK

• Guest
##### Re: Fog
« Reply #2 on: February 07, 2014, 04:15:48 PM »
lua:21: attempt to call field 'mod' (a nil value)

try this: index = math.fmod(frames+i,60)
« Last Edit: February 07, 2014, 04:22:04 PM by GEEK »

#### Cosmo

• Guest
##### Re: Fog
« Reply #3 on: February 07, 2014, 05:27:33 PM »
Hi Geek,

Quote
lua:21: attempt to call field 'mod' (a nil value)

What lua:21 ?  Is running here!  No error, no crash.
I use lua 5.1 and what have you ?

#### Bereb

• Guest
##### Re: Fog
« Reply #4 on: February 07, 2014, 05:43:50 PM »
Quote
lua:21: attempt to call field 'mod' (a nil value)

What lua:21 ?  Is running here!  No error, no crash.
I use lua 5.1 and what have you ?

lua:21 is the line number where  occured the error (same on my computer)
As GEEK wrote, math.fmod() corrects the problem... However I think this function isn't in Lua 5.1 but in Lua 5.2 (I'm not sure), and EGSL 1.6.0  is built with Lua 5.2

Correction: math.mod() doesn't exist either in Lua 5.1, it's math.fmod(). But there is also an operator % which can be usefull:
Code: [Select]
index = (frames+i) % 60
« Last Edit: February 07, 2014, 06:02:54 PM by Bereb »

#### Cosmo

• Guest
##### Re: Fog
« Reply #5 on: February 07, 2014, 08:47:39 PM »
Hi Bereb,

I have Lua5.1.dll here!  math.mod doesn't make trouble.
Jelly runs fine here with Windows7.

When it would not run, I would not put it to the forum!
« Last Edit: February 07, 2014, 11:07:56 PM by Cosmo »

#### GEEK

• Guest
##### Re: Fog
« Reply #6 on: February 07, 2014, 11:37:55 PM »
I use the standart EGSL IDE and maybe that's why we got this problem and you don't?
I use "lua52.dll"

#### Cosmo

• Guest
##### Re: Fog
« Reply #7 on: February 08, 2014, 11:18:42 AM »
Hi Geek,

where did you get it?  (lua52.dll)

#### Tomaaz

• Guest
##### Re: Fog
« Reply #8 on: February 08, 2014, 11:34:26 AM »
where did you get it?  (lua52.dll)

EGSL 1.6 uses lua52, EGSL 1.5 - lua51.

#### Cosmo

• Guest
##### Re: Fog
« Reply #9 on: February 08, 2014, 12:45:17 PM »
Thanks Tomaaz,