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

Username:   Password: 
 RegisterRegister   
 better way than cls?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Saad85




PostPosted: Thu Jan 05, 2006 3:06 pm   Post subject: better way than cls?

k, boredom got the better of me lately, and i decided to program something. well i have run into a problem. my code involves moving particles, and drawn-in lines using the mouse. i have use offscreenonly and cls to get the particles moving, that part works fine. the thing is, whenever it clears screen, it also clears anything that the mouse has drawn. is there any way to fix this so the particles move fine but anything drawn by the mouse stays on screen?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Thu Jan 05, 2006 3:13 pm   Post subject: (No subject)

Learn about Flexible Arrays. There's a link to the tutorial in the Turing Walkthrough. You can make a flexible array of two points, like this:
code:

var line_data : flexible array 1 .. 0 of
    record
        x1, y1, x2, y2 : int
    end record

Or better yet,
code:

type coord :
    record
        x, y : int
    end record
var line_data : flexible array 1 .. 0 of
     record
          p1, p2 : coord
     end record


Failing that, you erase the particles by, after the View.Update but before you modify their position, drawing a circle of the same size in the background colour. However, this isn't foolproof, as when a particle passes over a line, it will erase part of the line.
Saad85




PostPosted: Fri Jan 06, 2006 2:58 am   Post subject: (No subject)

Cervantes wrote:

code:

type coord :
    record
        x, y : int
    end record
var line_data : flexible array 1 .. 0 of
     record
          p1, p2 : coord
     end record




i understand everything but that part.


also, is there a way i can make lines any shape(squiggles) instead of straight lines or other premade shapes? if not, or if it would lag too much (lag is an issue here) then thats fine, straight lines work fine.


other than that, i just have one question. is there any practical way of erasing these lines after they have been created?
Cervantes




PostPosted: Fri Jan 06, 2006 8:54 am   Post subject: (No subject)

Check out the Records and Types Tutorial

You could do the squiggly line thing, but it would slow things down somwhat. The easiest way to do it would probably be to make a 2D array of pixels that stretch across the entire Run Window. If you're only drawing in white and black (or any two colours), you could use an array of boolean values.

There is a practical way of removing the lines. You just have to remove that element from the flexible array. This is discussed in the Flexible Arrays Tutorial

If you're talking about removing the squiggly lines, it's still possible, but you wouldn't be using the 2D array anymore. You'd probably be using a flexible array of.. a flexible array of points. Scratch that: Turing won't let you create flexible arrays within records.
Saad85




PostPosted: Fri Jan 06, 2006 2:01 pm   Post subject: (No subject)

i get that perfectly now, dont know why i didnt yesterday. guess i was just sleepy. the thing is, the say you said to remove the lines deasn't seem practical.

either the user would have to know which line in the array they want to remove (which is just plain mean, seeing as how it is graphical)

or i would have to go through every line, and see which one they clicked on, and remove it (waay better) but im not sure how to distinguish between left and right clicks in turing.
Saad85




PostPosted: Fri Jan 06, 2006 2:03 pm   Post subject: (No subject)

sorry double post, but i cant seem to edit my last one..

anyway, i thought it might help to have the code
http://www.compsci.ca/v2/viewtopic.php?p=104405#104405
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: