asc and chr

Post Reply
User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

asc and chr

Post by rbytes »

I would like to see the functions #.asc() and #.chr() added. I don't know if there are emoji characters available in Windows, but there should be some symbol characters that would be useful. To find them, we could built an SPL ASCII character display and selection program using these functions.
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: asc and chr

Post by Mr. Kibernetik »

In SPL working with characters is much more sophisticated. It works with Unicode characters of different complexity.
You can check "rosetta\string length.txt" program example to see how SPL treats characters. Simple ASC() function is not enough.

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: asc and chr

Post by Mr. Kibernetik »

Similarly, it is possible to convert bytes to Unicode string with #.str function:

Code: Select all

a = [4Ah, 00h, 32h, 03h, 6Fh, 00h, 32h, 03h, 73h, 00h, 32h, 03h, E9h, 00h, 32h, 03h]
#.output(#.str(a))
Result:

J̲o̲s̲é̲

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: asc and chr

Post by Mr. Kibernetik »

This program prints emoticons:

Code: Select all

i = 1
> n, 0..ffh
  a[i] = n
  i += 1
  a[i] = 26h
  i += 1
<
#.output(#.str(a))
Result:

☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓☔☕☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻☼☽☾☿♀♁♂♃♄♅♆♇♈♉♊♋♌♍♎♏♐♑♒♓♔♕♖♗♘♙♚♛♜♝♞♟♠♡♢♣♤♥♦♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚇⚈⚉⚊⚋⚌⚍⚎⚏⚐⚑⚒⚓⚔⚕⚖⚗⚘⚙⚚⚛⚜⚝⚞⚟⚠⚡⚢⚣⚤⚥⚦⚧⚨⚩⚪⚫⚬⚭⚮⚯⚰⚱⚲⚳⚴⚵⚶⚷⚸⚹⚺⚻⚼⚽⚾⚿⛀⛁⛂⛃⛄⛅⛆⛇⛈⛉⛊⛋⛌⛍⛎⛏⛐⛑⛒⛓⛔⛕⛖⛗⛘⛙⛚⛛⛜⛝⛞⛟⛠⛡⛢⛣⛤⛥⛦⛧⛨⛩⛪⛫⛬⛭⛮⛯⛰⛱⛲⛳⛵⛶⛷⛸⛹⛺⛻⛼⛽⛾⛿

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: asc and chr

Post by Mr. Kibernetik »

Of course it can be done by just

Code: Select all

#.output("🤴")

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: asc and chr

Post by rbytes »

Thanks, Mr. K.
Windows has come a long way with characters! I will need to study this.
The only thing that gets me down is gravity...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: asc and chr

Post by rbytes »

Here is a slight modification of the code that draws the text instead of outputting to the console
Another surprise - for me, anyway. The characters lose their colors.

Code: Select all

i = 1
> n, 0..ffh
  a[i] = n
  i += 1
  a[i] = 26h
  i += 1
<
#.fontsize(60)

> t, 1..300,30
#.drawtext(10,50+t*2.4,#.mid(#.str(a),t,20))
<
Attachments
Screenshot (100).png
Screenshot (100).png (278.81 KiB) Viewed 3668 times
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: asc and chr

Post by Mr. Kibernetik »

Because they are not text characters anymore but graphics symbols :D

Code: Select all

i = 1
> n, 0..ffh
  a[i] = n
  i += 1
  a[i] = 26h
  i += 1
<
#.fontsize(60)

> t, 1..300,30
  #.drawcolor(#.hsv2rgb(t/300*360,1,1):3)
  #.drawtext(10,50+t*2.4,#.mid(#.str(a),t,20))
<
Снимок.JPG
Снимок.JPG (223.63 KiB) Viewed 3667 times

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: asc and chr

Post by rbytes »

I found a link to the Windows Unicode table:

https://unicode-table.com/en/

One of the characters it shows is a checkmark ✓. This would make a good indicator for multiple selections in a list.
It didn't appear in the output when I ran your code above. What upper limit should the loop be set for to output the entire Unicode table?
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: asc and chr

Post by Mr. Kibernetik »

rbytes wrote:
Sat Oct 14, 2017 10:43 pm
I found a link to the Windows Unicode table:

https://unicode-table.com/en/

One of the characters it shows is a checkmark ✓. This would make a good indicator for multiple selections in a list.
It didn't appear in the output when I ran your code above. What upper limit should the loop be set for to output the entire Unicode table?
There is no upper limit. Unicode table is more than 65000 character codes. In the code above there are only 256 characters with codes from 2600 to 26FF.

Post Reply