Continuing with my Wolfram Mathematica Trial Experience...
I watched and went through some more Mathematica introduction videos, read lots of Mathematica documentation and also going through the Wolfram Lab Online again a few times.
There are some major learning curves and Mathematica is a lot different from normal programming language. Sometimes there is a lot of interesting "shortcuts", say like: FindFaces[], WordCloud[].
Sometimes I got a little confused on how one can do iterations. Normally FOR LOOP concept is introduced early, but in Wolfram, because everything is EXPRESSIONS and ENTITY (like OBJECTS), sometimes it gets quite quirky.
Mind you I am still in the first impression and having to look at many tutorials. Lots of NEAT EXAMPLES from documentation, but sometimes I got lost.
I found Wolfram to be really awesome with LIST and generating list. It's almost too easy when it works visually. I cannot explain them with my own words yet, but there are 3 expression to keep being aware of when working with LIST:
- Table[]
- Map[]
- Apply[]
Table[] can quickly generate pair numbers, row and column tables of sequences.
For my Rainbow Text practice, I thought that Table has potential to quickly create the result I wanted, however, I am stuck with how to break and iterate over STRING.
(You see above how "colors" can just be stated like that? The power of Entity in Wolfram.)
There is this Characters[] expression that can break Text String into List of Characters. However, unlike in Python, I cannot think of FOR LOOP setup in Wolfram. Maybe it is different?
for every character in text blah:
character.color = ???
character.size = ???
I tried all kinds of combination and probably missing something here.
Although Style[] itself can easily output Text with custom Size, Color, and Character/Text like above. However, how to break into character?
RAINBOW TEXT
Really I think it should not be too hard, but it requires some Wolfram kind of thinking. There must a very elegant syntax expression way to get what I want, but for now I will go the hard way.I realized I can do this below (the Row[] is just so that we can see the Text Output without bracket and commas):
Cool, now knowing the above, we can probably prepare the data generator to pair those 3 required values {text character, text size, and color}.
Below, I even found out about Transpose[] expression by accident. This could be very useful in many cases. Although I wonder if this is expensive to calculate and generate in Wolfram? Because at some point I can see the RAM usage goes up the roof more than 13GB? Or maybe it was a bug.
Anyway, the idea is to generate the values needed to be applied to multiple list.
- Prepare a string to be made into Rainbow Colored Text output
- Break the TEXT STRING into CHARACTERS, be aware about the total character numbers
- Now, I generate the numbers (it's going up from 0 to 1 in HUE, easy actually)
- Then I generate random size numbers list.
- Combine everything and using Style[] we got the job done.
I guess this is interesting exercise.
I don't know, maybe it is discussed or mentioned in the documentation somewhere, but digging Mathematica and Wolfram Language is interesting.
I wish I can ask mentor, but well, part of self learning is to keep searching for answer. Maybe ask at Mathematica Stack Overflow or check at Mathematica or Wolfram forum out there?
SMALL TRICK I LEARN...
Lots of cool things can be done just by using a single liner expression in Wolfram. I believe Mathematica is one language that introduces this "Notebook" workflow that combines users own regular text with code together. Don't know it's probably iPython first.
I found out that we can right click and copy a cell line (that weird line on the right side. Instead of having to highlight.
Beginner programmers that are using Python and Jupyter Notebook may be shocked a bit when they normally work in single liner and then having to switch to multi lines and using Variables. Warn you.
What's cool is once we have a working program, we could combine all the expressions, variables, and functions all into one. Using semicolons (;) actually allows user to keep variable without having to output the result until the last line.
So far though, I believe I have been doing Procedural Programming. Still basic, however it gives an interesting output.
And one thing I really like with Wolfram is how instant and visual the data feels like.
The range that SoundNote[] can take is limited, so that's something to keep in mind. But something like below seems to work okey.
mytext = "Awesome"
EmitSound[
Sound[SoundNote /@ Flatten[RealDigits[ToCharacterCode[mytext], 50]],
4]]
Print[Flatten[RealDigits[ToCharacterCode[mytext], 50]]]
SOMETHING CRAZY
In Wolfram Language, sometimes making everything as numbers and trying to visualize the output in all kind of ways, is almost pushed. Being crazy and try things are much recommended.
Below, I tried visualizing the Character Code (sometimes called ASCII) of my text, and turn it into Wolfram sound output as well.
The range that SoundNote[] can take is limited, so that's something to keep in mind. But something like below seems to work okey.
mytext = "Awesome"
EmitSound[
Sound[SoundNote /@ Flatten[RealDigits[ToCharacterCode[mytext], 50]],
4]]
Print[Flatten[RealDigits[ToCharacterCode[mytext], 50]]]
Comments
Post a Comment