Computer Science Canada

The Customizer

Author:  Remm [ Mon May 08, 2006 6:55 pm ]
Post subject:  The Customizer

Yeah. This is my first program that wasnt assigned by a teacher ( the class stuffs is just drooling with simplicity Sad ) Any feedback on it is welcome. Oh, and for some reason, it works fine on my school computer, yet at home the object will move super fast from one side of screen to other, and it pumps comp usage up to 100%. if anyone knows why it does so, (maybe the multiple proceedures running) please tell me. Thanks, and have fun.
controls:
insert - colour back # up
delete - colour back # down
home - object colour # up
end - object colour # down
page down - change object
arrows - move object

code:

var colobak, colosqu, colobox : int
var num, num2, num3, num4, num5 : int
var draw : string
num := 100
num2 := 100
num3 := 200
num4 := 200
num5 := 1
colobak := 0
colobox := 1
%====================================

process bakcolours
    var colo : array char of boolean
    loop
        Input.KeyDown (colo)
        if colo (KEY_INSERT) then
            colobak := colobak + 1
        elsif colo (KEY_DELETE) then
            colobak := colobak - 1
        end if
        if (colobak >= 250) then
            colobak := 1
        elsif (colobak < 0) then
            colobak := 250
        end if
        delay (100)
        colourback (colobak)
    end loop
end bakcolours

%===================================


%====================================

process colours
    var colo2 : array char of boolean
    loop
        Input.KeyDown (colo2)
        if colo2 (KEY_HOME) then
            colobox := colobox + 1
        elsif colo2 (KEY_END) then
            colobox := colobox - 1
        end if

        if (colobox >= 250) then
            colobox := 1
        elsif (colobox < 0) then
            colobox := 250
        end if
        delay (100)
    end loop
end colours

%==================================


%==================================
process shp
    var shape : array char of boolean
    loop
        Input.KeyDown (shape)
        if shape (KEY_PGDN) then
            num5 := num5 - 1
            delay (100)
        end if
    end loop
end shp
%==================================

fork bakcolours
fork colours
fork shp


cls
View.Set ("offscreenonly")

%=================================
var mve : array char of boolean
loop
    Input.KeyDown (mve)
    if mve (KEY_UP_ARROW) then
        num2 := num2 + 5
        num4 := num4 + 5
    elsif mve (KEY_DOWN_ARROW) then
        num2 := num2 - 5
        num4 := num4 - 5
    elsif mve (KEY_LEFT_ARROW) then
        num := num - 5
        num3 := num3 - 5
    elsif mve (KEY_RIGHT_ARROW) then
        num := num + 5
        num3 := num3 + 5
    end if

    if (num >= maxx) or (num3 >= maxx) then
        num := num - 5
        num3 := num3 - 5

    elsif (num2 >= maxy) or (num4 >= maxy) then
        num2 := num2 - 5
        num4 := num4 - 5
    elsif (num <= 0) or (num3 <= 0) then
        num := num + 5
        num3 := num3 + 5
    elsif (num4 <= 0) or (num2 <= 0) then
        num2 := num2 + 5
        num4 := num4 + 5
    end if

    if (num5 = 1) then
        Draw.FillBox (num, num2, num3, num4, colobox)
    elsif (num5 = 2) then
        Draw.FillMapleLeaf (num, num2, num3, num4, colobox)
    elsif (num5 = 3) then
        Draw.FillStar (num, num2, num3, num4, colobox)
    elsif (num5 >= 4) then
        num5 := 1
        Draw.FillBox (num, num2, num3, num4, colobox)
    elsif (num5 <= 0) then
        num5 := 3
        Draw.FillStar (num, num2, num3, num4, colobox)
    end if
    View.Update
    cls
end loop
%========================================

Author:  HellblazerX [ Mon May 08, 2006 7:17 pm ]
Post subject: 

Don't use processes. You don't need them, and they make life a pain in the read end. Also, the reason why it runs really fast on your home computer is because your school computer is really slow. You should use the delay function to stop your program temporarily for a period of time. The way you would use it is like this:

code:
delay (50) %delays for 50 milliseconds


Not sure about that 100% CPU thing. Probably because of the processes.

Author:  Remm [ Mon May 08, 2006 7:25 pm ]
Post subject: 

Yeah. im kinda a processd fiend. But they work so well! -.-
I added in delays and it works much better... with delays at school computer though, its just scary.

Author:  HellblazerX [ Mon May 08, 2006 7:33 pm ]
Post subject: 

Ya, school computers can be very scary. Last year when me and my partner made our FP, we had made it on our computers, and we can timed the delays and stuff according to our computers, but when we brought it to school,......wow what mess. We used to have computers that if you typed one letter, it would take 5 minutes for it to show up on the screen, and I'm not even joking with you.

Author:  ohgeez_ [ Mon May 08, 2006 8:07 pm ]
Post subject: 

im not too sure about this..

but i believe u can use some arrays instead of all those variables. It doesnt really save any lines but it would seem more neat and it would be easier to manipulate later.

Also. as the other guy said, avoid forks and processes. There a pain to try and control. if its possible at all.

otherwise. its quite interesting

Author:  upthescale [ Mon May 08, 2006 9:19 pm ]
Post subject: 

HellblazerX wrote:
it would take 5 minutes for it to show up on the screen, and I'm not even joking with you.



yea man, at school if i want an oval to move instead of doing

code:

loop
cls
drawfilloval(x,y,30,30,7)
View.Update
end loop




if would have to do:

code:

loop
drawfilloval(x,y,30,30,7)
delay(3)
drawfilloval(x,y,30,30,0)
end loop



i had to re-draw the oval white because cls would lag my compyuer soooo frigging <b>MUCH</b>

Author:  [Gandalf] [ Mon May 08, 2006 9:20 pm ]
Post subject: 

Yes, please avoid processes for the good of us all.

Quote:
Ya, school computers can be very scary. Last year when me and my partner made our FP, we had made it on our computers, and we can timed the delays and stuff according to our computers, but when we brought it to school,......wow what mess. We used to have computers that if you typed one letter, it would take 5 minutes for it to show up on the screen, and I'm not even joking with you.

This is why you use Time.DelaySinceLast() instead of Time.Delay() aka delay(). It ensures approximately equal run time on computers of all speeds.

Quote:
Not sure about that 100% CPU thing. Probably because of the processes.

Processes are bad, but they are not the cause of this. Turing programs always take up 100% processing power as long as they are running.

For more information on processes, you may want to check out our two tutorials on them:
Part 1.
Part 2.
But better yet, why don't you check out how to organize your program properly into procedures and functions?

Author:  Remm [ Tue May 09, 2006 7:02 am ]
Post subject: 

Uhh... yeah.... about proceedures... Very Happy how exactly are they different from process? it doesnt loop unless you press a key? Confused guess its time for me to look over that Turing Walkthrough thing.
Oh, and my school computers must be horrible, because all process-massing programs seem to work perfectly without delays. As did this one.

I'll try to let up on the process massing, seeing as how its basically random output Sad

Remm

Author:  [Gandalf] [ Tue May 09, 2006 3:27 pm ]
Post subject: 

Processes are concurrent, procedures are sequential. Calling a procedure inside your code is just like copy and pasting the code inside it to that point inside the program. Just more organized and allowing things like arguments, recursion, etc.


: