Posted: Wed Nov 18, 2009 9:59 am Post subject: Falling Snow actually works
Falling Snow
This will have a pic in it if you need just the snow ask me
View.Set ("graphics:800;600,nobuttonbar,nocursor,noecho")
View.Set ("offscreenonly")
%set up the snow
const NoOfFlakes := 400
var flakeX : array 1 .. NoOfFlakes of int
var flakeY : array 1 .. NoOfFlakes of int
for flake : 1 .. NoOfFlakes
flakeX (flake) := Rand.Int (0, maxx)
flakeY (flake) := Rand.Int (0, maxy)
end for
for flake : 1 .. NoOfFlakes
%Drop The Flake
flakeY (flake) -= Rand.Int (1, 5)
%flakeX (flake) += Rand.Int (-1, 1)
if flakeY (flake) < 0 then
flakeY (flake) := maxy
flakeY (flake) := Rand.Int (0, maxx)
end if
Draw.FillOval (flakeX (flake), flakeY (flake), 1, 1, white)
end for
%Update the screen (because of offscreen only)
View.Update
delay (25)
end loop
TURING
Sponsor Sponsor
Turing_Gamer
Posted: Wed Nov 18, 2009 12:05 pm Post subject: Re: Falling Snow actually works
Lol very well done, although the code is long...
Overall, 8/10
ssjwilliam
Posted: Sun Dec 06, 2009 11:36 am Post subject: Re: Falling Snow actually works
Nice work! You may like to make it shorter for a higher rating.
Superskull85
Posted: Sun Dec 06, 2009 12:13 pm Post subject: Re: Falling Snow actually works
Just a comment on "long code." Just because your code is long does not mean it is inefficient or bad. Likewise just because your code is short does not mean it is efficient or good.
In general, "long code" is easier to understand as the code is explicitly outlined and not compressed into less lines. For example:
Turing:
function Greater (NumOne, NumTwo :int):boolean if NumOne > NumTwo then resulttrue else resultfalse endif end Greater
Versus:
Turing:
function Greater (NumOne, NumTwo :int):boolean result NumOne > NumTwo
end Greater
Unless a programmer has thorough knowledge of expressions, and boolean algebra, the first piece of code would be easier to understand than the second piece of code.
Sorry that that was off-topic.
mirhagk
Posted: Mon Dec 07, 2009 11:27 am Post subject: RE:Falling Snow actually works
yeah but shorter code makes it way easier to manage, although uber compressed code isn't a good idea either. (look in 20 lines or less lol)
For instance putting algebra onto the draw line isn't a good idea, but using an array and for loops are better than 100 lines of almost the same thing.
His code could definetly be improved by making it shorter.
belarussian
Posted: Mon Dec 07, 2009 9:14 pm Post subject: RE:Falling Snow actually works
ok lo0o0ky here if i would not put a backgound the program would literally suck because it would show lines so yeah get out of my house
mirhagk
Posted: Mon Dec 07, 2009 11:36 pm Post subject: RE:Falling Snow actually works
you could draw it from it from a pic ya know
mag400
Posted: Tue Dec 08, 2009 2:39 pm Post subject: RE:Falling Snow actually works
Could I have a copy of the falling snow code? just the snow by itself please. thank you.
Sponsor Sponsor
mirhagk
Posted: Tue Dec 08, 2009 2:40 pm Post subject: RE:Falling Snow actually works
i designed a pretty advanced snow program that allows the snow to pile up, and I also have a piece of code that just does the snow, do you want either one of those?
belarussian
Posted: Tue Dec 08, 2009 9:05 pm Post subject: RE:Falling Snow actually works
ya please can you show me how to make the snow pile up
mirhagk
Posted: Tue Dec 08, 2009 10:55 pm Post subject: RE:Falling Snow actually works
i don't have the exact code with me right now, i'll get it to you tommorrow but basically what I did was had an array of about 1000 "snowflake" objects and then an array of 1000 "staticflakes" (the snowflakes recorded things like speed and such and x and y in :real format while staticflakse only recorded an int of x and y since they didn't move). I also had a variable record the "bottom" which was where the snow was stacked up to
once the snow flake hit the bottom it would do three things
1. create a "staticflake" at the location it hit (staticflakes are recycled once all 1000 are used up)
2. increase the bottom variable by like 0.01 or something like that
3. return to the top of the screen with new random variables
now the bottom variables is also used to create a white box about 10-20 pixels below the bottom. This will cover up the spaces left behind by "staticflakes" that were recycled.
while not being 100% accurate it's very close to being accurate and allows for a the snow to fall, land and create a bumby-ish bottom and keep falling over and over.
(oh and "staticflakes" were bigger than "snowflakes" so that the ground looked smoother)
mirhagk
Posted: Wed Dec 09, 2009 10:22 am Post subject: RE:Falling Snow actually works
sorry for the double post but here's the snow code i was talking about
Turing:
module Snow
export snowflake, create, fall, draw, pileup
type snowflake : record
x, y :real
yvel :real
alive :int endrecord var pileup :real:=0
function create : snowflake
var temp : snowflake
temp.x := Rand.Int (0, maxx)
temp.y :=maxy + (Rand.Real*10)
temp.yvel :=(Rand.Real*3) + 1
temp.alive :=1 result temp
end create
function fall (flake : snowflake): snowflake
var temp := flake
temp.y -= temp.yvel
if temp.y < pileup then
temp.alive :=0
pileup +=0.005 endif result temp
end fall
procedure draw (flake : snowflake) drawfilloval(round(flake.x),round(flake.y),1, 1, white) end draw
end Snow
module StaticFlake
import Snow
export draw, create, staticflake
type staticflake : record
x, y :int endrecord fcn create (flake : Snow.snowflake): staticflake
var temp : staticflake
temp.x :=round(flake.x)
temp.y :=round(flake.y) result temp
end create
proc draw (flake : staticflake) drawfilloval(flake.x, flake.y, 2, 2, white) end draw
end StaticFlake
var win :=Window.Open("offscreenonly") colourback(black) colour(white) var cur :=0 var snow :array1.. 1000of Snow.snowflake %creates 100 snowflakes var static :flexiblearray1.. 0of StaticFlake.staticflake
for i :1.. upper(snow)
snow (i):= Snow.create %creates all dem snowflakes
snow (i).y -=Rand.Real*100 endfor
loop%main loop for i :1.. upper(snow) if snow (i).alive ~=0then
snow (i):= Snow.fall (snow (i))%the snow flake falls a bit else ifupper(static) < 1000then new static, upper(static) + 1
static (upper(static)):= StaticFlake.create (snow (i)) else
cur := cur rem1000
cur +=1 Text.Locate(1, 1) put cur
static (cur):= StaticFlake.create (snow (i)) endif
snow (i):= Snow.create
endif endfor