text stringlengths 0 897 |
|---|
{pageBreak} |
The layers are numbered from 0 to 7, and stacked up with 0 in the front, and 7 in the back. Display layers that are off, or have any transparent areas, let you see through to the next layer behind it, and so on all the way to the back. (If all layers are off or see-through, the screen appears black.) |
When you start up Mini Micro, or use the `clear` command, the display layers are set up like this: |
{width:"75%"} |
 |
So in the standard configuration, displays 0, 1, and 2 are off; 3 is text; 4 is sprites (which we'll learn about in a few days); 5 is pixel graphics; 6 is off; and 7 is a solid color (black). You might have noticed yesterday that when you have overlapping pixel graphics and text on the screen, the text appears on top ... |
But this is only the default configuration; as a programmer, you can change this however you like! The eight display layers can be set to any configuration, including multiple displays of the same type if desired. Let's prove it! Try this: |
{caption:"Filling all 8 displays with random text."} |
```miniscript |
for layer in range(7, 0) |
// set the layer to text mode, with a random text color |
display(layer).mode = displayMode.text |
display(layer).color = rgb(255*rnd, 255*rnd, 255*rnd) |
display(layer).clear |
// fill it with random characters |
for row in range(0,25) |
for col in range(0,67) |
c = char(32 + rnd*64) |
display(layer).setCell col, row, c |
end for |
end for |
wait |
end for |
``` |
Run this, and it should make an absolute mess of your Mini Micro screen. Don't worry; entering `clear` will of course clean it up! Each of the eight layers is set to text mode, and then filled with random text. By the end, every text position on the screen contains eight overlapping characters. |
This program introduces several new things you can use in your own programs: |
- `displayMode`, which is a built-in map that lets you refer to the different display modes by name, for example `displayMode.text`, `displayMode.pixel`, and `displayMode.solidColor`. These simply map to the mode numbers (0-5) shown in the table on the previous page. |
- `display(num)`, a function that returns a reference to the display object for the given layer number (0-7). |
- `mode`, a property on every display class that controls what mode that layer is. |
So in the listing above, line 3 uses the `display` function to get a reference to one of the layers (using the `layer` variable from the `for` loop); and then it changes it to text mode by assigning `displayMode.text` to its `.mode` property. |
Let's use the REPL to do this step by step. Start by resetting your displays: |
```terminal |
]clear |
]text.color = color.orange |
``` |
After the `clear` call, display 3 is text and display 2 is off. Let's change display 2 so that it is *also* text, and print some overlapping text. |
```terminal |
]display(2).mode = displayMode.text |
``` |
As soon as you enter this line, all that random text that was created from the program before suddenly appears! The `clear` command turns display 2 off, but it does not actually clear the underlying text display. So we'll do that next, and then set the color, and print some dashes on line 10. |
```terminal |
]display(2).clear |
]display(2).color = color.green |
]display(2).row = 10; display(2).print "-----" |
``` |
Those dashes appear in display 2, which is in front of the default `text` display (3). So now let's print some text behind the dashes: |
```terminal |
]text.row = 10; text.print "DONE!" |
``` |
Below is a handy function to list what the current display types are. |
{caption:"Function to list the current mode of all eight display layers."} |
```miniscript |
dispDump = function() |
for layer in range(0,7) |
d = display(layer) |
print layer + ". " + displayMode.str(d.mode) |
end for |
end function |
dispDump |
``` |
This uses the `displayMode.str` function to convert a mode number back into a string (basically doing the same thing as `displayMode.indexOf` in this case). The `for` loop here has been wrapped in a function so that, once you've run this code, you can just call `dispDump` at any time to see how your displays are arran... |
Before we move on, let's create a couple of functions to do a fade-out or fade-in effect. This will work by setting the frontmost display (layer 0) to solid color, and then using a loop to gradually change that from clear to black or vice versa. This acts like a sort of stage curtain, covering or revealing the other ... |
{caption:"Display fade-out and fade-in functions."} |
{i:"fade out"} |
```miniscript |
// fade a black curtain from alpha0 to alpha1 |
// (where 0 means clear and 1 means solid black) |
// over `duration` seconds. |
fade = function(alpha0, alpha1, duration=1) |
// set the frontmost display to solid color |
display(0).mode = displayMode.solidColor |
t0 = time // note the time |
while true // loop until done |
t = (time - t0) / duration // fraction done |
if t > 1 then break // done when t > 1 |
a = alpha0 + (alpha1 - alpha0) * t |
display(0).color = color.rgba(0,0,0,a) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.