Learn JavaScript with p5.js: Coding for Visual Learners Arslan instant download
Learn JavaScript with p5.js: Coding for Visual Learners Arslan instant download
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/
https://textbookfull.com/product/full-stack-javascript-learn-
backbone-js-node-js-and-mongodb-mardan-azat/
https://textbookfull.com/product/coding-art-a-guide-to-unlocking-
your-creativity-with-the-processing-language-and-p5-js-in-four-
simple-steps-2nd-edition-mathias-funk/
https://textbookfull.com/product/web-development-for-beginners-
learn-html-css-javascript-step-by-step-with-this-coding-guide-
programming-guide-for-beginners-website-development-1st-edition-
Learning React js Learn React JS From Scratch with
Hands On Projects 2nd Edition Alves
https://textbookfull.com/product/learning-react-js-learn-react-
js-from-scratch-with-hands-on-projects-2nd-edition-alves/
https://textbookfull.com/product/d3-js-in-action-data-
visualization-with-javascript-2nd-edition-elijah-meeks/
https://textbookfull.com/product/d3-js-in-action-data-
visualization-with-javascript-second-edition-elijah-meeks/
https://textbookfull.com/product/learn-python-visually-creative-
coding-with-processing-py-1st-edition-tristan-bunn/
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
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
Another Random Scribd Document
with Unrelated Content
William looked very thoughtful for some time: at last he said, "no,
mamma, this is certainly the best; for it seems more like the truth, I
dare say all these things really happened; while you know even little
Louis would laugh at me if I really believed there ever were such
creatures as fairies."
"Ah, William," said Mary, "but there are some very beautiful stories
about fairies. Do not you remember the story in verse which mamma
read to us some time ago? It began thus:
"Oh yes, Mary, I remember, and I wish mamma would read us some
more tales like that."
"I must find them first, Willy," said Mrs. Dormer, "for that tale stands
alone in the English language: I do not remember another that
equals it in beauty. But you must be content with hearing the
adventures of children like yourselves, for my stock of fairy lore is
almost exhausted."
"What is the name, dear aunt, of the next story you mean to read
us," asked Kate, "for I peeped into your desk when you took the last
out, and I saw that you had a good many more left."
"That will depend on circumstances, my love," replied Mrs. Dormer.
"I do not know which I shall read first. But I will tell you what you
will like better; and that is, our friends Mr. and Mrs. Matthews have
sent an invitation for you all to spend to-morrow afternoon with
them. We shall have a delightful walk across the heath; and you,
William, will see your little friends—for George and Edward have
come home for the holidays."
This news gave great delight to the little Dormers, and they spent
the evening anticipating the pleasure of the morrow, and in hoping
and wishing for a fine day.
William's eyes were opened by six the next morning; he ran to the
chamber where his sister and cousin slept, and tapping at the door,
asked them if they would get up, as it was a fine morning, and study
their lessons in the garden before breakfast, and then they would be
done very early when their mamma was teaching them. This
proposal was perfectly agreeable to the little girls; who, after
dressing themselves and saying their prayers, went into the garden,
and with lively spirits enjoyed the delicious freshness of a lovely
summer's morning. Here they walked up and down, studying very
diligently till they had their lessons by heart, and already looked
forward to the pleasure of their mamma's praise.
All this was very well, and they walked some time very soberly, till
little Louis came into the garden, saying he had some very hard
words to learn, and intreating his sister Mary to pronounce them for
him. Mary very good-naturedly complied, and sat down on the seat
under the fir tree to con them over with him.
Kate and William, though good children were sometimes inclined to
be giddy, and this morning they were in such high spirits, that they
were more careless than usual. Unfortunately, chance led their steps
towards the poultry-yard, which was separated from the garden by
some pales and a wicket. They opened the gate and passed
through, to look at some nice broods of ducks that were just
hatched. Kate stood several minutes admiring the soft yellow
ducklings, and did not notice what William was doing, till he called
her to partake in some sport which he thought very delightful. He
had laid a plank (left there by accident) across a small dirty pond,
dug for the convenience of the ducks, and was racing backwards
and forwards so cheerfully on this board, that giddy little Kate
thought she must follow his example. After they had amused
themselves for some time with this diversion, William took it into his
head to jump from the plank across the pond, and as it was a very
little distance, he did it easily. Kate endeavoured to follow, but as
she was not used to leaping, it is no great wonder that she plumped
up to her waist in the dirty water. They both shrieked in concert for
help; and the gardener being fortunately near the spot, soon pulled
Miss Kate out of the mud, and carried her in his arms to the house.
In their way they met Mary and Louis, who had been alarmed by the
cries of Kate: Mary was terribly frightened at seeing the water
stream from her cousin's clothes; she ran to her mother's door,
crying, "pray, mamma, come quickly, for I fear that Kate is
drowned."
Mrs. Dormer was much astonished, for she did not think Kate could
get at any water sufficient to drown herself. However, she hastened
to the children's room, where she beheld the weeping Kate, with the
house-maid busily employed in taking off her wet clothes. Mrs.
Dormer's first care was to hurry the imprudent child to bed, and
cover her up warm, while her clean clothes were airing. She then
demanded the particulars of the disaster; and, on hearing the whole
affair, could hardly help laughing. However, she comforted the
weeping girl by saying, if she had not taken cold there was no great
harm done, and, promising to send her up some warm tea, she
retired; whilst Kate was greatly troubled for fear she should be made
to lay in bed all the day.
When Mrs. Dormer entered the parlour, she perceived William,
looking much like a culprit.
"So, Sir," said his mother, "it was you who led your cousin into this
mischief."
"It was, dear mamma, but I am very, very sorrow," answered
William.
"Consider," said Mrs. Dormer, "the delicate state of your cousin's
health, and how fatal such an accident might have been if her wet
clothes had not been taken off directly. I do not think she will be ill
as it is, but hope she will be able to go to Mrs. Matthews's this
afternoon.
"I suppose, mamma," said William, "as I have been so bad a boy, I
am not to go?"
"You well know," said his mother, "that I never punish an act of
carelessness as I do any thing criminal, therefore I shall trust to your
own good disposition, that you will not err in a like manner for the
future."
William kissed the hand of his kind mamma, and said, "I did indeed
think of Sidney's jumping into the ditch, just as Kate fell into the
pond: but you know, mamma, that was too late. We should have
thought on it before we played such a foolish trick."
After Mrs. Dormer had done breakfast she went up and dressed
Kate, who had taken no hurt. The children finished their lessons very
soon: and Mrs. Dormer told them there was time for a good deal of
play before dinner. "I think," added she, "I can answer for Kate's
keeping out of the duck-pond."
On hearing this remark Kate hung down her head, and looked very
foolish—at last she said, "I would rather not go out, aunt. If you
would read us a story I should like much better to sit still and hear
it."
Mrs. Dormer smiled, and unlocking her writing-desk, selected from
among her papers the tale of
The cloth was laid for dinner by the time Mrs. Dormer had finished
her story. The children all looked very grave at the end, and seemed
much edified: particularly William, who said, as he seated himself at
table, "I am afraid, mamma, you think that I behaved as bad as
Harry or Phil this morning."
"No, Willy," said his mother, "what you did wrong was not the result
of wilful mischief but was only for want of thought: for instance, if I
had looked over the pales when you were dancing on the plants,
and told you to come away, and never to do so again, I think I can
answer for my William that he would not have disobeyed me."
"No, dear mamma," said William, "I hope I should not have been so
wicked."
Just as dinner was finished, Edward Matthews drove up to the door
in a donkey chaise, which he had brought, by the desire of his
father, that the little girls might not be fatigued with walking in the
heat of the day. Mrs. Dormer, with Kate and Mary, were soon ready;
and Edward, having lifted the young ladies and little Lewis into the
chaise, walked with William by the side of the donkey, leading him,
and patting his neck. Mr. and Mrs. Dormer walked behind, and were
greatly pleased with the attention and kindness of Edward: who, to
say the truth, was a favourite with all the family. He was a fine
manly youth of thirteen, but though he was by many years older
than the little Dormers, he was so sweet tempered that they doated
on him.
The little party proceeded joyously across the heath, exulting in the
company of their dear Edward; who, poor fellow, had need of two or
three pair of ears: for, in the joy of their hearts, the children all
talked at once, telling him all the wonderful things that had
happened to them since they saw him last.
The afternoon passed rapidly; and the children enjoyed themselves
so much, that their indulgent parents, rejoicing to see them good
and happy, delayed breaking up the party till the latest minute.
When the hour of separation at length arrived, and they were
preparing to depart, Mrs. Matthews asked Mrs. Dormer if she would
permit her little family to join her sons in a party to Hampstead-fair,
that day week. Now Mrs. Dormer had a dislike to fairs; but as Mr.
Dormer seemed to wish it, and the children all looked up in her face
with most anxious countenances, she would not withhold her
consent.
The donkey chaise was again brought to the door, and the little
Dormers had a charming ride home. Mary, in particular, was
delighted at seeing the heath spangled with glow-worms.
"Oh, papa," she exclaimed, "do let me get out and catch some of the
lovely creatures; I never saw any before."
"No, Mary," said her mother, "you must not run on the damp grass
with your thin shoes. Look," continued she, holding up her
handkerchief, which shone like a lamp, "see, Mary, I have collected a
great many of the lovely creatures, as you call them, and will
examine them when we get home."
Mary was highly pleased at this; but she could not help calling out,
as she saw these beautiful insects shine brighter as the darkness
increased: "Oh, mamma, there is another! do catch it."
All the little party were quite grieved when they turned down the
lane that separated their house from the heath.
Sleep weighed too heavy on the eyes of all the children to allow
them to look at the glow-worms that night, but in the morning Mary
ran into her mother's dressing-room to look at the beautiful
prisoners. She hastily took off the lid of a glass jar, in which her
mother had placed them, and, lifting up some wet moss, gave
almost a shriek of disappointment. "Oh, mamma," she said, "all the
glow-worms have run away; here are nothing but some ugly brown
beetles! I dare say they have eaten those pretty creatures."
"What a pity!" said Kate. "Dear aunt, let us empty the jar into the
garden."
"No, my love," said her aunt, "let them alone; perhaps these beetles
may bring us some tidings of the glow-worms." At that minute they
heard Mr. Dormer below, talking to Edward, who had just arrived,
with his little brother George. Mrs. Dormer, therefore, went down to
ask them to dinner; which invitation they thankfully accepted.
In the cool of the evening, after the children and their guests had
tired themselves with play, they all came up to Mrs. Dormer's
dressing-room and begged for a story. Mrs. Dormer had prepared for
them, there, a regale of cakes and fruit, and while they were
enjoying it, she kindly read to them the story of
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com