random walks with VectorDrawing

Share your advanced PureBasic knowledge/code with the community.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

random walks with VectorDrawing

Post by applePi »

just a play, in ancient magic there is values for every letter, suppose we are in english language, and the values from 1 to 26. we go through characters and plotting their values in a square spiral mode, so "zzzz" will make a square
but i am in trouble with any unicode issues, in PB 5.50 how to plot french or german chars which have marks over it such as é , or hauptsächlich, in english windows ? thanks in advance for any code variations, amusements or ideas.

notes: change magnify to other value to fit the graphics within the window

Code: Select all

OpenWindow(0, 0, 0, 800, 600, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 2, 2, 795, 595, #PB_Canvas_Border   )

magnify = 7
x = 400 : y = 300

chars.s = "cupoftea"; "zzzz"
chars = UCase(chars)

Dim charValue(26)
For i=1 To 26
  Read.l charValue(i)
Next
StartDrawing(CanvasOutput(0)) 
Circle(x,y,3, RGB(255,0,0))
StopDrawing()
If StartVectorDrawing(CanvasVectorOutput(0)) 
MovePathCursor(x, y)
For i=1 To Len(chars)
  letterValue = charValue(Asc(Mid(chars, i, 1))-64)
  
turn = turn + 1
If turn = 5 
  turn = 1
EndIf
  
   Select turn
     Case 1
        x = x + letterValue * magnify
     Case 2
        y = y - letterValue * magnify
     Case 3
       x = x - letterValue * magnify
     Case 4
       y = y + letterValue * magnify
    EndSelect
        
    VectorSourceColor(RGBA(50, 0, 255, 255))
    AddPathLine(x, y, #PB_Path_Default) 
    StrokePath(1, #PB_Path_Preserve)

  Next
  
  StopVectorDrawing()
EndIf
StartDrawing(CanvasOutput(0)) 
Circle(x,y,3, RGB(255,0,0))
StopDrawing()

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

DataSection
  Data.l 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26
EndDataSection
Last edited by applePi on Fri Nov 04, 2016 1:31 pm, edited 1 time in total.
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: random walks with VectorDrawing

Post by #NULL »

to my knowledge german umlauts äöüß are not defined in an contiguous sequence to form a simple alphabeth, neither in ascii nor as unicode character codes. so you might have to define the sequence manually. the same is probably true for other languages.

Code: Select all

Debug Asc("A") - 65
Debug Asc("B") - 65
Debug Asc("a") - 65
Debug Asc("b") - 65

Debug Asc("z") - 65
Debug Asc("ä") - 65
Debug Asc("ö") - 65
Debug Asc("ü") - 65
Debug Asc("ß") - 65

Debug "---------"

abc.s = "abcdefghijklmnopqrstuvwxyzäöüß"

For c=1 To Len(abc)
  Debug "" + c + " : " + Mid(abc, c, 1)
Next
also for languages like hebrew you might want to use a non contiguous sequence even for the numbers, so would need to define the sequences on your own.
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: random walks with VectorDrawing

Post by Demivec »

Try doing a random walk with this string:

Code: Select all

chars.s = "  z   z   e db  an  hhhjllpxc  bqb  bjch  e  hcji  b"
chars + "gb  ah  ebhjb  bqb  abg  d  dbddgfjji  b"
chars + "pb  ab  chf  bf  b  hfb  bfrhf  cba  b  bfb  bb  blxl  b"
chars + "sb  abb  hhb  cfc  bdhbb  bbb  bb  be  b"
chars + "mb  afg  b  gbjfg  b  gbi  bfb  aja  b  abcbb  b  bjb  b"
chars + "lb  abf  f  fbijh  bb  b  z   z   z   z   j   j"
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: random walks with VectorDrawing

Post by applePi »

Thank you #NULL and Demivec
the Demivec string produce PureBasic word, thank you very much, i supposed the space char = 0
Image

not optimized code

Code: Select all

OpenWindow(0, 0, 0, 800, 600, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 2, 2, 795, 595, #PB_Canvas_Border   )

magnify = 5
x = 400 : y = 300

;this bizarre string is provided by Demivec
chars.s = "  z   z   e db  an  hhhjllpxc  bqb  bjch  e  hcji  b"
chars + "gb  ah  ebhjb  bqb  abg  d  dbddgfjji  b"
chars + "pb  ab  chf  bf  b  hfb  bfrhf  cba  b  bfb  bb  blxl  b"
chars + "sb  abb  hhb  cfc  bdhbb  bbb  bb  be  b"
chars + "mb  afg  b  gbjfg  b  gbi  bfb  aja  b  abcbb  b  bjb  b"
chars + "lb  abf  f  fbijh  bb  b  z   z   z   z   j   j"

chars = UCase(chars)

Dim charValue(32)
For i=1 To 32
  Read.l charValue(i)
Next
StartDrawing(CanvasOutput(0)) 
Circle(x,y,3, RGB(255,0,0))
StopDrawing()
If StartVectorDrawing(CanvasVectorOutput(0)) 
MovePathCursor(x, y)
For i=1 To Len(chars)
  OneChar = Asc(Mid(chars, i, 1))
  Select OneChar
      Case  65 To 90
        letterValue = charValue(Asc(Mid(chars, i, 1))-64)
      Case  32
        letterValue = 0
 EndSelect
 
turn = turn + 1
If turn = 5 
  turn = 1
EndIf
  
   Select turn
     Case 1
        x = x + letterValue * magnify
     Case 2
        y = y - letterValue * magnify
     Case 3
       x = x - letterValue * magnify
     Case 4
       y = y + letterValue * magnify
    EndSelect
        
    VectorSourceColor(RGBA(50, 0, 255, 255))
    AddPathLine(x, y, #PB_Path_Default) 
    StrokePath(1, #PB_Path_Preserve)

  Next
  
  StopVectorDrawing()
EndIf
StartDrawing(CanvasOutput(0)) 
Circle(x,y,3, RGB(255,0,0))
StopDrawing()

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

DataSection
  Data.l 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,0,0,0,0,0,0
EndDataSection
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: random walks with VectorDrawing

Post by davido »

@applePi, Nice magic. :)

Impressive addition by Demivec.
DE AA EB
Post Reply