Computer Science Canada

Moving A Polygon

Author:  Blockgen [ Sat Oct 20, 2012 1:37 pm ]
Post subject:  Moving A Polygon

What is it you are trying to achieve?
I'm trying to get a polygon (car) to move across the screen.


What is the problem you are having?
It's giving me error codes because I don't exactly know how to do this, so I used background knowledge.


Describe what you have tried to solve this problem
I tried making the integers in the array variables that change


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:


setscreen ("graphics:500;500")
var x0 : int := 0
var x10 : int := 10
var x13 : int := 13
var x20 : int := 20
var x27 : int := 27
var x30 : int := 30
var x35 : int := 35
var x65 : int := 65
var x80 : int := 80
var x83 : int := 83
var x90 : int := 90
var x97 : int := 97
var x100 : int := 100
var x110 : int := 110

var xc : array 1 .. 22 of int := init (   x0,   x0,  x10,  x20,  x35,  x65,  x80,  x90,  x90, x100, x110, x110, x100,  x97,  x90,  x83, x80, x30, x27, x20, x13,  x10)
var yc : array 1 .. 22 of int := init (   020203040403020201810,   0,   0,   710,   7007, 107,   0)

loop
    loop
        Draw.FillPolygon (xc, yc, 22, red)
        x0:= x0 + 2, x10:= x10 + 2, x13:= x13 + 2, x20:= x20 + 2, x27:=  x27 + 2, x30:=  x30 + 2, x35:=  x35 + 2, x65:=  x65 + 2, x80:=  x80 + 2, x83:=  x83 + 2, x90:=  x90 + 2, x97:=  x97 + 2, x100:=  x100 + 2, x110:=  x110 + 2
        exit loop xc = 500
    end loop
end loop




Please specify what version of Turing you are using
4.1

Author:  Zren [ Sat Oct 20, 2012 2:44 pm ]
Post subject:  RE:Moving A Polygon

What would be the output of the following? Try it out yourself in Turing.

Turing:

var a, b : int
a := 0
b := a
a += 1

put a
put b


:= will assign the calculated value on the right side to the left side's variable. Later on, you will encounter pointers, which can be used like you wish to here.

Author:  evildaddy911 [ Sun Oct 21, 2012 9:09 am ]
Post subject:  RE:Moving A Polygon

you are changing the the various x variables, but then what are you doing with them?
When it draws the car, what variables is the Draw.FilPpolygon using?

Author:  QuantumPhysics [ Sun Oct 21, 2012 2:03 pm ]
Post subject:  RE:Moving A Polygon

You should also give your x values more definite names. Not some random numbers. possibly name them in order or by vertices. Also, you don't have to define them straight down, i am some what positive that turing lets you define them in a list (e.g. int x1 = 1, x2 = 2, x3 = 3) <- on the same line.

Author:  chipanpriest [ Wed Oct 31, 2012 7:30 pm ]
Post subject:  Re: Moving A Polygon

You could have a for statement to get all x values to increase:

Turing:

for i : 1 .. upper(xc)
xc (i) += 2
end for


See if this works

Author:  Raknarg [ Thu Nov 01, 2012 10:23 am ]
Post subject:  RE:Moving A Polygon

Listen to what Zren said, he is doing exactly what you're doing.

Tell us why, in Zren's program, a does not equal b anymore.


: