Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
How do you move a circle in turing
Author Message
Kobe24

Posted: Sat May 17, 2014 9:57 pm   Post subject: How do you move a circle in turing

How do you move a circle in Turing?

Raknarg

Posted: Sun May 18, 2014 11:18 am   Post subject: RE:How do you move a circle in turing

There's a couple different methods. Either a for loop, or a variable. Here's two examples of a circle moving back and forth:

for loop:
 Turing: loop     for x : 1 .. 150         Draw.FillOval(x, 200, 10, 10, 12)         delay(5)         cls     end for     for decreasing x : 150 .. 1         Draw.FillOval(x, 200, 10, 10, 12)         delay(5)         cls     end for end loop

variables:
 Turing: var x : int := 0 var direction : int := 1 loop     x += direction %this means add value of direction to x         if x <= 0 then         direction := 1     elsif x >= 150 then         direction := -1     end if         Draw.FillOval(x, 200, 10, 10, 12)     delay(5)     cls end loop

Personally I would say the second one is the best option.
Jesse Kazemi

Posted: Wed May 21, 2014 6:25 pm   Post subject: Re: How do you move a circle in turing

Kobe24 @ Sat May 17, 2014 9:57 pm wrote:
How do you move a circle in Turing?

like this :

% ICS2O - draw moving circle across screen
View.Set ("graphics")

const R := 30
const DELAY := 5
const STEP := 2
% Initially setting the x, y values to place a ball in the top left corner
% of the screen
var x : int := 0 + R
var y : int := maxy - R
var col := 13 % this is the colour pink
const BGD := white
loop
loop
exit when x > maxx - R % off the right side of the screen
% cls % clears the screen
Draw.FillOval(x-STEP, y, R,R, BGD) % reduces flicker rather than cls
% draw oval with centre at x,y and x,y radius = R and colour = col
Draw.FillOval (x, y, R, R, col)
delay (DELAY) % delays for DELAY milliseconds
x := x + STEP % move the ball to the right a bit
end loop

% col := col + 1
loop
exit when x < R % off the left side of the screen
cls % clears the screen
% draw oval with centre at x,y and x,y radius = R and colour = col
Draw.FillOval (x, y, R, R, col)
delay (DELAY) % delays for DELAY milliseconds
x := x - STEP % move the ball to the left a bit
end loop
end loop
Raknarg

Posted: Wed May 21, 2014 9:30 pm   Post subject: RE:How do you move a circle in turing

Like I said though, that's not a good method if you want to animate more than one thing.
Jesse Kazemi

Posted: Wed Jun 18, 2014 1:22 pm   Post subject: Re: How do you move a circle in turing

True that but it is a simpler method
Raknarg

Posted: Wed Jun 18, 2014 8:29 pm   Post subject: RE:How do you move a circle in turing

It's not really that much different.
Srlancelot39

Posted: Wed Jun 18, 2014 9:38 pm   Post subject: RE:How do you move a circle in turing

I haven't done graphics in a while, but look into procedures and processes if you'd like to move more than one object at a time.
Note: Processes in Turing don't mix well with graphics. I recommend using procedures and a single, very short delay.
Raknarg

Posted: Wed Jun 18, 2014 10:48 pm   Post subject: RE:How do you move a circle in turing

Never use processes in Turing.

Srlancelot39

Posted: Thu Jun 19, 2014 7:43 am   Post subject: Re: RE:How do you move a circle in turing

Raknarg @ Wed Jun 18, 2014 10:48 pm wrote:
Never use processes in Turing.

This.

The only exception I know of is sound. Sound seems to work fine in processes. Anything else, no.

A real example is my medieval RPG, "Grail Quest" (link in my signature), where I have a process for each sound effect and a process for the music. I tried drawing moving clouds using processes and it just created a flashfest...so no moving clouds lol.

EDIT: I've heard that the reason for this is that Turing processes do not actually function as proper processes, but instead have their code wedged into the rest of the code as it runs and does a very bad job of it. I'm assuming that the reason why sound is okay is because it does not need to be refreshed like images do; the process just tells it to play once (because that is the nature of sound files) and it does so.

EDIT2: My Grail Quest download does not include the source code, just the application...sorry :/

Posted: Thu Jun 19, 2014 3:49 pm   Post subject: Re: How do you move a circle in turing

Srlancelot39 wrote:
I've heard that the reason for this is that Turing processes do not actually function as proper processes, but instead have their code wedged into the rest of the code as it runs and does a very bad job of it. I'm assuming that the reason why sound is okay is because it does not need to be refreshed like images do; the process just tells it to play once (because that is the nature of sound files) and it does so.

I would tend to say that in reality it is because it is often tougher to reason about the behavior of concurrent threads/processes. When you have two processes running in parallel there are certain things you can no longer assume.
Most of the time people use processes in Turing when they are not necessary and often without understanding what they are.

The reason sound is fine is because your process is not the one playing the sound, Turing (or maybe just good old Windows) does all the work for you.
Srlancelot39

Posted: Thu Jun 19, 2014 5:30 pm   Post subject: Re: How do you move a circle in turing

Dreadnought @ Thu Jun 19, 2014 3:49 pm wrote:
The reason sound is fine is because your process is not the one playing the sound, Turing (or maybe just good old Windows) does all the work for you.

That's very sound reasoning, haha
Seriously though, that makes sense - thanks!
Lucas.M

Posted: Sat Apr 18, 2020 6:16 pm   Post subject: Re: How do you move a circle in turing

This works, but my circle keeps flickering when it moves. Any suggestions on how i stop it? I did GUI.Refresh and the View.Set commands but I assume you already know it doesn't work.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 12 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: