Author Topic: Interactive program  (Read 2779 times)

0 Members and 1 Guest are viewing this topic.

Zahex

  • Guest
Interactive program
« on: May 15, 2005, 02:05:53 PM »
How can i create an interactive program?
For example :

i want the user to be able to define two final draws with the same program,defining paths through which the user can chose between possibilities...

Please help

Thanks

daron

  • Guest
Interactive program
« Reply #1 on: May 16, 2005, 07:45:47 AM »
What are two final draws? Cond sounds like the option you want for possibilities.

Zahex

  • Guest
Interactive program
« Reply #2 on: May 16, 2005, 10:40:59 AM »
Yes DARON you're right,cond is what i need...
What i mean by 2 final draws is that in the end the program allows me to choose between paths and the final draw can be different because of the options i've input...

Thanks

daron

  • Guest
Interactive program
« Reply #3 on: May 16, 2005, 11:25:21 AM »
Okay, So, what's your question, then?

Zahex

  • Guest
Interactive program
« Reply #4 on: May 16, 2005, 11:29:43 AM »
ok,i'll post you the code i have and i ask you to run it and tell me why doesn't it work in the part where you ask the transformation question ("change/exit/restart)...

Code: [Select]




(command "layer" "new" "solido" "color" "40" "solido" "") ;volume
(command "layer" "new" "espiral" "color" "30" "espiral" "") ;espiral
(command "layer" "new" "estrutura" "color" "20" "estrutura" "");structure


;;; start
(alert "To run type: Tatlin")
;;; ESPIRAL
(defun espiral(param)
 
  (setq spin -1); -1=CW, 1=CCW
  (setq ri (car param) rf (cadr param))
  (setq h (nth 2 param))
  (initget (+ 1 2 4))
  (setq ns (getint "number of spirals:" ))
  (setq tu (getreal "Number of turns: "))
  (setq rt (getreal "extrusion radius: "))
  (setq segs (nth 3 param))
  (setq old (getvar "osmode"))
  (setvar "cmdecho" 0)  
  (setq fi1 (/ (* 2 PI) segs) i 0)
  (setq points (fix (* tu segs))
h1     (/ h points)
r1     (/ (- rf ri) points)
s      (last param)
  );end setq
 
  (setvar "osmode" 0 )
  (command "3dpoly")
  (setq i 0)
  (repeat (1+ points)
    (setq fi (* i fi1) h (* i h1) r (+ ri (* i r1)))
    (setq x (* r (cos fi)) y (* spin r (sin fi)))
    (command (list (+ (car s) x) (+ (cadr s) y) (+ (caddr s) h)))
    (setq i (1+ i)))
  (command "")
  (setvar "osmode" old)
  (setq spiral (entlast))
  (command "ucs" "n" "za" (polar s 0 ri)
  (list
  (+(car s) (* ri (cos fi1)))
  (+(cadr s) (* spin ri (sin fi1)))h1))


  (command "circle" "0,0,0" rt)
  (command "extrude" (entlast) "" "p" spiral)
  (setvar "osmode" old)
  (command "ucs" "p")
  (command "array" (entlast) "" "p" s ns 360 "y")
  ); end defun





; transformation question

(defun c:Question ()
  (command "zoom" "e")
  (initget 1 "Change eXit Restart")
  (setq answer (getkword "\n Enter option: [Change/eXit/Restart] "))
  (cond
    ((eq answer "Change")(c:spiral))
    ((eq answer "eXit"))
    ((eq answer "Restart")(c:sol))
    )
  (princ)
  ); defun
   
;;; SOLID
(defun c:sol ()
  (setq r1 (getdist "\n larger radius: ")
r2 (getdist "\n smaller radius: ")
h (getdist "\n height: ")
sides (getint "\n number of polygon sides: ")          
centerpt (getpoint "\n insertion point: ")
osnaps (getvar "osmode")
ang (atan (* (/ (- r1 r2) h) (cos (/ PI sides))))

  ); end setq
 
  (setvar "osmode" 0)
  (command "polygon"
  sides
  centerpt
  "I"
  (polar centerpt 0 r1)
  )
  (command "extrude" (entlast) "" h (/ (* ang 180.0) pi ))
  (setvar "osmode" osnaps)
  (list r1 r2 h sides centerpt)
  (command "zoom" "ex")
 (c:Question)
) ;end defun



 
  ;;; initial function

(defun c:Tatlin ()
 
  (c:sol)
);defun



daron

  • Guest
Interactive program
« Reply #5 on: May 16, 2005, 11:41:07 AM »
Haven't you asked this question in another thread already? I'll look at it. Wait a minute.

daron

  • Guest
Interactive program
« Reply #6 on: May 16, 2005, 11:57:24 AM »
Alright. First of all, I believe CAB probably answered you, but I've looked at it. The first problem I see is that if someone were to hit C for change, the program would break because there is no function called c:spiral. Your code above says espiral and there is an argument required with it, which you also have not supplied. Your cond statement could be a little better too. Have a look at this:
Code: [Select]

  (cond
    ((eq answer "Change")(espiral (list "dont" "forget" "your" "argument")))
    ((eq answer "Restart")(c:sol))
    )

You could take out the eXit part and also the 1 from your initget and consider eXit as the default, or even use a call to enter as a default for something else, like so:
((or (aq answer "Restart") (eq answer nil)))
I hope that helps.

Sorry if my post reads a little annoyed. I don't wish to sound that way, but just so you know, most of the people here read all the threads and posts within those threads. Posting the same question in different ways in different threads may turn a few of us off. Please consider this for future topics.

Zahex

  • Guest
Interactive program
« Reply #7 on: May 16, 2005, 02:00:11 PM »
You're right Daron,it's just that i need to figure this out as soon as possible...

Please answer me this question:

Can you explain what the (param) next to (defun spiral) means?
and if it is a list why isn't it defined with values...?

Thanks for your help

daron

  • Guest
Interactive program
« Reply #8 on: May 16, 2005, 02:37:20 PM »
I assume you're referring to this:
Code: [Select]
(defun espiral(param)
param is an argument. It's a variable that is required in order to run the program. There are three things to look for at the defun line:

() or (/) empty set. This usually means there are no variables to consider or clear

(param) means the user (program or calling user) need to supply something in order for it to work. Since you don't know what param means, I realize you didn't write the code. On that note, I'd say you might do best to contact the person that did write it and see if this is something you should be posting in a public forum.

Lastly, (/ local variable) This is where the programmer helps the computer out by freeing up the space used up by using variables. It resets all variable values to nil when it's finished with them. You can combine arguments and local variables like so: (param / local variable)

So, the reason it's not defined with values, is that it allows the user to supply different values upon invocation. The value put in there could be anything, but the way that code is written it requires a numeric? list with at least 4 values. I think you're going to have problems with this because you aren't allowing your user to define the list and I'm guessing there could be any number of list combos that would make this too big.

Zahex

  • Guest
Interactive program
« Reply #9 on: May 17, 2005, 10:23:39 AM »
The param is an argument that saves the information given by the solid function because the program needs those values to draw the spiral...

As you can see in the code i sent you,the spiral is drawn by a 3D poly and according to the number of sides,height and rasdius  there are points,how can i create a list with those points so i can use them later?

Thanks

daron

  • Guest
Interactive program
« Reply #10 on: May 17, 2005, 11:24:51 AM »
I doubt they are the same points always, that is why I feel there would be too much to do, however, you could put together a procedure that would prompt the user for that list before proceding with that function, then pass the results of the user defined list to the espiral function. Taking it further, you could get into a dialog box with some default values and allow your users to change as they will, then they wouldn't have to go through each prompt every time. I don't get into dialog boxes much. It's rare when I do, so I'm not going to be any help there. I bet if you write the code for the command prompting and post it, someone might be happy to help you convert it into a dialog box.

Zahex

  • Guest
Interactive program
« Reply #11 on: May 17, 2005, 08:13:14 PM »
Thanks Daron for your help but i don't have a clue what your talking about,i'm sorry but i don't understand much about LISP.

Are you sure there isn't any way simpler to get the points and save them in a list so afterwards i may be able to use them to draw lines starting on those points?

Please give a help

Thanks