text stringlengths 0 897 |
|---|
Green on black is nice, but what if we reduced the contrast a bit more by coloring the background? |
```terminal |
]text.backColor = color.navy |
]dir |
``` |
Notice that we assigned to `text.backColor` here rather than `text.color`. You might have also noticed that changing this only changes the background color of subsequent printing, not text already printed, or areas that are not printed over in some way. To clear the whole screen to your new text colors, just enter `c... |
PRINT>Take a few moments now to explore other color schemes. Are there any you particularly like? The figure below shows what my screen looked like after messing around for a while (at least, as well as we can show it in a black and white book). |
EBOOK>Take a few moments now to explore other color schemes. Are there any you particularly like? The figure below shows what my screen looked like after messing around for a while (though if you're reading this on a monochrome ebook reader, you will have to use some imagination). |
{width:"80%"} |
 |
In addition to the 20 standard colors, the `color` module contains a couple of helper functions. One is the `color.rgb` function, which constructs a color given numeric values for red, green, and blue in the range 0 to 255. |
```terminal |
]text.color = rgb(255, 200, 100) |
``` |
There's also a `color.rgba` function that does the same, but takes an alpha value, also in the range 0-255. An alpha of 0 makes a color that is invisible because it is completely transparent; an alpha of 255 is fully opaque (non-transparent). Intermediate values make colors that are translucent, i.e., you can see thr... |
{i:"`lerp`;linear interpolation;`color.lerp`"} |
The last color function we're going to talk about is `color.lerp`. "Lerp" is a computer term that comes from "linear interpolate," which is just a fancy way to describe the mixing of two values. `color.lerp` takes three parameters: *colorA*, *colorB*, and *t*, which is the interpolation value from 0 to 1. The resul... |
A couple of examples will clear it up. Suppose that `a` and `b` are colors. Then `color.lerp(a, b, 0)` returns exactly the same thing as `a`. We've gone 0% of the way from color `a` to color `b`. If we did `color.lerp(a, b, 0.5)`, then we'd get a color exactly halfway between `a` and `b`. And of course `color.lerp... |
We can use this to generate a bunch of colors in between two others in a loop. Try this: |
```terminal |
]for t in range(0, 1, 0.05) |
...]text.backColor = color.lerp(color.red, color.blue, t) |
...]print " " |
...]end for |
``` |
PRINT>Here we've made a simple `for` loop that goes from 0 to 1 in increments of 0.05, and then use that value to lerp between red and blue. For each one, we set the text background color and print and handful of spaces so we can see it. (I can't effectively show the result in a black and white book, so please try it... |
EBOOK>Here we've made a simple `for` loop that goes from 0 to 1 in increments of 0.05, and then use that value to lerp between red and blue. For each one, we set the text background color and print and handful of spaces so we can see it. (Words can't do this justice; please try it!) |
There's one more trick you should know about colors, and that is the color picker in the Mini Micro code editor. Enter `edit` to launch the editor, type `text.color =`, and then pause. Use the mouse to click on the code wizard button, which looks like a magic wand glowing above a little document icon. A menu should ... |
 |
Here you can adjust the red, green, blue, and alpha values by using the sliders or by typing in values. You can also select one of the standard colors by clicking on the little color boxes below. A large color preview is shown against a checkered background, so you can see what effect the alpha channel has. Once you... |
## The Text Display |
So far we've just been using `print` and `input` to manipulate the text on the display, just like a terminal or even the Try-It! web page. You may have also caught `clear` for clearing the screen. Now we're going to learn some more advanced ways to put text on the Mini Micro screen. |
The Mini Micro text display uses a friendly, monospaced font arranged in a grid of 26 rows by 68 columns. Columns are numbered starting on the left, and like many things in computers, they begin at 0 with the leftmost column. The rightmost column is column 67. Rows start at the bottom of the screen with 0, and proce... |
 |
In terms of pixels, each cell is 16 pixels wide and 24 pixels tall, but they overlap horizontally by 2 pixels. So effectively, you can think of the text cells as 14 by 24 pixels in size. (You don't really need to worry about pixel coordinates yet, but we will start thinking about such things soon when we get into pix... |
The text display has the concept of a cursor, which is where any printing goes. You've seen this already: it's the blinking block that shows you where you can type. But the cursor is only visible when it's waiting for input. At other times, it's invisible, but it's still there — and the output of any `print` stateme... |
```miniscript |
for row in range(20, 5) |
text.row = row |
text.column = 10 + row*2 |
print "Hello world!" |
end for |
``` |
You already used `text.color` and `text.backColor` in the previous section, and now you've done something similar with `row` and `column`. As you've surely noticed, there is a `text` module much like the `key` module. It's actually *slightly* different, because Mini Micro can have not just one, but up to eight differ... |
{i:"Mini Micro, `text` module;`text` module;text properties" |
{caption:"Properties that can be read or assigned to in the `text` module."} |
| `text.color` | foreground (text) color of subsequent printing | |
| `text.backColor` | background color of subsequent printing | |
| `text.column` | cursor column (0-67) | |
| `text.row` | cursor row (0-25) | |
| `text.inverse` | boolean: when true, foreground and background colors are swapped | |
| `text.delimiter` | string to follow the text of every `print`; by default, `char(13)` | |
PRINT>Some of that functionality is in the form of properties you can both read, and assign new values to, like we did with `text.row` and `text.column` above. The full set of these text properties is shown in the table on the previous page. |
EBOOK>Some of that functionality is in the form of properties you can both read, and assign new values to, like we did with `text.row` and `text.column` above. The full set of these text properties is shown in the table above. |
But the `text` module also contains functions, like the `key` module did yesterday. You never assign new values to these; you just call them and pass in any parameters they need. Here is the list of those functions. |
{caption:"Functions in the `text` module.", colWidths:"150,*"} |
| `text.clear` | clear the display using the current foreground and background colors | |
| `text.cell(x, y)` | get the character displayed at column *x*, row *y* | |
| `text.setCell x, y, s` | set the character displayed at column *x*, row *y* to *s* | |
| `text.cellColor(x, y)` | get the foreground character at column *x*, row *y* | |
| `text.setCellColor x, y, c` | set the foreground color at column *x*, row *y* to *c* | |
| `text.cellBackColor(x, y)` | get the background character at column *x*, row *y* | |
| `text.setCellBackColor x, y, c` | set the background color at column *x*, row *y* to *c* | |
| `text.print s` | print *s* to this display starting at `text.column`, `text.row` | |
As usual, you should not try to memorize these! Just skim them so you have some idea of what's available, and then look them up (here, or on the Mini Micro Cheat Sheet) when you need them. |
{i:"`text.inverse`"} |
The `text.inverse` property is a switch that causes the foreground and background colors to be swapped on subsequent output. Try it: just enter `text.inverse = true` at the Mini Micro prompt. Maybe follow it with `dir`, or `print` something, so you can really see the effect. Do `text.inverse = false` to turn it back... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.