Full Learn JavaScript With p5.js: Coding For Visual Learners Arslan Ebook All Chapters
Full Learn JavaScript With p5.js: Coding For Visual Learners Arslan Ebook All Chapters
com
https://textbookfull.com/product/learn-javascript-
with-p5-js-coding-for-visual-learners-arslan/
https://textbookfull.com/product/getting-started-with-p5-js-making-
interactive-graphics-in-javascript-and-processing-1st-edition-lauren-
mccarthy/
textbookfull.com
https://textbookfull.com/product/full-stack-javascript-learn-backbone-
js-node-js-and-mongodb-mardan-azat/
textbookfull.com
https://textbookfull.com/product/the-handbook-of-media-education-
research-1st-edition-stuart-r-poyntz/
textbookfull.com
The Primitivist Theory of Truth Jamin Asay
https://textbookfull.com/product/the-primitivist-theory-of-truth-
jamin-asay/
textbookfull.com
https://textbookfull.com/product/his-scarred-woman-1st-edition-sam-
crescent/
textbookfull.com
https://textbookfull.com/product/professions-and-metaphors-
understanding-professions-in-society-andreas-liljegren/
textbookfull.com
https://textbookfull.com/product/chinese-history-and-culture-sixth-
century-b-c-e-to-seventeenth-century-volume-1-yingshi-yu/
textbookfull.com
https://textbookfull.com/product/articulations-of-capital-global-
production-networks-and-regional-transformations-1st-edition-john-
pickles/
textbookfull.com
Adaptive Sports Medicine A Clinical Guide Arthur Jason De
Luigi (Ed.)
https://textbookfull.com/product/adaptive-sports-medicine-a-clinical-
guide-arthur-jason-de-luigi-ed/
textbookfull.com
Learn JavaScript
with p5.js
Coding for Visual Learners
—
Engin Arslan
Learn JavaScript
with p5.js
Coding for Visual Learners
Engin Arslan
Learn JavaScript with p5.js: Coding for Visual Learners
Engin Arslan
Toronto, Ontario, Canada
Chapter 1: Introduction������������������������������������������������������������������������1
Why Learn Coding?�����������������������������������������������������������������������������������������������1
Coding vs. Programming���������������������������������������������������������������������������������������2
On HTML and CSS�������������������������������������������������������������������������������������������������3
Why Learn JavaScript?�����������������������������������������������������������������������������������������4
Why Do We Have Different Languages?����������������������������������������������������������������6
Learning JavaScript with p5.js�����������������������������������������������������������������������������8
iii
Table of Contents
Summary������������������������������������������������������������������������������������������������������������42
Practice���������������������������������������������������������������������������������������������������������������42
Chapter 7: Loops���������������������������������������������������������������������������������85
For Loop��������������������������������������������������������������������������������������������������������������85
Random and Noise Functions�����������������������������������������������������������������������������92
Summary������������������������������������������������������������������������������������������������������������99
Practice�������������������������������������������������������������������������������������������������������������100
iv
Table of Contents
Chapter 8: Functions������������������������������������������������������������������������101
Creating Functions��������������������������������������������������������������������������������������������101
Revisiting Setup and Draw Functions���������������������������������������������������������������107
Summary����������������������������������������������������������������������������������������������������������108
Practice�������������������������������������������������������������������������������������������������������������108
Chapter 9: Objects����������������������������������������������������������������������������109
Using Object Initializer��������������������������������������������������������������������������������������109
Using the Constructor Function������������������������������������������������������������������������117
Summary����������������������������������������������������������������������������������������������������������123
v
Table of Contents
Index�������������������������������������������������������������������������������������������������213
vi
About the Author
Engin Arslan is a Software Developer with a Bachelor of Science in
Materials Engineering and a Postgraduate Degree in Visual Effects. Before
becoming a Developer, he worked as a Visual Effects Artist / Technical
Director on films and TV shows including Resident Evil, Tron, Mama,
Pompeii, Vikings, and Strain. He received an Emmy nomination and won a
Canadian Screen Award for his achievements in Visual Effects. During his
time in VFX, he fell in love with Python and with programming in general.
As a result, he changed careers to be able to immerse himself completely
in software development. Engin currently works at a Toronto-based digital
services company, where he helps develop solutions in strategic problem
spaces using emerging technologies. He also works at Seneca College as
a part-time professor and creates online courses for Lynda/LinkedIn and
Pluralsight.
vii
About This Book
The emphasis of this book will be primarily on learning programming
using JavaScript and p5.js and secondarily in creating visuals. The main
focus is to teach you how to program so that you can choose to pursue
whatever field that you would like with your newly established skill set.
The skills that you will acquire from this book are highly transferrable and
can be used with whatever you choose to build: whether web applications,
programmable robots, or generative art. This means that I will provide
you with enough context so that you can build a strong foundation for
programming. But I also won’t hinder your momentum with irrelevant
technical or theoretical points. The aim is to build a strong but a minimum
viable knowledge to get you running with coding. This is the book that I
wished I had available when I was learning coding myself.
If you are an artist or a visual designer, this book is perfect for you as
you might find the examples we will be building to be directly relevant
to your work. If not, this is still a great book for learning programming as
the visual nature of the exercises will help you grasp the fundamentals
of programming more easily and let you build a strong foundation in a
shorter amount of time.
This book will present various JavaScript and p5.js features and
concepts in the following chapters. The knowledge will be reinforced
by building several useful examples like an animation and a data
visualization; and as a final project, we will be building a game that can be
deployed online using what we learned in this book!
ix
About This Book
x
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
CHAPTER 1
Introduction
At this age and time that we live in, coding is simply invaluable. It has
the power to uplift your career, your future prospects, and even your
intellectual capacity. Computation is driving one of the largest capital
expansions in history, and there has never been a better time to learn
coding than now.
2
Chapter 1 Introduction
3
Chapter 1 Introduction
4
Chapter 1 Introduction
main()
{
cout << "Hello World!" << endl;
return 0;
}
5
Chapter 1 Introduction
class HelloWorld {
static public void main( String args[] ) {
System.out.println( "Hello World!" );
}
}
console.log('Hello World');
• is easier to write;
6
Chapter 1 Introduction
your programs. Others can be much more concise but could be slower to
execute. Some languages are better suited for certain tasks. JavaScript is
perfect for full stack web development, Matlab is great for mathematical
calculations, C++ has dominance in game programming, and Julia is used
for data science. This doesn’t mean you can’t be using other languages
in these domains, though. Unity Game Engine offers C# for game
development. Python can be preferred for data science. And GoLang or
many other languages could be used for back-end web development. It
sometimes boils down to what the developers prefer to use and what they
already know. And sometimes it comes down to the constraints of a given
project.
I used to work in the visual effects industry and the software packages
that we would be using in the field could be automated using Python or
C++. So those were great language choices for that domain given that’s
what the tools that we were using were supporting. Knowing Java in visual
effects would have been largely useless except for the fact that knowing a
programming language actually makes it more likely that you will be able to
pick up another language as they share similar principles among each other.
Choosing which language to learn as your first can sometimes be a
tough choice as there are lots of viable options out there. Sometimes the
choice is dictated by the application domain. If you are seeking to build
a game using the Unreal Engine maybe you should just learn C++. But
then again if it’s your first time interfacing with a programming language,
you might be faced with such a steep learning curve that it might be
discouraging.
JavaScript stands to be a great choice to learn as your first
programming language. As mentioned earlier, it is widely used and has a
vast application domain that would allow you to experiment with lots of
different applications. It has a big and active community behind it and also
has a very concise syntax that makes it closer to human languages.
7
Chapter 1 Introduction
8
Chapter 1 Introduction
• Faker.js (https://github.com/Marak/Faker.js):
Generate massive amounts of fake data.
• jimp (https://github.com/oliver-moran/jimp): An
image processing library.
9
Chapter 1 Introduction
thousands. Since p5.js was built with simplicity in mind, sometimes small
p5.js programs are referred to as sketches. Even though that’s a clever
way to describe it, I am personally not a huge fan of that wording since it
obfuscates the fact that what you are doing is programming after all.
You can find pragmatic applications of p5.js such as creating data
visualizations (Figure 1-1).
10
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Chapter 1 Introduction
11
CHAPTER 2
Getting Started
I nstalling p5.js
There are a couple of ways you can start using p5.js and JavaScript. One
option is to visit the p5.js website (https://p5js.org/download) and
download the p5.js source code on to your system (see Figure 2-1).
At the time of the writing of this walkthrough, the download page has a
link called ‘p5.js complete’ that includes the p5.js library and an example
project. Download this archive file and find the folder named empty-
example inside it. In this folder, you will find two files: the sketch.js
file where you can write JavaScript code and an index.html file that can
be launched with a web browser such as Chrome and would execute and
display the result of the JavaScript code inside sketch.js file. You can also
find a copy of these files on my GitHub repository: https://github.com/
hibernationTheory/p5js-complete.
Even though you can change the contents of sketch.js JavaScript file
with a plain text editor like NotePad, you might instead want to use a code
editor such as `Sublime Text` to do so.
A code editor is pretty similar to a text editor, like Notepad or Word, but
it has special features that make coding much easier such as highlighting
of special words for a given programming language, which in this case
that language is JavaScript. Sublime Text is a code editor that you can use,
which can be downloaded and evaluated for free.
Perhaps the easiest way to get started with p5.js is to use an online
editor. An online code editor can be used inside the web browser and
doesn’t require you to install anything on your system. It is my preferred
way of working when I am learning as it makes it really easy to get started.
An easy-to-use Online Code Editor that is available at the time of the
preparation of this book can be found at this link:
[p5.js online editor - alpha](https://alpha.editor.p5js.org/)
If the above link is not accessible for any reason, you can also try the
p5.js template that is hosted on my Codepen account:
[Codepen - p5.js simple template](https://codepen.io/
enginarslan/pen/qpBBXz?editors=0011). CodePen (https://codepen.
io) is a social development platform that allows you to write code in
the browser and share your work with other developers. It is a great
environment for development and experimentation. The difference
between Codepen and the p5.js editor that is mentioned above is that the
p5.js editor only allows you to run p5.js related code inside itself whereas
Codepen can execute any front-end code.
14
Chapter 2 Getting Started
How the online editor works is that, whenever we have some code
ready to be executed, we will press the play button at the top of the page.
This play button will show the results of our code on the right-hand
side panel. The online editor of Codepen is slightly different in that it
automatically executes the code any time you change it. Pressing the Play
button at this point wouldn’t do much as we didn’t write any code that
draws shapes to the screen. We will just see an empty screen get generated.
But as we can see, this editor has some code already written into it. This
code that we see is needed for almost all the p5.js programs that we will be
writing so it is included here for our convenience (Listing 2-1).
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
}
Let’s just delete this code for now. Before we start using p5.js to learn
JavaScript, we will see a couple of things on the fundamentals of JavaScript.
You can find the code examples that we will be using throughout this
book at the GitHub repository: https://github.com/hibernationTheory/
coding-for-visual-learners.
16
Random documents with unrelated
content Scribd suggests to you:
CHAPTER XVII
IN THE BRÛLÊ
That was a very beautiful camp and a merry night, that last night with the
cowboys from Rosebud. The fire they had made was what they called a nor'-
wester. Timber was plentiful—to be had, indeed, for the felling—and the
men left in camp had found it better fun to swing an axe than to do nothing.
So whole trees lay across the fire, and huge tongues of flame kept leaping
out and shooting into the darkness. Every now and then a log broke, and the
ends fell in with a crash, the flames roared more fiercely than ever, and a
shower of red sparks went away on the wind.
The men left in camp, being in a luxurious mood and having lots of time
on their hands, had run up a shelter of boughs—two great props and a
crosspiece, with a lot of underbrush sloping from this ridge-pole to the
ground. Under this, with their feet to the fire, lay the men smoking.
'Wal, Dick,' said the Judge, 'I reckon I don't owe you no grudge. You've
been a good pal to us, and I hope, mate, you'll strike it rich where you're a-
goin'.'
'Thank you, Texan, old chap,' laughed Snap. 'If you don't do any more
mining amongst those gopher-holes before I come back, I'll bet you my best
saddle that the Cradle and I lick your head off at any distance you like on old
"Springheels."
The laugh, for a moment, went against Texan, for in the round-up just
over it was commonly stated as a fact that, whilst riding at full pace down a
hill after cattle, his pony had put its foot in one gopher-hole and shot its
owner into another, from which, five minutes later, he was extracted by a
comrade, who said that he had found Texan 'growing anyhow, just planted
root up'ards in a gopher-hole!'
'There's one thing agin you, Dick, and that's the weather,' remarked the
Judge; 'for all it's so fine now, I don't half like that fringe round the moon.'
'No, it does look watery, doesn't it?' said old Dick, looking up; 'but, hang
it all, don't let us croak. Hand me another of those fish, Snap, if you can
spare one. Bust me! if you don't eat half-pound trout as if they was shrimps,'
he added.
'There's summat I'm thinking,' said Texan after a pause, 'that's worse nor
weather. I don't want to croak, Dick, but air you sure about them Injuns? I
kem acrost their fishing-camp to-day, and there isn't a soul in it. Do you
calculate as they're on the war-path?'
'Not they!' replied Dick; 'a Crow won't face a Blackfoot nowadays, and,
unless they're stealing horses or killing cattle, they aren't doing any harm,
you bet.'
'How!'
It was a sound between a human voice and a dog's bark, sharp, hoarse,
and guttural, and it appeared to proceed from the ground under Snap's seat.
Snap was round as if a wasp had stung him. There had been no sound behind
the camp-fire; no dry twig had cracked, no leaf rustled; and yet there was
this sudden 'How!' and behind Snap stood, stiff and silent, a tall, grim-
looking Redskin.
A sort of pointed hat of rush was on his head, through the band of which
an eagle's plume had been stuck; round his shoulders was a bright-coloured
blanket, and wide trousers of deer-skin, with long fringes of the same down
the seams, reached to his ankles.
'Not a beauty,' Snap thought, and he moved a little uneasily away from
the stranger, who stood quietly staring at the group.
The Indian was certainly not a beauty, even for an Indian. His hair was
sleek and black—'snaky' Towzer called it. His eyes were small and set close
together in a big bull-like head, and he was hare-lipped. His face, too, was
full of lines and wrinkles. He was as old as the hills apparently, but old as the
oaks grow old—strong and rugged, and nowhere near being worn out.
'How!' said Dick, and he rose and gave the chief his hand, and offered
him a seat on his blanket, which he took.
'Do you speak English?' asked Snap as the Indian sat beside him, but the
only answer he got was a stony stare.
'I guess he does, for all that,' whispered Texan; 'these beggars never let on
how much they know. Say, Dick, you talk their lingo; ask him where he
comes from.'
So adjured, old Dick Wharton supplied his guest with fish, bread, and tea,
all of which he took without a word, and then Dick began to question him.
The Indians had broken up their fishing-camp, the Redskin said; their
medicine-man had advised them to. Oh, yes, it was a good season, and there
were lots of fish there yet, but the medicine-man had seen a bird, and the
tribe could not stay any longer.
'Seen a bird!' cried old Wharton; 'well, I reckon he sees a good many
birds in a day; but what kind of a bird was this to frighten the whole tribe
from fishing and gambling?'
'The tribe was not frightened, O white-skin,' replied the Indian with
dignity; 'but they knew that the bird which Teeveevex saw was the bird of
doom, which preys on the tribes of men, and the Crows have hidden until the
danger is passed.'
'Only Teeveevex has seen it,' replied the chief, 'but its white wings are as
the clouds which contain the rain-storms, and it rushes through the sky like a
star falling from its throne.'
'What is the name by which the braves call you?' asked Wharton.
'The men call me the Great White Rabbit,' replied the chief proudly.
The Indian could not have understood what was meant, but he saw the
smile, and gave Frank one of his ugly looks.
'Ask him how old he is,' said Snap, and Wharton repeated the question.
The chief thought for a moment, and then held up five fingers solemnly.
'Oh, you be hanged!' cried Towzer. 'Why, the beggar's laughing at us. A
nice, tender, five-year-old you are, aren't you, my beauty?' And the boys
laughed in concert.
'He is right enough, though,' said Wharton; 'with these chaps each finger
stands for ten, and I don't suppose that he is more than fifty.'
After eating everything which the whites had left, and begging for a
charge or two of powder, the cowboys' visitor got up and left without a word
either of thanks or adieu.
'Well,' said Towzer, 'that twopence which I presume our friend's mamma,
Mrs. Doe Rabbit, spent on her son's manners doesn't appear to have been a
good investment.'
'Lord bless you, you don't expect thanks from an Injun, do you?'
remarked Wharton; 'like enough that chap will put a ball in you if he gets a
chance, and I should be very much surprised if either of your grizzlies has its
hide on to-morrow. If it has, old Buck Rabbit, or whatever he calls himself,
won't be to blame, you bet!'
And sure enough, when Snap and Texan went up next morn (rather late, it
is true), both bear-skins had gone, and the place, so Texan said, 'stunk of
Injuns.'
When Snap and Texan got back without their bear-skins old Wharton had
the ponies packed, and 'the Judge' had made all preparations for a start.
'So Buck Rabbit got those skins, did he?' asked Wharton. 'Well, I'll
forgive him, whatever Snap says, if that's all the hair he raises this fall.'
'Yes, you may say that,' Texan added grimly. 'I've been here some while
now, but I never knowed those Crows give up their summer gamble, and
bust me if I think they'll feel inclined to lie idle now that they have been
skeered out of their fishing-camp.'
'That being so,' said Dick, 'it seems to me you mout as well lead them off
our trail a bit. Don't let them sight you between this and Rosebud, and
maybe, if Buck Rabbit didn't count the horses, he'll think, when he sees the
trail of all them ponies, that we've all gone back to Rosebud.'
'Oh, I reckon Rosebud can look after itself, leastways it could when I was
theer,' replied the old foreman; and Texan and the Judge nodded approvingly,
and murmured with emphasis 'You bet!'
'Well, we'll do our possible,' replied Wharton, busy with the Cradle's lash-
rope; 'if we don't turn up you'll understand that we're wiped out, and "the
boys" can divide my band amongst 'em.'
'The boys won't none of 'em hanker after their share of that band, Dick,'
replied Texan, shaking the old man's hand. 'Good luck to you!'
'So long!' cried the Judge. 'Keep your eyes skinned at night, pard!'
And with the bell of the leading pack-animal tinkling merrily the two
boys, and all the ponies save the Cradle and another, disappeared among the
trees on the back track.
Dick and the boys stood looking along the trail for some time after their
friends were out of sight. Now and again they could hear the bell or a cry
from Texan or the Judge to one of the self-willed ponies, but by degrees they
passed out of earshot as out of sight.
'I guess we'd better tramp,' said Dick, turning to the three young
Englishmen, over whom a certain sense of loneliness had been stealing.
For the first time they realised what this adventure meant. They saw now
that for the next four months at any rate they were entirely dependent upon
their own efforts for all the necessaries of life. They were only four men,
armed and strong, it is true, isolated among the great things of Nature—
mountains and forests, and by-and-by ice and snow and tempest—and cut
off from railways and the civilised world, and bound to die if they could not
find food and make shelter for themselves. Old Dick, used all his life to
depend on his own right hand for everything he wanted, probably only felt a
bit of a wrench at parting from his old comrades and saying good-bye to his
old position of foreman.
The boys felt a good deal more than that. Those two rough-riders, driving
their string of pack ponies before them, were to them the world, or at any
rate their last glimpse of it.
'You had better lead "the Cradle," Snap,' cried Wharton, 'but I reckon
we'll all have to swim at the ford. Your friends can swim, I suppose?'
'Come on, then,' said the old man, and with a long, swinging stride the
four started on their hundred-mile walk.
All four were in mocassins, flannel shirts, and pants of blue jean. On their
heads they wore the usual cowboy hat, a wide light-coloured sombrero. Snap
carried his rifle, as the best shot of the party, but the others had tied their
rifles with their coats and blankets on the pack-animals' backs.
The river when they reached it was not as full as Wharton had expected,
still for a few paces in the middle horses and men had to swim.
As they stood shaking themselves on the further bank, Towzer looked
ruefully at his own draggled appearance and remarked:
'I believe I've got my stockings wet! Don't you think, Frank, mother
would like us to change them?'
There was a laugh among the boys, and then as they tramped through the
grimy, burnt forest, with its charred stumps and black, leafless branches,
their thoughts went back to Fairbury.
Well, it was a dream, and Snap an optimist and a bit of a poet, and
perhaps in nine cases out of ten such dreams only lead to disappointment;
but if you are prepared to meet with disappointment, a beautiful dream is no
bad thing to beguile a long march.
The country through which the boys were now travelling was as desolate
and uncanny as anything which the world can show. They were crossing a
belt of forest between the forks of a great stream, one arm of which they
crossed in the morning. Between the two streams a great fire had raged some
years ago, and range after range of rolling hills lay before them covered with
tall trees charred to a cinder, yet standing upright still—grey, unburied
skeletons of the past. In some places a tree which had once been nearly two
hundred feet in height still reared a great grey spire towards heaven, and yet
a few yards from the ground you could see that fire and weather between
them had eaten the trunk almost through, so that its balance alone seemed to
keep it upright. All through the brûlé, as this burnt forest is called, the trails
are blocked by fallen timber. At every breeze a score of them come crashing
down, and hardly a minute goes by without a snap like a rifle-shot to remind
you that it is merely by an interposition of Providence that each of the great
pines along your path has not fallen upon you as you passed. The difficulty
of getting pack animals through a forest of this kind is considerable,
although they will jump and crawl like cats; and the walking is weary work
even for the strongest man, where at one moment you have to balance along
the stem of a fallen pine, or climb over a log ten feet high, and the next have
your pants caught by the point of a sharp rampike which tears them to shreds
and perhaps takes a foot or two of skin with it.
'I am afraid Texan was right,' said Dick as they plodded along, while the
sun was setting slowly in the west, 'those clouds are coming up uncommon
fast, and it's main dark for three o'clock.'
Winthrop was leading 'the Cradle,' and Towzer was walking alongside of
him, and when Dick spoke he spoke to Snap, who had fallen a bit behind.
'Don't you agree, Snap?' he said after a pause, and as no answer came he
looked round.
'Hulloh! Why, where in thunder have you got to?' he cried. 'Here! hold on
there in front. Where's Snap?'
The boys pulled up and looked round. Not five minutes before they had
seen him; now, though they could see plainly amongst the grey, bare poles,
there was no sign of him.
'Snap! hi, Snap!' they cried; and faint and far away an echo seemed to say
'halloa.'
'Was that an answer?' said Dick; 'here, dang your skin, hold up there,' he
added, giving 'the Cradle' an angry dig in the ribs, to induce that animal to
stop pawing the ground and snorting.
'Now shout agin, Frank, and mebbe this brute will let us hear if he
answers.'
'Snap! halloa, halloa there, Snap!' cried Frank, and again from far away
came an answering halloa, very feeble and faint, but still recognisable as
Snap's voice.
'Yes, I reckon he is,' said Dick; 'I hope he ain't much hurt.'
'Not exactly, but if you'll give me thet lash-rope we'll, maybe, find him
pretty soon. It's lucky we missed him so soon,' he added.
Turning back, the old man walked along the trail, calling Snap by name
from time to time, the answer getting plainer as he advanced, but still
proceeding apparently from somewhere under their feet.
'Here he is,' remarked Wharton at last, 'and a pretty dark hole it is, too.
Are you hurt any, Snap?' he inquired, leaning over a log and looking down
on the other side.
'No, I'm all right,' said the voice, 'but I can't get out.'
'Lay hold of that,' replied Wharton, lowering the rope, 'and we'll pretty
soon haul you out.'
When the Winthrops came up this was what met their gaze. The whole
floor of the forest was composed of fallen trees and dead logs, in most cases
overgrown with moss and bushes, which in their turn had been burnt or
scorched. For centuries the trees had grown and fallen, rotted or refused to
rot, and over them the fresh forest had grown, until in many cases they
formed a solid soil of rotted wood and debris. Here and there, however,
where a few great trees had fallen and had not yet rotted, a thin crust, as it
were, of boughs and soil and debris had formed above, and through such a
crust as this Snap had tumbled into what Towzer called the basement of the
forest, a dark, damp, underground hollow, in which in places you could
travel upright for thirty or forty yards under a bridge of fallen timber. Out of
a place of this kind Snap was hauled, very black and grimy, and as hoarse as
a crow with shouting, but otherwise unhurt.
'We had better push on at once,' said Wharton as soon as he was sure that
his friend was unhurt. 'I don't like the look of the evening a bit, and should
be thankful if we could get under the lee of some big boulders I know of, a
few miles further on, before the storm breaks.'
'It does look bad, doesn't it?' said Frank; 'however, a little rain would do
no harm, as we shall not strike water to-night, and we all want a wash badly,
specially Snap.'
'If this storm catches us in the brûlé, we shan't want washing any more,'
was Dick's gloomy reply; and, though the sky—covered with long fleecy
storm-clouds, and full of an angry yellow light—did not look reassuring, the
boys all thought that for once Dick was taking an unnecessarily black view
of their chances.
The boys were still digesting Dick's last speech when there came a tiny
whisper through the trees. It was not anything more. Just a faint little wind
like a sigh; and yet three or four great trees, which had kept their balance for
years, came down before it with a crash which made even Dick's cheek
blanch.
'Caught, by thunder!' cried he. 'Boys, we've only one chance; leave them
ponies and follow me.'
IN THE BRÛLÊ
Not understanding the danger, the boys could not help seeing that it was
real, by the old man's manner, and the speed with which he darted back
along the trail. As he passed 'Cradle,' Snap noticed that that intelligent beast
turned of his own accord and followed his human companions. As they ran,
another faint wind came, and another half-dozen great trees thundered down,
and one of them right across the path between Dick and his friends. One of
its boughs flew up and struck Frank across the face, leaving a long black
mark and drawing a bright stream of blood.
For a moment the boys recoiled aghast; but Wharton's voice woke them
to a fresh effort.
'Run, run, tear and ages! will you run?' he shrieked, and one after another
the boys scrambled over the carcase of the great tree and reached Dick's
side.
Dick was on his knees beside the hole from which he had extricated
Snap. The good old fellow, though he knew the danger, meant to see
everyone else safe before he thought of himself.
'Here, young 'un,' he cried to Towzer, 'get hold of my fist. Now then,
down you go,' and he lowered the boy as far as he could into the hole.
'All right,' said Towzer's voice from somewhere beneath their feet.
'Now then, Frank,' said Dick; and one after another he let the boys down,
and a moment after dropped down amongst them.
'Great Scott! how it shakes the wind out of you,' he muttered, picking
himself up, 'I didn't know it was so far.'
Just then a peal of thunder drowned their voices, and after it came the rain
in torrents, driven by a perfect gale of wind. Even where the boys were the
rain came in bucketfuls, and the red lightning lit up their subterranean shelter
until they could see the black logs above their heads, like the gigantic beams
in some old English hall. But the loud thunder echoing amongst the cliffs
beyond the river, and the hissing rain, and every other sound was drowned
when the wind arose, for after the first rush of the wind it seemed as if the
end of the world had come, or as if, at the very least, some great battle like
Hohenlinden was being fought right over their heads. Tree after tree came
crashing to the ground and, as it fell, dragged down others with it. Now they
would fall one after another with loud reports as if a regiment of giants were
file-firing, and again a great wave of sound, a very volley of the heaviest
artillery, would make the ground rock with its awful roar.
'Thank God, we got here in time,' said old Dick reverently; 'I guess there
won't be a tree standing when this storm stops, and those poor wretched
ponies will be pounded small enough for sausage meat!'
'Do you think they can't escape, Dick?' asked Frank; 'our rifles won't be
good for much, then.'
'No,' replied Wharton, 'except, maybe, for old iron or chips to light a fire
with. By the way, who has the matches?'
'Haven't you, Snap?' asked Dick. 'What are you thinking of, boy?' Dick
added.
'No, I haven't a match, Dick. I was thinking what a cur I was to leave
poor old Cradle, and how piteous he looked as I passed him; but I had no
notion what I was leaving him to,' replied Snap sadly.
'Yes, it is a pity. He was a good horse, but there are plenty better, and,
besides, we hadn't a rope strong enough to lower him into this hole, even if
we had had time to try it; and then I'm not sure as he'd have let us do it,' said
Wharton; adding, after a while, 'I guess the storm is stopping, but it's a poor
camp we shall have to-night, without a fire.'
Before long the storm stopped; our friends down below could feel that the
air was fresh and sweet, and that the evening sun was shining brightly over
everything. By tying a little log on to the lash-rope and throwing it over one
of the beams which formed the roof of their shelter, our friends made
themselves a ladder, and one by one climbed up from the darkness to
daylight again.
CHAPTER XVIII
When they did so, what a change had taken place! An hour and a half ago
thousands of burnt trees, stretched upon all sides, blocked the view and
formed a forest of skeletons. Now every high head was levelled, every tall
grey spire laid low. Like a wheatfield beaten down in autumn lay the burnt
forest, but, unlike that, no sun could ever raise it up again. When years
should have passed and the dead trees returned to earth, another forest would
spring up where the pines had stood—not a forest of bright larch and tall
pines, but, oddly enough, a forest utterly alien to the one which had so long
covered the ground. Beech and birch, and maple or poplar, would grow
green in spring and shed their leaves in autumn where the winds once
whistled and the snows lay amongst the great evergreens.
As Snap looked at the levelled forest the words came somehow to his
lips, 'This is the Lord's doing; and it is marvellous in our eyes.' Lifting his
hat, he looked up to the bright sun, and even the grim old cowboy was not
ashamed to follow his example.
Picking their way with difficulty among the chaos of fallen trees, the
boys' ears were greeted by a low whinny.
'It's the Cradle, poor old chap!' cried Snap. 'Can it possibly be that he is
alive?'
'It's a pity if he is, my lad,' said old Wharton, 'for he'll only be calling you
to shoot him out of his pain. He's most sure to have a leg broke or his back
smashed.'
'But he hasn't, though, have you, old chap?' shouted Snap, who had
scrambled breathlessly over the logs to the spot from which his old horse
had called to him.
'But, Dick,' the boy added, 'how on earth are we ever going to get him out
of this?'
And he well might ask. 'The Cradle' couldn't stir, and no wonder. He had
seen the danger as well as his masters, and with that wonderful instinct
which sometimes serves a beast better than our reason serves us had taken
the best means he could to escape it. Finding himself deserted, he crouched
down on the lee-side of the great pine which had fallen across Snap's path,
and by tucking his knees under him had managed to crawl almost under its
projecting side like a rabbit. Tree after tree had crashed over him, but the
great butt against which he crouched was solid, and now when Snap found
him he was absolutely untouched, but shut in as if in a cage by the great
fragments of trees which had broken just over his head. By taking off his
pack (which contained two out of the three rifles), and by the free use of an
axe, which was also attached to his pack, our friends at last set the old pony
free, and they all laughed heartily as they watched him crawling almost on
his belly amongst the timber, even lying down and pushing himself under a
log on his side, until the cunning old rascal was rubbing his head on his
master's sleeve again.
The other pony they found later on, but, as Dick said, no one but Snap
could have had such luck as not to lose his horse in the late storm. The
second pony was crushed to pieces. The first tree that struck the poor brute
had broken its spine as if it had been a dry twig, and crushed it as a cart-
wheel would crush a rat. The pack, too, was crushed and buried under the
trees, the only thing which had escaped being Towzer's rifle, which had got
torn away from its lashings before the pony was killed.
'Well, we might have done a lot worse,' said Wharton; 'there are all the
rifles safe, and old Cradle has the flour and a frying-pan, the axe and the
kettle. We shall do very well.'
'Much good the kettle will be,' said Towzer; 'the tea is somewhere under
that dead horse, and so are the beans and bacon.'
'Yes,' added Frank, who had been hunting about amongst the packs, 'and
there isn't a match that will strike amongst us.'
'Never mind that,' said Wharton. 'You have the only muzzle-loader
amongst us, haven't you, Frank? Hand it here. We'll camp just where we are.'
Frank obeyed, and the old man chose a spot where some fallen trees
formed a kind of square, the centre of which he cleared from debris, and
then, taking an axe, he just trimmed off the wet outside of one of the great
trunks, and made a big hollow in the dry, half-burnt tinder. This done, he
greased a piece of rag, and, having 'salted it over,' as he expressed it, with
grains of gunpowder, he rammed it loosely into one of the barrels of Frank's
muzzle-loader, and then fired it into the hollow he had prepared. After one or
two tries he succeeded; the rag caught fire, and set fire to the dry wood, and
it kept the boys very hard at work with their axes and a rope to cut off and
separate the huge log which formed their camp-fire from the logs around it.
Whilst they were thus employed old Wharton had produced his knife and
skinned part of the pony's quarters, which were still protruding from under
the tree which had killed him.
'Just cutting you a steak, my boy,' was the reply; 'it's a pity, though, that
this pony was born so long ago.'
No one fancied his supper much that night, but, after all, the poor old
Cradle was the only one of the party who did not share in it. He went
supperless to bed; but all the boys confessed that Dick was not a bad cook,
and that pony-steak was very good eating when you had nothing better.
It took our friends two whole days to get out of that ruined forest, and
two days of such hard work that Dick, toughened by years of hardship, was
the only one who had strength or courage to attempt to light a fire or cook at
night. Indeed, if it had not been for Dick, I doubt if even hunger would have
induced the boys to make the effort necessary to get themselves some food;
and without a good meal at night none of them would have had strength to
escape from that interminable tangle of twisted boughs and fallen trunks.
All this time 'the Cradle' had no food. There was nothing to give him,
and, except for the rain-puddles, black and thick with charcoal, the party had
no water. The men drew their belts and old Cradle's girth tighter every
evening, and a more slender-looking or famished party, black and wearied
and ragged, never came out of a burnt forest than the wanderers from
Rosebud when on the morning of the third day they issued from among the
timber and plunged into the welcome stream which made the north-west
boundary of this land of desolation.
On the far side were green forests and a stretch of yellow grass, which
seemed to revive all 'the Cradle's' worn-out energies. He needed no
persuasion to make him plunge into the stream, no hobbles to keep him safe
when he reached the further shore.
A bundle of matches, some of which had escaped the rain, had been
found, so the men sat down, lit a fire, and as they baked themselves cakes
upon the coals they watched with pleasure the steady, business-like way in
which the old pony made up for lost time.
When they had all washed and fed they made another march of about
fifteen miles, which brought them to the edge of that country in which Dick
hoped to feed his cattle.
'Of course,' said he, 'we shall have to come a long way round; you
couldn't drive cattle through that wilderness,' pointing back to the brûlé; 'but
it is a good country, isn't it?'
And it was! A few miles from where they were camped was a range of
high, rocky peaks, with little or no timber upon them. These peaks were
quite bare, and one in particular rose like a great pulpit high above the rest,
the centre of the highest group of peaks. Up to the foot of this little group of
mountains ran Dick's range, a succession of rolling swells of grass-land,
studded over with groves and bunches of the red bull pines. It was a
splendid, park-like country, and many a group of deer cantered away from
them as they rode through it.
'Right you are,' replied the old man; 'but I'm not a-goin' to have any
sleeping partners in our firm, so just you get up off of your back, young man,
and get some bread made while I cut wood for the night-fire.'
Towzer made a grimace and rolled over on to his face with a yawn, but
eventually shook himself and began to make preparations for baking.
'Had you there, Snap,' said Frank; 'the young 'un has got "a rise" out of
you this time.'
'Quite fair, too,' said Dick. 'I guess Snap got a pretty considerable rise out
of the boys at Rosebud with that tarnation Borwick of his.'
But Snap pretended to be out of hearing, and was soon lost among the
timber.
There was a good deal to do about the camp that afternoon. All the pack
wanted overhauling and cleaning. Charcoal and wood-ash took too
prominent a place in the composition of everything in the Cradle's load, from
tea to tobacco. The frying-pans had lost their handles, and these had to be
replaced by others extemporised from a split stick; the spoons had been lost,
so others had to be made from birch-bark; the soup-kettle was lying as flat as
a pancake under the dead pony in the brûlé, so another had to be made, and
this, too, was of birch-bark.
'How are you going to boil that, Dick, without burning a hole in the
bottom?' asked Frank.
'By putting the fire inside instead of out, my lad,' replied he.
'Oh yes, old boy, I twig, and the soup outside instead of in!' cried Towzer.
'Quite simple, isn't it, Frank?'
Towzer obeyed.
'Now, you see,' said Dick, suiting the action to the word, 'in go the
pebbles and the water begins to sing; as soon as the first lot get dark and
cool, out they come, and in goes another lot. If you pour the water over your
toes by accident, you'll find it piping hot, I promise you; and when you've
done doing that and can spare time to look at the bottom of the kettle, you'll
find that it ain't got no hole in it.'
'Bully for you, Dick,' assented Towzer, 'your youth doesn't appear to have
been as much wasted as I thought it had been.'
'Why don't you give the brat a taste of the lash-rope, Dick? it would do
him a world of good.'
'Snap doesn't seem to be having any luck with the deer,' Frank remarked
after a while.
'No,' replied the other; 'I've not heard his rifle myself, but I reckon he's
got a bluff between us and him, and then, like enough, we wouldn't hear with
that chatterin' young jay-bird anywheres near.'
As the sun was setting, Snap was seen coming down a long glade towards
the camp.
'Don't carry his tail in the air, does he?' remarked Towzer. 'I don't believe
he has got a thing.'
'He can't have been out three hours here without getting a shot, I'll lay a
wager,' said Wharton.
'He's all right, I can see something hanging on his shoulders,' said Frank.
'So can I now,' added Wharton, 'but it's not venison, it's only fool-hens,
I'm thinking.'
'A jolly sight better too,' remarked Towzer, smacking his lips greedily.
'Well,' replied the hunter, throwing down three big blue grouse by the fire,
and leaning on his rifle, 'that's the bag.'
'Wal! but you don't mean to say you didn't see any deer?' exclaimed
Wharton. 'Why, man, the park is full of them. Couldn't you hit 'ein?'
Snap put his finger in the muzzle of his Winchester, and held it up
unsoiled.
'Never fired a shot, Dick,' he said. 'I stoned those fool-hens coming home,
and my arm regularly aches with shying at them; but I can't understand about
the deer.'
'Well, going from here towards what you call the "Lone Mountain," the
wind would be right for me, wouldn't it?'
'Slap in your teeth; couldn't be better, what there is of it,' replied Dick.
'Well, and yet every deer I saw had its head up; almost every one was
going at a canter; and, though, I dare say, at one time and another, I must
have seen forty, I never got what I should call a fair shot. You see, we've no