Results 1 to 6 of 6

Thread: semi random walk (pictorial numerology)

  1. #1

    semi random walk (pictorial numerology)

    Hi
    in the message "prime numbers spiral" the dot walking spirally by a fixed steps, but what if every walk represent something .
    from the old history people assign values to letters of alphabet such as A=1,...,Z=26. so the numerologist(a specialist in a pseudoscience called numerology) can add the values of the characters of your name ,and making some prediction for you, then you give him some money. okay here is a computarized version, in which the dot advanced in 2D space by a value of a character, and proceed spirally to the end of the text.
    the subject called random walk http://en.wikipedia.org/wiki/Random_walk but here the walk rather than random it is defined by the values of the letters of a word or sentence or a whole file.
    here is how the program produce "good evening" if the alpabet values from A to Z = 1 to 26

    if you change the value for G=20 instead of the original 7 the image like this:



    it can be used for ciphers, but there is a problem of the overlapping lines
    the plot for a big text can crawl outside the screen, you may construct a poet to make a closed figure or an interesting shape.
    some comments:
    1:you can make the program to read text from file use:
    myStr = FILE_Load("test.txt")
    2:the figure in the program magnified by 4, if you want more text set magnify = 1
    3:it is not absolute to run the plot in certain clockwise direction, but you can define your own right,left,up,down direction for every char.
    4:i have used remove$ to remove spaces and some possible chars from the string, but we can use regular expressions for a more efficient way.
    other suggestions are welcome.
    regards
    [code=thinbasic]Uses "UI"
    Uses "FILE"
    Dim myStr, char As String
    Dim i,j,colrR,colrG,colrB As Long
    Dim x, y, dots, turn, magnify, charValue As Long
    magnify = 4
    'read a whole file to a string variable:
    'myStr = FILE_Load("test.txt")
    myStr = "good evening"

    myStr = Remove$(myStr, Any " "+","+"."+"-"+":"+"*"+"/")
    myStr = Ucase$(myStr)

    Dim lettersValue(26) As Long
    'assign any values to letters, it is here 1,2,3,...
    'but you can choose 3,1,4,1,5,....
    Array Assign lettersValue(1)=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

    Dim hWin As DWord = Canvas_Window("pictorial numerology", 1, 1, 800, 600 )
    Canvas_Attach(hWin, 0, %TRUE) ' <- double buffer
    Dim t1, t2 As Quad
    hiresTimer_Init
    t1 = hiresTimer_Get
    Canvas_Clear(%BLACK)

    x=400:y=300
    turn=0

    'ploting point number 1 as a small yellow circle:
    Canvas_Ellipse(x-3, y-3, x+3, y+3, Rgb(255, 255, 0),Rgb(255, 255, 0))
    Canvas_Redraw

    Plotting() 'call plotting routine
    'the last point in the plot:
    Canvas_Ellipse(x-3, y-3, x+3, y+3, Rgb(255, 255, 0),Rgb(255, 255, 0))
    Canvas_Redraw
    t2 = HiResTimer_Get

    MsgBox hWin, "Time taken:"+Format$((t2-t1)/1000000, "#.000")+" second --" + dots + " dots drawn", %MB_APPLMODAL


    Canvas_Window end


    Sub Plotting()
    'plotting the first point
    Canvas_Line( (x, y), (x, y) , Rgb(255, 255, 255) )

    For i=1 To Len(myStr)
    charValue = lettersValue(Asc(Mid$(myStr, i, 1))-64)
    turn = turn + 1
    If turn = 5 Then turn = 1
    colrR = 0 : colrG = 255 : colrB = 0

    Select Case turn
    Case 1
    x = x + charValue * magnify
    Case 2
    y = y - charValue * magnify
    Case 3
    x = x - charValue * magnify
    Case 4
    y = y + charValue * magnify
    End Select

    Canvas_Line( Step , (x, y) , Rgb(colrR, colrG, colrB) )

    dots = dots + 1
    Canvas_Redraw
    Next j

    END SUB

    [/code]

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732

    Re: semi random walk (pictorial numerology)

    Hi Zak,

    thanks for another interesting code! I really liked it and I am looking forward to your next creations. It is really inspiring.
    It is lot of fun with longer texts, the shape generated looks like project for some city.

    Just few tips for easier coding:

    If you want just letters from the text, do not hesitate to use Letter$:
    [code=thinbasic]
    ' Instead of:
    myStr = Remove$(myStr, Any " "+","+"."+"-"+":"+"*"+"/")

    ' You can do:
    myStr = LETTER$(myStr)
    [/code]

    ThinBASIC does not force you to use ARRAY ASSIGN, you can do directly this with the same effect:
    [code=thinbasic]
    ' Instead of:
    Array Assign lettersValue(1)=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

    ' You can do:
    lettersValue(1)=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
    [/code]

    If you need ASCII code at given character, simply specify the position
    [code=thinbasic]
    ' Instead of:
    charValue = lettersValue(Asc(Mid$(myStr, i, 1))-64)

    ' You can do:
    charValue = lettersValue(Asc(myStr, i)-64) ' ASC first param is string, second is character position
    [/code]

    The last thing is that in Plotting subroutine you have:
    [code=thinbasic]
    For i=1 To Len(myStr) ' here looping i

    ...

    Next j ' j is not i
    [/code]
    ... but this does not do any trouble, as ThinBasic ignores the token after next. You can even leave it as:
    [code=thinbasic]
    For i=1 To Len(myStr)

    ...

    Next
    [/code]


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3

    Re: semi random walk (pictorial numerology)

    Hi Petr
    your tips are extremely valuable, i never thought that there is a LETTER$ function, also the assignment of several values to the array at once. the thinBasic keywords and methods are very huge.
    thanks

  4. #4
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: semi random walk (pictorial numerology)

    Never ran into this stuff, very interesting and fun. Thanks.
    Repeating a word in even intervals adds a neat pattern.
    Also if you write a sentence, then make a second copy it makes a nice pattern also.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  5. #5

    Re: semi random walk (pictorial numerology)

    thanks kent,
    after trying LETTER$ as suggested by Petr, i think of NUMBER$ but i can't get it to work, what its purpose since it is highlighted?
    anyway i have found LETTER_SetMask$ LETTER_GetMask$, to extract numbers from a text and adding 10 to it:
    [code=thinbasic]Dim s As String
    Dim num As Long
    LETTER_SetMask$("0123456789")
    s = LETTER$("go5od *_ eveni28ng4")
    num = Val(s) + 10
    MsgBox 0, s & " + 10 = " & num[/code]

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732

    Re: semi random walk (pictorial numerology)

    Hi Zak!,

    there is no number$ function in ThinBASIC, what you saw highlighted was number$.
    This is because it is data type:
    [code=thinbasic]
    DIM a, b, c AS NUMBER
    [/code]
    It allows using both integer and floating point numbers, and in fact it is 80bit floating point type.

    But you had good idea - there is function to do what you need, but it is called DIGIT$:
    [code=thinbasic]
    s = "I just saw 4 incredible GPUs for just $99"
    s = DIGIT$(s)
    ' -- s will now contain "499"
    [/code]


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. pictorial representation of Beethoven music
    By zak in forum Shout Box Area
    Replies: 0
    Last Post: 26-04-2011, 15:09

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •