POV-Ray : Newsgroups : povray.text.scene-files : Character number lookup dict - chr.inc Server Time
2 Mar 2024 14:57:01 EST (-0500)
  Character number lookup dict - chr.inc (Message 1 to 3 of 3)  
From: ingo
Subject: Character number lookup dict - chr.inc
Date: 6 Jun 2023 05:45:00
Message: <web.647eff05744ea817bac71e8ffb8ce3@news.povray.org>
A scene file I just added to my tool box directory.

As the #switch #case only compares floats and not strings I always have to
figure out what character is what number. To scratch that itch a little scene
that writes an include file for the 'reverse look up' of the chr function using
a dictionary. It covers the ascii chars 34 to 127 as I don't know how to use a
'bell' as key.


---%<------%<------%<---

// Persistence of Vision Ray Tracer Scene / Include File
// File: chars.pov
// Vers: 3.8
//
// Desc: A scenefile to create an include file with a dictionary to look up
// the ascii numbers for characters.
// Author: Ingo Janssen
// Date: 2023-06-06

#version 3.8;

global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }}

#fopen CHR "chr.inc" write
#write (CHR "#version 3.8;\n
#ifndef(chr_Inc_Temp)
  #declare chr_Inc_Temp = version;
  #ifdef(View_POV_Include_Stack)
    #debug \"including chr.inc\"
  #end\n\n"
)
#write (CHR "#declare Chr = dictionary {\n")
#for (i, 34, 127)
  #if (chr(i) = "\"" | chr(i) = "\\")
  #write (CHR concat("[\"\\", chr(i),"\"] : ", str(i,0,0),"\n"))
  #else
    #write (CHR concat("[\"", chr(i),"\"] : ", str(i,0,0),"\n"))
  #end
#end
#write (CHR "};\n\n")
#write (CHR " #version chr_Inc_Temp;
#end")
#fclose CHR

#include "chr.inc"
#debug concat(str(Chr["\""], 0, 0), "\n")  // The " has to be escaped
#debug concat(str(Chr["\\"], 0, 0), "\n")  // the \ has to be escaped
#debug concat(str(Chr["F"], 0, 0), "\n")
#debug concat(str(Chr["&"], 0, 0), "\n")


---%<------%<------%<---


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Character number lookup dict - chr.inc
Date: 6 Jun 2023 12:45:00
Message: <web.647f61fb1f4d89424a345f4489db30a9@news.povray.org>
"ingo" <nomail@nomail> wrote:
> A scene file I just added to my tool box directory.
>
> As the #switch #case only compares floats and not strings I always have to
> figure out what character is what number. To scratch that itch a little scene
> that writes an include file for the 'reverse look up' of the chr function using
> a dictionary. It covers the ascii chars 34 to 127 as I don't know how to use a
> 'bell' as key.

Can you not use asc() for this ?`

http://www.povray.org/documentation/view/3.7.1/228/

You can use chr(7) to quote the ASCII bell character.

https://www.povray.org/documentation/view/3.7.2/232/

This code outputs 7

#version 3.7;
global_settings { assumed_gamma 1.0 }
#debug "\n"
#debug str(asc(chr(7)), 0, 0)
#debug "\n"
#error ""

Perhaps chr(7) can also be used as a key in a v3.8 dictionary (?)

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: ingo
Subject: Re: Character number lookup dict - chr.inc
Date: 6 Jun 2023 13:20:00
Message: <web.647f69e61f4d894217bac71e8ffb8ce3@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:

>
> Can you not use asc() for this ?`
>

Oh.

Must have a blind spot.

Must have been there for years. :(


Thanks,

ingo


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.