PDA

View Full Version : semi random walk (pictorial numerology)



zak
11-06-2010, 17:52
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
https://sites.google.com/site/zak31415/Home/numerology.PNG
if you change the value for G=20 instead of the original 7 the image like this:

https://sites.google.com/site/zak31415/Home/numerology2.PNG

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

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

Petr Schreiber
11-06-2010, 18:30
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$:


' Instead of:
myStr = Remove$(myStr, Any " "+","+"."+"-"+":"+"*"+"/")

' You can do:
myStr = LETTER$(myStr)


ThinBASIC does not force you to use ARRAY ASSIGN, you can do directly this with the same effect:


' 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


If you need ASCII code at given character, simply specify the position


' 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


The last thing is that in Plotting subroutine you have:


For i=1 To Len(myStr) ' here looping i

...

Next j ' j is not i

... but this does not do any trouble, as ThinBasic ignores the token after next. You can even leave it as:


For i=1 To Len(myStr)

...

Next



Petr

zak
11-06-2010, 18:54
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

kryton9
11-06-2010, 23:08
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.

zak
12-06-2010, 11:56
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:

Dim s As String
Dim num As Long
LETTER_SetMask$("0123456789")
s = LETTER$("go5od *_ eveni28ng4")
num = Val(s) + 10
MsgBox 0, s & " + 10 = " & num

Petr Schreiber
12-06-2010, 12:58
Hi Zak!,

there is no number$ function in ThinBASIC, what you saw highlighted was number$.
This is because it is data type:


DIM a, b, c AS NUMBER

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$:


s = "I just saw 4 incredible GPUs for just $99"
s = DIGIT$(s)
' -- s will now contain "499"



Petr