forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


By Mac: Draw shapes in a listbox

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 4 Source Code
View previous topic :: View next topic  
Author Message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Sat May 17, 2003 3:03 pm    Post subject: By Mac: Draw shapes in a listbox Reply with quote

This is an example I found by Mac and thought that it may be of
interest to others. Smile

NOTE: For this to work, you must trim all trailing spaces or download
the script directly. Search for a tool to do this on the forum or download
the script directly at:
http://www.sools.com/vds/files/scripts/listdraw.dsc

Failure to do this will result in errors.


Code:
  OPTION SCALE, 96
  TITLE By Mac
  DIALOG CREATE,Draw Shapes Using Chars In A List Box,-1,0,450,355
  DIALOG ADD,STYLE,Style1,Courier,8,B
  DIALOG ADD,STYLE,Style2,Courier,8
  DIALOG ADD,BUTTON,Clear,5,5,36,20
  DIALOG ADD,COMBO,C1,5,46,114,20,,,CLICK
  DIALOG ADD,TEXT,T1,8,170,,,"x1       y1       x2       y2",,Style2
  DIALOG ADD,COMBO,C2,5,189,40,20,0
  DIALOG ADD,COMBO,C3,5,261,40,20,0
  DIALOG ADD,COMBO,C4,5,333,40,20
  DIALOG ADD,COMBO,C5,5,405,40,20
  DIALOG ADD,LIST,L1,30,5,440,320,,Style1
  DIALOG SHOW

  LIST LOADTEXT, C1
"Line x1,y1 to x2,y2
"Circle radius 3
"Circle radius 4
"Circle radius 5
"Circle radius 6
"Circle radius 7
"Circle radius 8
"Circle radius 9
"Circle radius 10
"Circle radius 11

  %x = 1
  REPEAT
    LIST ADD, C2, %x
    LIST ADD, C4, %x
    if @greater(25, %x)
      LIST ADD, C3, %x
      LIST ADD, C5, %x
    end
    %x = @succ(%x)
  UNTIL @greater(%x, 48)
  LIST SEEK, C2, 11
  LIST SEEK, C3, 0
  LIST SEEK, C4, 34
  LIST SEEK, C5, 23

  rem -- load with 48x24 blank spaces (1 - 48 for X , 0 - 23 for Y)
  rem -- Y is modified to use 1 - 24 input in Dot routine --
:ClearBUTTON
  LIST CLEAR, L1
  %y = 0
  REPEAT
    %x = 1
    %s = ""
    REPEAT
      %s = %s" "
      %x = @succ(%x)
    UNTIL @greater(%x, 48)
    LIST ADD, L1, %s
    %y = @succ(%y)
  UNTIL @greater(%y, 23)

:EVLOOP
  WAIT EVENT
  goto @event()

:C1CLICK
  if @equal(@item(C1), "Line x1,y1 to x2,y2")
    %%x1 = @item(C2)
    %%y1 = @item(C3)
    %%x2 = @item(C4)
    %%y2 = @item(C5)
    GOSUB DrawLine
  else
    rem -- Approx center of draw area --
    %x = 24
    %y = 13
    rem -- Get radius --
    %r = @substr(@item(C1), @pred(@len(@item(C1))), @len(@item(C1)))
    GOSUB DrawCircle
  end
  goto EVLOOP

:CLOSE
  EXIT
  STOP

  rem ---- GOSUB Routines ----

:Dot
  rem -- Draw dot at xd, yd --
  %s = @item(L1, @pred(%%yd))
  %s = @strdel(%s, %%xd)
  %s = @strins(%s, %%xd, @chr(174))
  LIST PUT, L1, %s
  exit

:DrawCircle
  rem -- Draw circle at x, y with approx radius of r --
  rem -- Best I could do, list width/height ratio is strange --
  %%xc = %x
  %%yc = %y
  %x = 0
  %y = %r
  %d = @prod(2, @diff(1, %r))
  REPEAT
    %%xd = @sum(%%xc, %x)
    %%yd = @sum(%%yc, %y)
    GOSUB Dot
    %%xd = @sum(%%xc, %x)
    %%yd = @diff(%%yc, %y)
    GOSUB Dot
    %%xd = @diff(%%xc, %x)
    %%yd = @sum(%%yc, %y)
    GOSUB Dot
    %%xd = @diff(%%xc, %x)
    %%yd = @diff(%%yc, %y)
    GOSUB Dot
    if @greater(@sum(%d, %y), 0)
      %y = @pred(%y)
      rem -- The "4" adjusts vertical ellipse --
      %d = @diff(%d, @pred(@prod(4, %y)))
    end
    if @greater(%x, %d)
      %x = @succ(%x)
      rem -- The "2" adjusts horizontal ellipse --
      %d = @sum(%d, @succ(@prod(2, %x)))
    end
  UNTIL @greater(0, %y)
  exit

:DrawLine
  rem -- Draw line from x1,y1 to x2,y2 --
  if @greater(%%x2, %%x1)
    %%dx = @diff(%%x2, %%x1)
    %%sx = 1
  else
    %%dx = @diff(%%x1, %%x2)
    %%sx = -1
  end
  if @greater(%%y2, %%y1)
    %%dy = @diff(%%y2, %%y1)
    %%sy = 1
  else
    %%dy = @diff(%%y1, %%y2)
    %%sy = -1
  end
  %%steep = ""
  if @greater(%%dy, %%dx)
    %%steep = 1
    rem -- swap x1 y1, dx dy, sx sy --
    %z = %%x1
    %%x1 = %%y1
    %%y1 = %z
    %z = %%dx
    %%dx = %%dy
    %%dy = %z
    %z = %%sx
    %%sx = %%sy
    %%sy = %z
  end
  %e = @diff(@prod(2, %%dy), %%dx)
  %i = 0
  REPEAT
    if %%steep
      %%xd = %%y1
      %%yd = %%x1
    else
      %%xd = %%x1
      %%yd = %%y1
    end
    GOSUB Dot
    if @greater(%e, -1)
      REPEAT
        %%y1 = @sum(%%y1, %%sy)
        %e = @diff(%e, @prod(2, %%dx))
      UNTIL @greater(0, %e)
    end
    %%x1 = @sum(%%x1, %%sx)
    %e = @sum(%e, @prod(2, %%dy))
    %i = @succ(%i)
  UNTIL @equal(%i, %%dx)
  %%xd = %%x2
  %%yd = %%y2
  GOSUB Dot
  exit


EDIT: Forgot to copy DrawCircle and DrawLine subs. Added.
EDIT 2: Changed the code again for compatibility with VDS 4

_________________
FreezingFire
VDSWORLD.com
Site Admin Team


Last edited by FreezingFire on Sun May 18, 2003 2:12 pm; edited 5 times in total
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sat May 17, 2003 3:54 pm    Post subject: Reply with quote

The script is missing the DrawCircle and DrawLine subs...
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Sun May 18, 2003 12:36 pm    Post subject: Reply with quote

You're right. I forgot to copy them. Thanks for reminding me Skit. Very Happy
_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sun May 18, 2003 1:03 pm    Post subject: Reply with quote

I can't get it to work...

It gives an error 25 on line 101... (Non-numeric value)

[code]%d = @prod(2, @diff(1, %r))[code]

I used the following values:
[code]%d = 0
%r = 5[/code]

I know why the error is, because of the @diff(1,%r), but I don't know how the code works, so I don't want to change things myself... Sad

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Sun May 18, 2003 1:58 pm    Post subject: Reply with quote

Yeah I ran into that error before I posted it the second time. But then I
tried it again and it worked fine. Confused

Here's the direct link:
http://www.sools.com/vds/files/scripts/listdraw.dsc

I just wanted to post it on the forum since it probably gets more attention
here.

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Sun May 18, 2003 2:01 pm    Post subject: Reply with quote

Let me try posting it again. It works for me. Just look:


_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Sun May 18, 2003 2:04 pm    Post subject: Reply with quote

OH! I think I know what is creating the trouble: When you copy text from
a web page it adds extra spaces on to the end. This is what is causing the
trouble I think.

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sun May 18, 2003 2:10 pm    Post subject: Reply with quote

If I download it it works. It must be the problem you said, with the extra spaces on the end...
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
GeoTrail
Valued Contributor
Valued Contributor


Joined: 18 Feb 2003
Posts: 572
Location: Bergen, Norway

PostPosted: Sun May 18, 2003 2:39 pm    Post subject: Reply with quote

I downloaded the source file and nothing happens.
I try to select different options in the combo and click around but nothing happens.

Is it just me? Embarassed

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sun May 18, 2003 2:43 pm    Post subject: Reply with quote

You should use the combo on the left. The other ones are to draw a line.
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
GeoTrail
Valued Contributor
Valued Contributor


Joined: 18 Feb 2003
Posts: 572
Location: Bergen, Norway

PostPosted: Sun May 18, 2003 2:50 pm    Post subject: Reply with quote

I did. Maybe this is for v3.x?

How am I supposed to draw?
Use the keyboard?

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Sun May 18, 2003 2:52 pm    Post subject: Reply with quote

The original source file is for 3.x

I had changed it and posted it but it didn't work with the extra spaces.
You need to add commas before the styles to upgrade it to 4.x code.
Take a look at the code posted to see how many commas are needed.

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 4 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group