text
stringlengths
0
897
// Helper function to wait for a click. Also watches
// for the Escape key, and if pressed, exits the program.
waitForClick = function()
// wait for mouse down, or escape key
while not mouse.button
if key.pressed("escape") then exit
yield
end while
// wait for mouse up
while mouse.button; yield; end while
end function
// Prepare six snowflakes.
flakes = []
for i in range(0,5)
flakes.push Snowflake.newRandom
end for
// Main loop.
while true
// Draw our current six snowflakes.
clear
for i in range(0,5)
col = i % 3
row = floor(i/3)
flakes[i].draw 160 + col * 320, 160 + row*320
end for
// Wait for a click, and figure out which flake was hit.
waitForClick
col = floor(mouse.x / 320)
row = floor(mouse.y / 320)
choice = row * 3 + col
// Replace all the other flakes with new ones.
for i in range(0, 5)
if i != choice then
// create either a mutant of the chosen one,
// or occasionally, a completely new one
if rnd < 0.8 then
flakes[i] = flakes[choice].cloneAndMutate
else
flakes[i] = Snowflake.newRandom
end if
end if
end for
end while
```
Before you call it a day, take some time to play with this program! It's really fun trying to "breed" the perfect snowflake, guiding their evolution with judicious clicks of the mouse. But don't be shy about hitting Escape and running again to get a fresh new batch of snowflakes to start from.
A> **Chapter Review**
A> - You developed an algorithm for drawing a snowflake, by recursively drawing the same (or similar) things at progressively smaller scales.
A> - You implemented that algorithm first in a small program that draws a snowflake.
A> - You elaborated that into a more sophisticated program that demonstrates cloning and mutation.
{chapterHead: "Day 29: Finding Help", startingPageNum:359}
{width: "50%"}
![](Chapter29.svg)
Q> Don’t be afraid to say "I don’t know" or "I don’t understand" – no question is a dumb question.
Q>— Margaret Hamilton (software engineering pioneer)
A> **Chapter Objectives**
A> - Learn where to look for programming help on the Internet.
A> - Explore some places where you can join a community and share your work.
A> - Learn some common ways programmers find solutions to problems.
I hope you've found this book fun and easy to follow. If you're like many readers, you began with little or no programming experience, and now you've completed an entire book, entered and debugged a large number of programs, and learned MiniScript syntax as well as most of the Mini Micro classes and functions.
Despite the considerable increase in your programming prowess, you may still find it difficult when you sit down to write a program from scratch. You may experience a form of "writer's block" where you don't even know how to begin. Or you may get partway through a project, and then run into some bug you don't know ho...
In this chapter we'll go over some places to get help at times like those. We'll also cover some communities you can join and participate in even when you don't need help — for example, when you've just coded something cool and want to share it with people who will appreciate it. The MiniScript community is friendly ...
Q> The Internet? Is that thing still around?
Q>— Homer Simpson
## Official MiniScript Sites
From the very beginning of the book, I've encouraged you to make use of the resources linked from the MiniScript home page. But it's worth suggesting these again.
MiniScript home page
: <https://miniscript.org>
This web site is the first step for all things related to MiniScript and Mini Micro. Other sites may come and go, or change their web address, but this one should always be valid and up to date.
From here you can find links to most of the other places mentioned in this chapter. You'll also find very helpful resources like the MiniScript Quick Reference.
One of these resources is the **MiniScript User's Manual**, a downloadable reference book that explains the MiniScript language and its intrinsic functions in good detail. I wouldn't recommend this book to someone who is entirely new to programming. But you're not new to programming any more! You will be able to und...
You'll also find an invitation link for the **MiniScript Discord server** here. Discord is a popular real-time chat program. People here communicate mostly by text, though you can also post pictures of your projects, and a voice channel is available when needed. Text channels are divided into topics, including `#min...
MiniScript wiki
: <https://miniscript.org/wiki/>
The MiniScript wiki is a very useful reference site. Continually updated and extended by volunteers (including myself), this wiki has a page for just about every language feature and function in MiniScript and Mini Micro. Let's say you are wondering if there is some way to hide the mouse cursor in Mini Micro. Just g...