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

Username:   Password: 
 RegisterRegister   
 weird effect
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DanShadow




PostPosted: Sat Dec 13, 2003 8:49 pm   Post subject: weird effect

I got bored, start messing with lines, created some stairway thing..Smile
code:

Draw.FillBox (0, 0, maxx, maxy, 255)
locate (13, 25)
color (12)
colorback (black)
put "Come..."
locate (14, 25)
put "take the gateway.."
locate (15, 25)
put "follow the steps..."
locate (16, 25)
put "enter the stars...."
delay (8000)
var x, y : int := 200
var num := 50
Draw.FillBox (0, 0, maxx, maxy, 255)
for i : 1 .. 50
    var xer, yer : int := 0
    randint (xer, 1, 640)
    randint (yer, 1, 400)
    Draw.Dot (xer, yer, 14)
end for
num := 50
loop
    delay (5)
    Draw.Line (x + num, y + 50, x, y, 2)
    num := num + 1
    y := y - 1
    exit when y < 0 - 50
end loop
var xer : int := 0
loop
    randint (num, 1, 3)
    Draw.FillOval (x + 25, y + 325, 30, 70, num)
    xer := xer + 1
    if xer = 10000 then
        locate (5, 30)
        put "k....close the program now..."
    end if
end loop


or maybe this odd thing

code:

var x, y, num : int := 200
num := 0
var modi : int := 1
Draw.FillBox (0, 0, maxx, maxy, 255)
loop
    Draw.Oval (x + num, y - 50, x, y, 14)
    delay (5)
    Draw.Oval (x + num, y - 50, x, y, 12)
    delay (5)
    num := num + 1
    Draw.Oval (x + num, y - 50, x, y, 2)
    y := y + modi
    if y < 0 then
        modi := 1
    elsif y > maxy then
        modi := -1
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
DanShadow




PostPosted: Sat Dec 13, 2003 8:55 pm   Post subject: (No subject)

hmm...i think i found a glitch in turing
code:

var x, y, num : int := 200
num := 0
loop
    num := num + 1
    Draw.Line (x + num, y - 50, x, y, 255)
    y := y - 1
end loop

Leave that running for a mniute, and watch it. See how in the code, the "y" axis is ONLY supposed to decrease? Well then how does it end up higher than the original "y" valu e of 200? *spooky* Shocked
Dan




PostPosted: Tue Dec 16, 2003 12:47 pm   Post subject: (No subject)

same thing will happen in c/c++ but it will take alot longer.

that is what most progaming languges do when you hit max number (or min), they go back to some set number. it is praty so the hole comp dose not crash when you get a value over the x big.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
DanShadow




PostPosted: Wed Dec 17, 2003 12:00 pm   Post subject: (No subject)

Oh I see...except seemingly when in C++, when you reach a "too" large integer, it crashes the program, heh.
Tony




PostPosted: Wed Dec 17, 2003 1:17 pm   Post subject: (No subject)

This all has to do with the way signed numbers work.

Anyone knows how to represent negative numbers in binary? Laughing

Binary numbers have a leading bit. 0 for possitive, 1 for negative. When you overflow the number - say you have an 8 bit integer. It is actually 9 bits long. So when you have 256+1, in binary its

011111111
+1
100000000

now since the integer is only 8 bits long, this number represents negative 0. As you add more, you keep on going backwards.

100000001
is -1 and so on.

The reason for C++ to take "longer" is because integers are "longer" - meaning more bits to fill before overflow.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
kalin




PostPosted: Tue Jan 20, 2004 3:37 pm   Post subject: (No subject)

Both of those things are really really really really *cough cough* wierd
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 1  [ 6 Posts ]
Jump to:   


Style:  
Search: