Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Falling Snow actually works
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
belarussian




PostPosted: 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

loop
%Make the background
Draw.FillBox (0, 0, 800, 300, 29)
Draw.FillBox (0, 300, 800, 600, blue)

%snowman
%body
Draw.FillOval (100, 110, 60, 60, white)
Draw.FillOval (100, 195, 45, 45, white)
Draw.FillOval (100, 260, 27, 27, white)
%eyes
Draw.FillOval (110, 270, 5, 5, black)
Draw.FillOval (90, 270, 5, 5, black)
%nose
Draw.Line (105, 263, 95, 263, 42)
Draw.Line (100, 250, 95, 263, 42)
Draw.Line (100, 250, 105, 263, 42)
Draw.Line (100, 250, 104, 263, 42)
Draw.Line (100, 250, 103, 263, 42)
Draw.Line (100, 250, 102, 263, 42)
Draw.Line (100, 250, 101, 263, 42)
Draw.Line (100, 250, 100, 263, 42)
Draw.Line (100, 250, 99, 263, 42)
Draw.Line (100, 250, 98, 263, 42)
Draw.Line (100, 250, 97, 263, 42)
Draw.Line (100, 250, 96, 263, 42)
%mouth
Draw.Line (105, 245, 95, 245, black)
Draw.Arc (100, 245, 5, 5, 180, 0, black)

%Hand
Draw.FillOval (60, 195, 25, 20, white)
Draw.FillOval (140, 195, 25, 20, white)
%Flag
Draw.ThickLine (155, 185, 155, 240, 2, black)
Draw.FillBox (156, 240, 195, 215, brightred)
%Draw.Arc ()


%Hat
Draw.ThickLine (127, 287, 73, 287, 3, black)
Draw.ThickLine (127, 291, 73, 291, 4, white)
Draw.ThickLine (127, 294, 73, 294, 3, black)
Draw.ThickLine (129, 287, 129, 294, 2, black)
Draw.ThickLine (73, 287, 73, 294, 2, black)
Draw.FillBox (80, 294, 120, 330, black)
%Buttons
Draw.FillOval (100, 165, 5, 5, black)
Draw.FillOval (100, 185, 5, 5, black)
Draw.FillOval (100, 205, 5, 5, black)
Draw.FillOval (100, 225, 5, 5, black)

%sky
%Moon
Draw.FillOval (65, 550, 40, 40, yellow)
Draw.FillOval (89, 556, 45, 45, blue)
%stars
Draw.FillStar (300, 500, 310, 510, yellow)
Draw.FillStar (265, 465, 255, 455, yellow)
Draw.FillStar (400, 550, 410, 540, yellow)
Draw.FillStar (200, 510, 210, 520, yellow)
Draw.FillStar (115, 550, 125, 560, yellow)
Draw.FillStar (375, 485, 365, 475, yellow)
Draw.FillStar (65, 480, 75, 490, yellow)
Draw.FillStar (130, 420, 140, 410, yellow)
Draw.FillStar (750, 550, 760, 560, yellow)

%Big Bear
Draw.FillStar (690, 455, 700, 465, yellow)
Draw.FillStar (720, 430, 730, 440, yellow)
Draw.FillStar (700, 400, 710, 410, yellow)
Draw.FillStar (670, 405, 680, 415, yellow)
Draw.FillStar (630, 380, 640, 390, yellow)
Draw.FillStar (605, 350, 615, 360, yellow)
Draw.FillStar (600, 320, 610, 330, yellow)

%Draw.FillStar (500, 500, 490, 490, yellow)
%Polar
Draw.FillStar (530, 550, 545, 565, yellow)
%Small Bear
Draw.FillStar (510, 530, 500, 520, yellow)
Draw.FillStar (495, 500, 485, 490, yellow)
Draw.FillStar (490, 470, 480, 460, yellow)
Draw.FillStar (490, 430, 480, 420, yellow)
Draw.FillStar (460, 475, 450, 465, yellow)
Draw.FillStar (460, 430, 450, 420, yellow)

%Christamas tree
%Trunk
Draw.FillBox (380, 100, 420, 170, 113)
%Leaves?
Draw.Line (300, 170, 500, 170, green)
Draw.Line (300, 170, 380, 250, green)
Draw.Line (500, 170, 420, 250, green)
Draw.Line (320, 250, 380, 250, green)
Draw.Line (420, 250, 480, 250, green)
Draw.Line (320, 250, 380, 310, green)
Draw.Line (480, 250, 420, 310, green)
Draw.Line (380, 310, 340, 310, green)
Draw.Line (420, 310, 460, 310, green)
Draw.Line (340, 310, 380, 350, green)
Draw.Line (460, 310, 420, 350, green)
Draw.Line (420, 350, 440, 350, green)
Draw.Line (380, 350, 360, 350, green)
Draw.Line (400, 390, 360, 350, green)
Draw.Line (400, 390, 440, 350, green)
Draw.Fill (400, 200, brightgreen, green)
%star
Draw.FillStar (380, 385, 420, 425, 40)
%presents
%#1
Draw.FillBox (340, 100, 370, 130, brightred)
Draw.Line (340, 105, 365, 130, green)
Draw.Line (345, 100, 370, 125, green)
Draw.Line (340, 100, 340, 105, green)
Draw.Line (340, 100, 345, 100, green)
Draw.Line (370, 130, 365, 130, green)
Draw.Line (370, 130, 370, 125, green)
Draw.Fill (360, 120, green, green)
%#2
Draw.FillBox (330, 100, 290, 130, brightgreen)
Draw.Line (290, 105, 325, 130, brightpurple)
Draw.Line (295, 100, 330, 125, brightpurple)
Draw.Line (290, 100, 290, 105, brightpurple)
Draw.Line (290, 100, 295, 100, brightpurple)
Draw.Line (325, 130, 330, 130, brightpurple)
Draw.Line (330, 130, 330, 125, brightpurple)
Draw.Fill (310, 115, brightpurple, brightpurple)

%Home
Draw.Arc (650, 275, 220, 220, 240, 300, black)
Draw.ThickLine (760, 85, 620, 360, 2, black)
Draw.ThickLine (540, 85, 650, 360, 2, black)
Draw.ThickLine (590, 65, 642, 200, 2, black)
Draw.ThickLine (712, 65, 642, 200, 2, black)
Draw.Fill (642, 100, 43, black)
Draw.Fill (642, 210, 114, black)
Draw.Arc (650, 275, 220, 220, 255, 285, 43)
Draw.Arc (650, 274, 220, 220, 255, 285, 43)

%person
%Draw.FillOval

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
Sponsor
sponsor
Turing_Gamer




PostPosted: 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




PostPosted: 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




PostPosted: 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
        result true
    else
        result false
    end if
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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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
Sponsor
sponsor
mirhagk




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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
        end record
    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
        end if
        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
        end record
    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 : array 1 .. 1000 of Snow.snowflake     %creates 100 snowflakes
var static : flexible array 1 .. 0 of StaticFlake.staticflake
for i : 1 .. upper (snow)
    snow (i) := Snow.create     %creates all dem snowflakes
    snow (i).y -= Rand.Real * 100
end for

loop     %main loop
    for i : 1 .. upper (snow)
        if snow (i).alive ~= 0 then
            snow (i) := Snow.fall (snow (i))     %the snow flake falls a bit
        else
            if upper (static) < 1000 then
                new static, upper (static) + 1
                static (upper (static)) := StaticFlake.create (snow (i))
            else
                cur := cur rem 1000
                cur += 1
                Text.Locate (1, 1)
                put cur
                static (cur) := StaticFlake.create (snow (i))
            end if
            snow (i) := Snow.create
        end if
    end for

    cls
    for i : 1 .. upper (snow)
        Snow.draw (snow (i))     %draws the snowflake
    end for
    for i : 1 .. upper (static)
        StaticFlake.draw (static (i))
    end for
    drawfillbox (0, 0, maxx, round (Snow.pileup)-5, white)
    View.Update
    Time.DelaySinceLast (20)
end loop



try it out, its beautiful
Insectoid




PostPosted: Wed Dec 09, 2009 1:21 pm   Post subject: RE:Falling Snow actually works

I think the snowflakes should me more spread out vertically at the beginning. It's to pattern-y.
mirhagk




PostPosted: Wed Dec 09, 2009 4:14 pm   Post subject: RE:Falling Snow actually works

yeah sorry just change this line
Turing:

snow (i).y -= Rand.Real * 100

to
Turing:

snow (i).y -= Rand.Real * 500
amateur




PostPosted: Wed Dec 09, 2009 4:27 pm   Post subject: RE:Falling Snow actually works

did you make this all by yourself, if so your really smart
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 21 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: