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

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




PostPosted: Thu Oct 26, 2006 8:19 am   Post subject: Musical keyboard

This is a fun little program I wrote when i started using the sound command. All the keys on the computer make a different sound, Plus it looks cool (i put in some screen effects. You can change how long the notes can go by using the arrow keys.

code:


var Key : array char of boolean
var Ch : char
var Font1 : int := Font.New ("Arial:50")
var Font2 : int := Font.New ("Arial:30")
var Font3 : int := Font.New ("Arial:20")
var X1, Y1, Size, C : int
var X2, Y2 : int
var L : nat2 := 100


procedure DrawStuff
    randint (X1, 1, maxx)
    randint (Y1, 1, maxy)
    randint (C, 1, 15)
    randint (Size, 1, 200)
    drawfilloval (X1, Y1, Size, Size, C)
    drawoval (X1, Y1, Size, Size, 7)
end DrawStuff
procedure DrawLines
    randint (X1, 1, maxx)
    randint (X2, 1, maxx)
    randint (Y1, 1, maxy)
    randint (Y2, 1, maxy)
    randint (C, 1, 15)
    drawline (X1, Y1, X2, Y2, C)
end DrawLines
procedure Pause
    Ch := getchar
end Pause



setscreen ("graphics:max,max,nobuttonbar")

colorback (7)
cls
Font.Draw ("Silly Keybord", maxx div 2 - 200, maxy - 200, Font1, 12)
Font.Draw ("(press any key to continue)", maxx div 2 - 200, maxy - 300, Font2, 12)
Font.Draw ("Made by: Peter Watt", maxx div 2 - 200, maxy - 400, Font3, 12)
Pause
loop
    cls
    Input.KeyDown (Key)

    if Key ('1') then
        DrawStuff
        sound (25, L)
    end if

    if Key ('2') then
        DrawLines
        sound (125, L)
    end if
    if Key ('3') then
        DrawStuff
        sound (225, L)
    end if
    if Key ('4') then
        DrawLines
        sound (253, L)
    end if
    if Key ('5') then
        DrawStuff
        sound (425, L)
    end if
    if Key ('6') then
        DrawLines
        sound (525, L)
    end if
    if Key ('7') then
        DrawStuff
        sound (625, L)
    end if
    if Key ('8') then
        DrawLines
        sound (725, L)
    end if
    if Key ('9') then
        DrawStuff
        sound (825, L)
    end if
    if Key ('0') then
        DrawLines
        sound (925, L)
    end if

    if Key ('q') then
        DrawStuff
        sound (50, L)
    end if

    if Key ('w') then
        DrawLines
        sound (150, L)
    end if
    if Key ('e') then
        DrawStuff
        sound (250, L)
    end if
    if Key ('r') then
        DrawLines
        sound (350, L)
    end if
    if Key ('t') then
        DrawStuff
        sound (450, L)
    end if
    if Key ('y') then
        DrawLines
        sound (550, L)
    end if
    if Key ('u') then
        DrawStuff
        sound (650, L)
    end if
    if Key ('i') then
        DrawLines
        sound (750, L)
    end if
    if Key ('o') then
        DrawStuff
        sound (850, L)
    end if
    if Key ('p') then
        DrawLines
        sound (950, L)
    end if

    if Key ('a') then
        DrawStuff
        sound (75, L)
    end if
    if Key ('s') then
        DrawLines
        sound (175, L)
    end if
    if Key ('d') then
        DrawStuff
        sound (275, L)
    end if
    if Key ('f') then
        DrawLines
        sound (375, L)
    end if
    if Key ('g') then
        DrawStuff
        sound (475, L)
    end if
    if Key ('h') then
        DrawLines
        sound (575, L)
    end if
    if Key ('j') then
        DrawStuff
        sound (675, L)
    end if
    if Key ('k') then
        DrawLines
        sound (775, L)
    end if
    if Key ('l') then
        DrawStuff
        sound (875, L)
    end if
    if Key (';') then
        DrawLines
        sound (975, L)
    end if
    if Key ('z') then
        DrawStuff
        sound (100, L)
    end if
    if Key ('x') then
        DrawLines
        sound (200, L)
    end if
    if Key ('c') then
        DrawStuff
        sound (300, L)
    end if
    if Key ('v') then
        DrawLines
        sound (400, L)
    end if
    if Key ('b') then
        DrawStuff
        sound (500, L)
    end if
    if Key ('n') then
        DrawLines
        sound (600, L)
    end if
    if Key ('m') then
        DrawStuff
        sound (700, L)
    end if
    if Key (',') then
        DrawLines
        sound (800, L)
    end if
    if Key ('.') then
        DrawStuff
        sound (900, L)
    end if
    if Key ('/') then
        DrawLines
        sound (1000, L)
    end if

    if Key (KEY_LEFT_ARROW) then
        L := 50
    end if
    if Key (KEY_RIGHT_ARROW) then
        L := 300
    end if
    if Key (KEY_UP_ARROW) then
        L := 200
    end if
    if Key (KEY_DOWN_ARROW) then
        L := 500
    end if
end loop


Sponsor
Sponsor
Sponsor
sponsor
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  [ 1 Posts ]
Jump to:   


Style:  
Search: