Home > MicroWorlds EX Robotics Examples > MicroWorlds EX Robotics Maths Projects > Graph-temp Code

Graph-temp Code


; Purpose: To record & plot temperature data
; Copyright © 2004 by Rupert Russell
; e-mail: rupert.russell1@gmail.com
; URL: http://www.rupert.id.au/microworlds/
; Created: November 28, 2004

; This program is free software;
; you can redistribute it and/or modify
; it under the terms of the GNU General
; Public License as published by
; the Free Software Foundation;
; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the 
; hope that it will be useful,
; but WITHOUT ANY WARRANTY;
; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A
; PARTICULAR PURPOSE. See the
; GNU General Public License for more
; details.
;
; You should have received a copy of
; the GNU General Public License
; along with this program; if not,
; write to the Free Software
; Foundation, Inc., 675 Mass Ave,
; Cambridge, MA 02139, USA.
; -----------------------------------

to startup
   ; used to number
   ; new event text
   ; boxes

   ; read the value from
   ; the hidden event_number
   ; text box
   make "event_count event_number

   pu
   cc

   ; hide the Stop button
   set "button4 "visible? "false
end

to start
   cc
   pd
   talkto "temperature
   bottom
   unselect
   print "

   setc "black
   t1, clickon
   sendrc [beep]

   ; hide the Start button
   set "button2 "visible? "false

   ; show the Stop button
   set "button4 "visible? "true
end

to stop_plotting
   t1, clickoff

   sendrc [beep]

   ; hide the Stop button
   set "button4 "visible? "false

   ; show the Start button
   set "button2 "visible? "true
end

to clear
   pu
   cg
   setpos [-352 23]

   talkto "Temperature
   ct
   cc
   clear_events

   ; move to current temperature
   carefully [sety (requestrm "temp1) / 2][ ]
   pd
end

to clear_events
   ; used to number
   ; new event text
   ; boxes

   make "event_count 0

   ; used to remember the
   ; current event_count
   ; this value is
   ; saved with the project

   talkto "event_number
   ct
   insert :event_count

   make "counter 0

   ; remove all event
   ; markers

   repeat 100 [
      make "counter :counter + 1
      make "new_name word "event :counter

      carefully [remove :new_name] []
   ]
end

to copy_data
   t1, clickoff

   talkto "Temperature
   top
   select
   bottom
   copy

   ; select the text
   ; again to show that
   ; it was copied

   top
   select
   bottom
end

to plot_data
   ; Plot the data
   ; in temperature
   ; text box again

   pu
   cg
   setpos [-352 23]
   setc "blue

   talkto "temperature
   top
   make "number_of_lines textcount "temperature

   repeat :number_of_lines [
      select
      eol
      ; copy to clipboard
      copy
      cd
      sol

      ; read the clipboard
      make "temp_value clipboard

     ; plot the value
      sety :temp_value
      pd
      ; move along the x axis

      setx xcor + 5
   ]
end

to event
   ; mark an event
   ; with a text box

   if :event_count > 99 [
      announce [You can only add 100 events]
      stop
   ]

   question [Enter event text]

   make "event_count :event_count + 1

   ; create the name for
   ; the new text box

   make "new_name word "event :event_count

   make "string1 (se (word char 91 xcor char 32 ycor char 93)
     (word char 91 150 char 32 30 char 93) )

   make "string2 (word "newtext char 32 char 34 :new_name
      char 32 :string1)

   carefully [run :string2] []

   talkto :new_name
   showtext
   top
   insert answer
   carefully [transparent :new_name] [ ]


   ; record current
   ; event_number
   ; in the hidden
   ; text box
   ; "event_number

   talkto "event_number
   ct
   insert :event_count
end




APA citation:
Russell, R. (2016, July 05, 07:14 am). Graph-temp Code.
     Retrieved November 21, 2017, from http://www.rupert.id.au/microworlds/code/art2.php

1768 Visits since August 26, 2005