Beginner S Step by Step Coding Course Learn Computer Programming The Easy Way DK Install Download
Beginner S Step by Step Coding Course Learn Computer Programming The Easy Way DK Install Download
https://ebookmeta.com/product/beginner-s-step-by-step-coding-
course-learn-computer-programming-the-easy-way-dk/
https://ebookmeta.com/product/lua-programming-the-ultimate-
beginner-s-guide-to-learn-lua-step-by-step-claudia-alves-
alexander-aronowitz-alves/
https://ebookmeta.com/product/php-programming-a-step-by-step-
guide-to-learn-in-an-easy-way-the-fundamentals-of-php-
programming-language-3nd-edition-daniel-robinson/
https://ebookmeta.com/product/swift-programming-the-ultimate-
beginner-s-guide-to-learn-swift-programming-step-by-step-3nd-
edition-alexander-aronowitz-nln-lnc-aronowitz/
https://ebookmeta.com/product/male-bodies-and-sexual-difference-
a-proposal-for-a-feminist-corporeo-ethics-1st-edition-ovidiu-
anemtoaicei/
Convolution like Structures Differential Operators and
Diffusion Processes Lecture Notes in Mathematics 2315
Rúben Sousa
https://ebookmeta.com/product/convolution-like-structures-
differential-operators-and-diffusion-processes-lecture-notes-in-
mathematics-2315-ruben-sousa/
https://ebookmeta.com/product/the-dark-triad-of-personality-
narcissism-machiavellianism-and-psychopathy-in-everyday-life-1st-
edition-minna-lyons/
https://ebookmeta.com/product/calculus-volume-2-gilbert-strang/
https://ebookmeta.com/product/frontiers-of-engineering-reports-
on-leading-edge-engineering-from-the-2015-symposium-1st-edition-
national-academy-of-engineering/
https://ebookmeta.com/product/emotional-advantage-embracing-all-
your-feelings-to-create-a-life-you-love-randy-taran/
The Luck of Fitzwilliam Darcy A Pride and Prejudice
Variation 1st Edition Glenna Mason
https://ebookmeta.com/product/the-luck-of-fitzwilliam-darcy-a-
pride-and-prejudice-variation-1st-edition-glenna-mason/
BEGINNER’S
STEP-BY-STEP
CODING
COURSE
LEARN COMPUTER PROGRAMMING THE EASY WAY
DK DELHI
Senior editor Suefa Lee
Project art editor Sanjay Chauhan
Project editor Tina Jindal
Art editors Rabia Ahmad, Simar Dhamija,
Sonakshi Singh
Assistant editor Sonali Jindal
Jacket designer Tanya Mehrotra
DTP designer Jaypal Chauhan
Pre-production manager Balwant Singh
Senior managing editor Rohan Sinha
Managing art editor Sudakshina Basu
DK LONDON
Project editor Miezan van Zyl
US editor Kayla Dugger
Project art editor Francis Wong
Managing editor Angeles Gavira Guerrero
Managing art editor Michael Duffy
Associate publishing director Liz Wheeler
Publishing director Jonathan Metcalf
Art director Karen Self
Jacket design development manager Sophia MTT
Producer (pre-production) Gillian Reid
Senior producer Meskerem Berhane
DK books are available at special discounts when purchased in bulk for sales
promotions, premiums, fund-raising, or educational use. For details, contact:
DK Publishing Special Markets, 1450 Broadway, Suite 801, New York, NY 10018
SpecialSales@dk.com
Printed in China
A WORLD OF IDEAS:
SEE ALL THERE IS TO KNOW
www.dk.com
CONTRIBUTORS
Clif Kussmaul is Principal Consultant at Green Mango Dr. Tammy Pirmann is a computer science professor
Associates, LLC, where he designs and implements at the College of Computing and Informatics at Drexel
research projects, faculty development workshops, and University in Philadelphia, Pennsylvania. She is an
classroom activities. Formerly, he taught for 20 years at award-winning educator, recognized for her focus on
college level and worked full and part time in software equity in computer science education and for promoting
development and consulting. Craig was a Fulbright guided inquiry in secondary computing education. She
Specialist at Ashesi University and a Fulbright-Nehru was the co-chair of the Computer Science Teachers
Scholar at the University of Kerala. He has received Association’s Standards Committee and an advisor on
multiple grants from the US National Science Foundation, the K12 CS Framework.
Google, and other sources to support his work with
Process Oriented Guided Inquiry Learning (POGIL), Dr. Martin Goodfellow is a Lecturer in the
Free and Open Source Software (FOSS), and other topics Computer and Information Sciences department
in computer science education. at the University of Strathclyde. He has also developed
educational computer science content and workshops
Sean McManus writes and cowrites inspiring coding for other organizations worldwide, including Google,
books, including Mission Python, Scratch Programming Oracle, CoderDojo Scotland, Glasgow Life, Makeblock,
in Easy Steps, Cool Scratch Projects in Easy Steps, and the BBC.
and Raspberry Pi For Dummies.
Jonathan Hogg is an audiovisual artist who has
Craig Steele is a specialist in computer science spent the last decade constructing works out of
education who helps people develop digital skills in combinations of software, electronics, sound,
a fun and creative environment. He runs Digital Skills light, wood, plastic, and metal. He often works
Education and is a founder of CoderDojo in Scotland, with young people, running creative and technical
which runs free coding clubs for young people. Craig workshops. Prior to art, Jonathan designed and
has run digital workshops with the Raspberry Pi developed software in the London finance industry.
Foundation, Glasgow Science Centre, Glasgow School He began his career researching and teaching
of Art, and the BBC micro:bit project. Computing at the University of Glasgow. The
only constant in all of this has been Python.
Dr. Claire Quigley studied Computing Science at
Glasgow University, where she obtained a BSc and David Krowitz learned to program in the early
PhD. She has worked in the Computer Laboratory at 1980s on a Commodore VIC-20 plugged into a
Cambridge University and at Glasgow Science Centre. portable black-and-white TV set. He has been studying
She is currently STEM Coordinator with Glasgow Life, and practicing computer programming ever since.
and lectures part time at the Royal Conservatoire of Nowadays, Dave spends his time building microservice
Scotland, working with BEd Music students. Claire architecture for businesses while expounding his love
has been involved in running CoderDojo Scotland since for object-oriented design patterns and software
its initial session in 2012. architecture. See dotpusher.com for more info.
CONTENTS FOREWORD
INTRODUCTION
10
12
What is programming? 16
Programming languages 22
SCRATCH
What is Scratch? 28 Logic and decisions 44
Manipulating data 42
PYTHON
What is Python? 94 Libraries 116
Functions 112
WEB TECHNOLOGIES
How the Web works 206 JavaScript debugging 280
Build a better website 214 PROJECT: Animating the web page 288
Foreword
If you’ve ever asked a teenager for help with your Starting at the absolute beginning, this guide will
computer, you probably have felt the crushing introduce the jargon and tools you’ll need to get
weight of self-doubt as you realize you understood programming in the most popular and versatile
less than half of what they just said. That same software languages. The pages are also peppered
“helpful teen” would most likely scoff at the idea of a with interesting facts about coding and careers,
book—made out of honest-to-goodness, old-fashioned together with step-by-step projects to get you going.
paper—on the subject of learning to code. “Just Even if you decide not to become the next Mark
Google it. There are loads of tutorials on YouTube!” Zuckerberg, the skills you’ll learn will be a great
they might say. asset when talking to technology professionals
But not everyone is high-bandwidth, multiscreen and will also help develop your own logic and
ready. Plus, when you are carefully stepping through problem-solving abilities.
the creation of your first lines of code, a physical page It was an ancient Greek philosopher who first noted
with your fingertip planted firmly on the next step can the irony “the only constant in life is change,” and
act as a valuable lifeline to the tangible world. this has never been more true than in the world of
If you’re reading this as a teenager yourself, computing. Maybe you’re looking for a different career
congratulations on discovering life beyond YouTube! or want to learn a new skill to support a hobby or
You’re about to find out that the creators of this guide passion project. Or perhaps you just want to be able
are exactly the kind of industry-defining professionals to talk to your tech-obsessed teenager in a language
whose content channels, blogs, and social media posts that will impress them!
you’d end up on if you did decide to Google “learning For those curious about coding, this guide is full of
to code.” straightforward information in easily digestible bites,
As a lifelong gamer and computing enthusiast, written by some of the leading educators and experts
I’ve been reporting on technology for almost a quarter in their field. There is jargon, but it’s jargon you’ll
of a century. In that time, I’ve witnessed seismic understand as you get to it. Is learning about coding
changes in the way we interact with the world. AI, essential? No. Will it help you understand and feel
big data, automation, e-commerce—all now intrinsic more comfortable in the world we now live in? I think
parts of our daily routines, even if we aren’t always so. Could it lead to a new and amazing career
aware of them. direction? Definitely, if that’s what you want.
Technology is no longer a niche topic. In fact, There is still a desperate shortage of technology
today, every industry could be considered a tech professionals in the workforce. Opportunities exist,
industry, which leads to a simple choice: get with but they are not going to come looking for you unless
it or get left behind. you speak at least a bit of their language.
Kate Russell
Technology reporter,
author, and gamer
About this book
How this book works grouped under Web Technologies. The book defines
Divided into three chapters, this book teaches the the basic concepts of each programming language and
fundamentals of five programming languages: Scratch, builds on them with the help of detailed projects that
Python, HTML, CSS, and JavaScript; the last three are you can try on your own.
Concepts
Each chapter contains the basic
programming concepts of the language.
These are explained with the help of
practical code examples that you can try
out to understand the concept better.
Illustrations help
you understand
and learn concepts
Projects
The projects in this book teach you how to YOU WILL LEARN
create games, planners, apps, and websites. Indicates the estimated
Each project starts with a brief overview of Time: time it will take to create
what you will learn in the project, how to 1 hour a project
plan the project, and what you will need to
create it. Simple step-by-step instructions Lines of code: 58 Indicates the estimated lines
guide you through the project and explain of code in a project. This
Difficulty level may vary depending on the
every aspect of the code, with the help of
detailed annotations. code editor being used
1.2
Projects are broken down into 1.1
smaller sections with clear steps
to make learning easier
available = 2500.00
budgets = {}
STEP-BY-STEP
These chevrons appear only in Every indent (spaces at the start of a line)
the shell window. Type in the equals four empty grid blocks. All subsequent
code at the >>> prompt indents will be in multiples of four
In this book, ellipses are used at the Gray code indicates an CODE WINDOW FOR The placement of the arrow
start of a line of code to indicate an existing line of code in WEB LANGUAGES indicates if a space needs to
extended indent, usually more than the program. It is used be added before it. In instances
eight grid blocks to identify the line below where there will be no space,
or above which the new no empty grid blocks are left
code must be added between the arrow and the code
Data center
A data center is similar to an
industrial-scale computing facility.
Its many servers may be accessed
over the internet to store data or
run software “in the cloud.” The
“cloud” is a global network of Desktop computer
remote servers that can provide Computers are widely used in
services through the internet. offices and homes for managing
administrative and creative activities,
such as music, design, writing,
Car banking, and many more.
Software can be used to Washing machine
monitor a car’s systems and Many household appliances run
performance, including its embedded programs to perform
speed, temperature, and a function. Inside the casing of a
fuel. The global positioning washing machine, software runs
system (GPS) used to manage its wash cycles, water
for navigation also temperature, and timings.
requires programs.
INTRODUCTION
What is programming? 16 17
What is a computer program? Thinking like a computer
A program is a set of instructions that a computer To write a program, it is necessary to
follows to perform a task. Programs can be extremely understand how a computer processes
complex, and there can be several different layers of instructions. This means that tasks need to
programs working together. Microsoft Windows, for be broken down into smaller chunks so that
example, is made up of millions of lines of instructions. the computer can understand the instructions.
For example, a robot cannot simply be asked to
Application software, “make some toast.” It is necessary to program
such as word processors,
run on top of the
precise and detailed instructions for each step.
operating system
Instead of repeating
Operating systems, such 1. Open cabinet the same instruction
as Microsoft Windows 2. Remove loaf twice, it will be
and macOS, manage the 3. Open bag shorter and clearer
hardware and software to say “Do this twice:
4. Remove slice
remove slice, insert in
5. Insert in toaster toaster” in a program
Firmware is software that
6. Remove slice
is coded into the hardware,
including the Basic Input/ 7. Insert in toaster
Output System (BIOS) 8. Push down plunger
9. Wait until toast
Hardware includes the physical pops up
elements of a computer, such
as the monitor
Game consoles
Consoles such as the Sony
PlayStation, Microsoft Xbox,
and Nintendo Switch are Camera
computers designed to offer Modern cameras use
a great gaming experience. software to change settings,
capture images digitally,
and enable users to review
and delete photographs.
Factory equipment
Factories can be highly automated. Assembly-
line robots, planning and control systems,
and quality-control cameras all require
programs to operate.
Managers and office workers
Many businesses create and use specialized software.
Software engineers develop complex software systems, but
managers and office workers often write short programs
to solve problems or automate tasks that might take
hours or days by hand. For example, they might write
code to query databases, format information,
analyze data, control equipment, customize
websites, or add features to word processors
and spreadsheets. Some programming
languages are specifically designed for these
purposes (see pp.344–347).
Coding in
the real world
Coding is used in nearly every aspect of modern life
and work. Basic knowledge of coding helps people
use software more effectively, create simple programs,
and communicate with other software developers.
INTRODUCTION
Coding in the real world 18 19
Software engineers and web developers
Software developers work for many different businesses
and organizations. Businesses require software to
track inventory and place orders with suppliers,
to schedule employees and track work hours,
and to send mailings to customers. Insurance
companies use software to set pricing based
on the number and cost of events and to
review and approve policies. Websites
often combine existing programs with
custom coding for special features.
Software engineers play key roles
in developing systems that suit
a client’s needs.
25,000,000
WORKERS ACROSS
THE WORLD ARE
SOFTWARE DEVELOPERS
Working as a
software developer
Writing a simple program might seem straightforward, but it can be
surprisingly difficult. Developing large, reliable software systems is
even more complex and requires teams of software developers with
a variety of specialized skills and roles.
Analyze
In this phase, developers decide what the
software must do. They might study existing
systems, design new processes, or interview
people to understand how they will use the
system. This also defines other constraints
or requirements. For example, how much
data must the system handle, how quickly
must it respond, and what should it do when
problems occur? The resulting documents could
range from a few pages to hundreds or more.
Test
Developers check whether the
software works correctly and fix
any problems they find during the
testing phase. This is often the
longest and least predictable phase
and a common reason for delays and
extra costs. There are many types of
tests—unit tests check if individual
functions are correct, functional
tests check individual components,
integration tests check if components
work together, and system tests
check the entire system.
INTRODUCTION
Working as a software developer 20 21
Overview
Software development involves four phases: analyze, design and
plan, build, and test. These phases, however, can be structured in
a variety of ways. A waterfall model steps through each phase once,
which seems simple, but often leads to problems. An iterative model
cycles through the phases several times, building part of the system
in each cycle. An agile model cycles through each phase many times,
adding different features in each cycle.
Design and plan pieces, and specifying the files and even the individual
In this phase, developers decide how the software functions to be created. Developers also need to
will work and how it will be created. This can include estimate the time, effort, materials, and cost to create
deciding on which language to use, sketching user the system and put together a schedule for who will do
interfaces, designing databases, subdividing it into which tasks at what time.
Build
In the build phase, developers
create the software, including
user interfaces, databases, code,
and documentation for users and
programmers. This means that
coding is just one part of one
phase of software development,
and in some ways the easiest and
most predictable. As each piece is
built, developers might inspect or
review the code to see how well
it is written and then integrate it
into the larger system.
Programming
languages
A programming language is a set of words and symbols that
allows people to write instructions for a computer. There is
sometimes a compromise between how easy the language
is to use and how powerful it is.
High- and low-level languages program can run on different hardware if it is written
High-level programming languages are designed to be in a high-level language. By contrast, low-level
easy to use without needing a detailed understanding languages give programmers granular control over
of the computer hardware. They often use words that the computer but also require a deeper understanding
are similar to human language and manage some of how it works. Programs written in a low-level
aspects of the computer automatically. Often, the same language might not work on other hardware.
Instruction to
HIGH-LEVEL LANGUAGES display some text
• Relatively fast to write
• Relatively easy to understand
• Usually fast enough in execution print("Hello!")
• Programs can be used on different
hardware Python
• No need to understand hardware A popular high-level language,
Python is easy to read and write.
This instruction puts the message
“Hello!” on the screen.
This is hexadecimal,
a common counting
system in computing
LOW-LEVEL LANGUAGES
• Direct control of hardware features
• Can increase speed of highly MOV AX, 66H
performance-sensitive code
• Requires an understanding of Assembly language
the hardware Assembly language more
• Program only works on the closely reflects the processor's
same or similar processor machine code. This example
takes a number and places it
into the part of the processor
called the accumulator.
INTRODUCTION
Programming languages 22 23
Machine code How the computer understands
Low-level code that represents how the computer a programming language
hardware and processor understand instructions Ultimately, all programs end up as machine
is called machine code. It is a collection of binary code. Most programs are written in more
digits—1s and 0s—that the processor reads and human-friendly languages and need to be
interprets. Machine code instructions are comprised translated into raw bits so that they can
of an opcode and one or more operands. The opcode be executed by a processor. An interpreter
tells the computer what to do and the operand tells translates and executes the instructions
the computer what data to use. as the program is running, while compilers
translate the program in one go before it runs.
Microprocessor
The microprocessor is the “brain”
of a computer and controls most
of the machine’s operations. It
carries out commands and runs
01101000
the machine code instructions. 01101001
00001101
00001010
HUMAN- CONVERT TO RUN
FRIENDLY COMPUTER INSTRUCTIONS
CODE INSTRUCTIONS
EVENT-DRIVEN PROGRAMMING
The event-driven programming concept is
Creates a
one where the program listens for certain
web page button
things to happen and then starts the
appropriate program sequence when they
do. For example, a program might react <input type="button" value="Click me!"
to user actions, sensor input, or messages
from other computer systems. JavaScript
(see pp.264–265) and Scratch (see pp.28–29),
onClick="showMessage();">
among others, can be used to write
event-driven programs.
Runs the showMessage() This icon has been used in
JavaScript instructions when the book to indicate code
the button is clicked being split into two lines
INTRODUCTION
Programming languages 24 25
CHOOSING A LANGUAGE
Sometimes, programmers’ choice PYTHON SCRATCH
of language may be dictated by the
A flexible language, it emphasizes A great first programming language,
hardware they are using, the team ease of understanding in the code. Scratch is perfect for simple games.
they are programming with, or the
kind of application they want to
JAVA JAVASCRIPT
create. Often, they will have a choice.
Here are some popular languages Widely used in financial services, The language used by web
that can be considered. small devices, and Android phones. pages for interactivity.
MAIN PROGRAM
Data for this object
FUNCTION 1
FUNCTION 3
Features
Scratch has a number of features that
make it an ideal programming language
for beginners. The use of premade
blocks of code sets it apart from most
Com
other programming languages. Scra munity
t
othe ch allow
com rs throu s users t
m g o
prog unit y. h a buil conne
U t c
mod rams for sers ca -in Scrat t with
n
learn if y, and others t share t ch
by st remix o pla
y
heir
ud y i .
ng o They can with,
t h er
s’ pr also
ojec
t s.
drop
Drag and cks can be
h b lo
Scratc ped in
and drop
dragged rea to build
A
the Code here is very
T
programs. , so users are
g
little typin make errors.
to
less likely
uage
Power ful lang use
h is ea sy to
Scratc
core concepts
but includes
sional
used in profes s. It
ng la ng ua ge
codi
ides a good
therefore prov uction
d intr od
all-aroun
ing.
to programm
Jigsaw de
sig
Instruction n
b
like jigsaw locks snap together
pie
connect th ces, so users can’t
em
Nonsensica in incorrect ways.
l
typically im combinations are
p
logic are m ossible, so errors in
inimized.
SCRATCH
What is Scratch? 28 29
Learning to program with Scratch used in education. Scratch has a highly
Scratch was created by the Lifelong Kindergarten visual interface with colored blocks of
Group at the Massachusetts Institute of Technology code that join together to form scripts,
(MIT). It was first launched in 2007. which can include images and sounds
Scratch was designed to be fun and easy to use to create action onscreen. Scratch provides
for beginners and to help them understand basic a powerful platform (see pp.30–31) for
concepts and avoid errors. It is therefore widely exploring programming.
Hardware support
The latest version of Scratch works on computers
with Windows, macOS, and Linux. It can even
Built-in assets be used on tablets. Scratch projects can use
th a preinstalled
Scratch comes wi d extensions to interact with hardware devices.
so un ds and images (calle
librar y of th at ma kes it
.32 –3 3)
sprites—see pp r
g right away. Othe
easy to start codin es lac k in this
guag Raspberry Pi
programming lan d
need to be create Scratch can use a Raspberry Pi to connect
regard, as images itin g a program.
be for e wr to other sensors or motors.
or uploaded
micro:bit
Scratch can be used with a BBC micro:bit,
which has a built-in LED display, buttons,
and tilt sensors.
Lego®
Scratch can connect to Lego® WeDo and
Lego® Mindstorms™ to work with motors,
sensors, and robots.
Webcam
Scratch can access a webcam to layer images
on a live video feed to create simple augmented
reality applications.
GETTING SCRATCH
The Scratch developer environment is required
Color
Instru coding
for using Scratch. It can be accessed both online
c
move tion blocks and offline.
m
and se ent, sound for
are co nsing (amo , control, In your browser
lo n
be ea r coded, s g others) Visit the Scratch website at
s o
when ily identifie they can https://scratch.mit.edu/ and click
creatin da
g a p r nd re ad Join Scratch to create an account.
og r a m
.
Offline
Scratch can be downloaded and used
without an internet connection at
https://scratch.mit.edu/download.
Scratch interface
The screen layout, or interface, in Scratch can be used to build
programs, edit them, and view the output in the same screen. The
interface is divided into several sections, each serving a particular
purpose. This book uses Scratch 3.0—the latest version of Scratch.
Create new projects; Use the Sounds tab to
Understanding the screen layout Change upload or save work Edit existing add music and sound
The Scratch interface is divided into the language to the computer projects effects to sprites
following sections:
• Blocks Palette: This contains the instructions,
SCRATCH File Edit Tutorials
or code blocks, required to build a program.
• Code Area: The instruction blocks are Code Costumes Sounds
assembled here to create a script.
• Stage: Allows the user to interact with Use the Costumes
Motion tab to change
the program. Motion the appearance of
• Sprite List: Displays and manages all the move 10 steps a sprite
images, or sprites, used in a program.
• Stage Info: Manages the background images. Looks
turn 15 degrees
Events
go to random position
STAGE
BLOCKS CODE
Control go to x: 0 y: 0
PALETTE AREA
glide 1 secs to random position
SPRITE Sensing
LIST
glide 1 secs to x: 0 y: 0
Operators
STAGE INFO
point in direction 90
Variables
VERSIONS OF SCRATCH
point towards mouse-pointer
My Blocks
There have been three versions of Scratch so far,
Select instruction blocks and
each with a different screen layout. New features drag them into the Code Area
and instruction blocks were added at each update to build a program
of the interface. These features may not work on
earlier versions. Contains the instruction
• Scratch 1.4: The interface was similar to Scratch blocks that can be used
3.0, but the Code Area was called Scripts Area.
• Scratch 2.0: The Stage was on the left of the
screen. Introduced sprite cloning and reorganized
some blocks into the Events category. Backpack
• Scratch 3.0: Introduced Blocks Palette extensions
and moved the Pen blocks into them. Use the “Add Extension” Store useful code, sprites, costumes,
button to add new categories and sounds in the Backpack so that
of blocks to the Blocks Palette they can be used in other projects
SCRATCH
Scratch interface 30 31
when clicked
forever
glide 3 secs to x: 0 y: –150
glide 3 secs to x: 200 y: 100
glide 3 secs to x: –200 y: 100
Stage
Sprite Sprite1 x -90 y -10
Sprite 1 Cactus
Drag instruction blocks into the A blue box This panel shows the sprites used Add new sprites Change the
Code Area and join them together highlights the in a program—select one to see to the project backdrop
to build a script for a sprite selected sprite its code in the Code Area
Sprites
Sprites are the basic components of Scratch. Similar to characters
in a video game, they can move around the Stage, change their
appearance, and interact with other sprites. Each sprite uses one
or more images and is controlled by scripts.
Creating a sprite
Scratch allows its users to add or create their own images. The Choose
a Sprite button on the bottom right of the Sprite List reveals options to
add, create, or upload sprites in a project.
Upload Surprise
Users can include their own Scratch also has an option
images and upload them to the to add a random sprite from
Scratch interface to be used as the Sprite library. It can be a
sprites. This includes images, such quick way to add sprites to
as photographs, which may be experiment with or to generate
required to create or new game ideas.
personalize games.
1 Costume Costume1
Group Ungroup Forward Backward Front Back
Fill Outline 2
costume1 Copy Paste Delete Flip horizontal Flip vertical
239 x 315
Choose which
costume to edit Select an Line thickness Flip selected
Select a
outline color elements
fill color
horizontally
2 or vertically
Select tool
Convert to Bitmap
wait until
Control blocks
Control blocks are used to make decisions
about what to do next. They also dictate how
often a set of blocks should repeat and when
the script should pause.
Events blocks
These blocks detect when the green
flag is clicked, a key is pressed, or a
sprite is clicked.
SCRATCH
Colored blocks and scripts 34 35
Using the Blocks Palette Select this tab to begin
Output blocks
+ move 10 steps
Sound blocks
Sound blocks are used to add sound
effects to a program. They provide audio
output by replaying recorded sounds.
Output using
movement
Scratch is an ideal language for programming simple games and
applications that move images around the screen. It has a set of
blue Motion blocks that can be used to control a sprite’s movement.
x axis
–240 0 240
Coordinates 180 x and y grid
The Stage here has
In Scratch, any position on the Stage can be been marked with grid
(x=180, y=120)
pinpointed using the x and y coordinates. The x lines every 60 steps. Try
axis runs from -240 on the left to 240 on the right, (x=–120, y=60) these positions in the
y axis
0 Motion blocks (below)
and the y axis runs from -180 at the bottom to 180 for moving a
at the top. When writing a program, coordinates sprite using
(x=–180, y=60) coordinates.
can be used to place a sprite in a particular position.
(x=60 y=-120)
–180
go to x: 0 y: 0 set x to 0 x position
MUSIC BLOCKS
The Music blocks in Scratch are an extension
set tempo to 120
and need to be added using the Add Extension
button on the bottom left of the Blocks Palette. set instrument to (20) Synth Lead
They make it possible for programmers to use
blocks to play musical notes. It is not necessary play note 60 for 0.25 beats
to know the number for each note, because
clicking the hole for the note number will play note 62 for 0.25 beats
display a piano keyboard to help enter the
required music. play note 64 for 0.25 beats
Playing sounds play sound Meow until done change pitch effect by 10
Sounds are a great way to
provide feedback in a game Pause script to play sound Alter pitch
Sets a sound to play, then pauses the Changes the pitch of a sound effect. Positive
or as an alert in a program. script until it is finished. The menu numbers make the pitch higher and negative
Before a sound can be used, in the block can be used to choose a ones make it lower. The stereo setting can
it has to be added to the different sound. be adjusted as well.
sprite from the Choose
a Sound button under the start sound Meow set pitch effect to 100
Sounds tab. Programmers
Play sound in background Reset pitch
can either use a sound from Starts playing a sound but does not Resets the pitch or changes it to a value
the Scratch Sound library pause the script. The sound plays in specified by the programmer. It can also be
the background while the script runs. used to adjust the stereo left/right setting.
or record or upload a sound
of their own.
stop all sounds clear sound effects
Event-driven programming
In event-driven programming, the program’s actions are started by events,
such as user input, sensor input (see pp.46–47), or messages sent by other when clicked
programs or parts of the program. The Events section of the Blocks Palette
contains blocks that can start scripts when something happens. Also Use green flag to start
Provides an easy way for users to start the
called hat blocks due to their shape, these Events blocks provide many program. Copies of this block can be used to
more ways to start scripts than simply clicking on them. start multiple scripts simultaneously.
when this sprite clicked when loudness > 10 when I receive message1
Use mouse click to start Use sounds to start Use message to start
This block starts the attached script when When the microphone detects a volume Scripts can send messages to each other
the sprite is clicked. It is ideal for creating more than 10 (on a scale of 0 to 100), the (see pp.48–49). This block starts a script
on-screen buttons for users to click on. script can be activated. when a particular message is received.
This costume
The blue highlight indicates indicates that the
this is the selected sprite Drum Kit is playing
when this sprite clicked
INTRODUCING DELAY
It is not always desirable to have
a program run as fast as possible.
In many cases, a program may when clicked
need to be slowed down so that
when clicked move 10 steps
users can easily see what is going
on and have time to respond. move 10 steps wait 1 seconds
Games are often artificially
slowed down in order to ensure move –10 steps move –10 steps
that players can keep up.
Normal movement Delayed movement
In this example, the program runs so Introducing a wait block makes
fast that the sprite’s movements are it possible to see the sprite move
not visible. Nothing seems to happen. from right to left and back again.
Manipulating data
Programs are often used to manage and process data. This data
is either provided by the user or collected from other computer
systems. In Scratch, the Operator blocks are used to manipulate
numbers and text stored in variables.
Variables
Many programming languages use variables Strings
to store information. A variable can store one Programmers often call a piece of text in a
piece of information— either text or a number. program a “string.” For example, a string can
In a game, for example, two variables might be a name, an answer to a question, or an entire
be used to store the player’s name and score. sentence. In Scratch, any variable can store a
number or a string, and it can store different
Make a variable
1 To create a variable in Scratch, select Variables in the Blocks values at different times.
Palette and click on the Make a Variable button. Give the new
variable a meaningful name, such as score, so that the code is easy banana
join apple
to understand. Usually, variables need to be created for all sprites,
which means that all sprites can see and change the variable. Join strings
This block can be used to join two strings. The strings are
joined without a space, so the result for this example will be
“applebanana”. Variable blocks can also be used in place of
Make a Variable words typed into the block.
Check strings
This block checks whether the second string input is in the first
one and gives the answer as true or false. It is also possible to
check for more than one letter: apple contains app?
SCRATCH
Manipulating data 42 43
LISTS
A list is used to store similar pieces of information,
such as a list of names. In Scratch, a list can be created
from the Variables section of the Blocks Palette. List
positions are used for inserting and deleting items. For
example, the delete 2 of [list name] block can be used
to remove the second item from a list.
say You didn’t beat the high score this time! for 2 seconds
Logic and
decisions
Programs can be made more flexible and useful
if they are coded to make decisions about what to
do next. They can use variables to control which
instruction to run and when to run them.
SCRATCH
Logic and decisions 44 45
Combining expressions
Boolean expressions can be combined to make decisions
based on more than one factor. Here are some examples
using the current year Sensing block. It has a menu in it
to change the year to other time periods.
USING BOOLEANS
Boolean expressions can Using Booleans with loops
be used in other ways as The repeat until block repeats repeat until lives left = 0
well. Clicking on them in one or more instructions until
the Code Area allows users an expression is true. In this case,
the loop will keep going until the
to see their results while player has no lives left.
programming. They can also
be combined with repeat
Waiting using a Boolean
and wait blocks to make a Using a wait until block will pause wait until score = 50
program repeat or pause a script until an expression is true.
until something changes. However, it is often better to use a The program takes no
broadcast (see pp.48–49). action until the score is 50
Exploring the Variety of Random
Documents with Different Content
拜謝曰:『清泉活人,何啻甘露,真有回生之功』!乃甃為 井,號曰
「聖泉」。郡使者奏於朝,詔封「崇福夫人」。 ●托夢建廟 紹興二十
六年丙子(一一五六),以郊典特封為靈惠夫人。二十七年(一一五
七),莆城東五里許有水市,諸舶所集曰「白湖」。歲之秋,神來相
宅於茲。章 氏、邵氏二族人共夢神指立廟之地。丞相俊卿陳公聞之,
驗其地果吉,因以奉 神。歲戊寅(一一五八),廟成。三十年(一一
六○),流寇劉巨興等嘯聚,直 抵江口。居民虔禱於廟,忽狂風大
震,煙浪滔天,晦冥不見,神靈現出空中。 賊懼而退。既而複犯海
口,神又示靈威,賊遂為官軍所獲。奏聞,天子詔加封 「靈惠、昭應
夫人」。 ●溫台剿寇 宋孝宗淳熙十年癸卯(一一八三),福建都巡檢
羌特立奉命征剿溫州、台州二府 草寇。官舟既集,賊船蟻水面,眾甚
懼。方相持之際,咸祝曰:『海谷神靈,惟 神女夫人威靈顯赫,乞垂
庇護』。隱隱見神立雲端,軿蓋輝煌,旗幡飛飆,儼然 閃電流虹。賊
大駭。俄而我師乘風騰流,賊舟在右,急撥棹衝擊之,獲賊首, 並擒
其黨,餘䑸四散奔潰,奏凱而歸。列神陰相之功,奏於朝,奉旨加封
「靈 慈、昭應、崇善、福利夫人」。 ●救旱進爵 宋光宗紹熙元年庚
戌(一一九○)夏,大旱,萬姓號呼載道。神示夢於郡邑長 曰:『旱
魃為虐,我為君為民請命於天,某日甲子當雨』。及期,果銀竹紛
飛, 金飆噴澍,焦林起潤,暵穀生春。郡邑交章條奏,天子詔神福民
殊勛,應褒封 進爵,頒詔進封「靈惠妃」以彰聖靈。 ●甌閩救潦 宋
寧宗慶元四年戊午(一一九八),甌閩苦雨,滂沱不止,漂屋蕩崖,
春夏倉廩 告匱,民不聊生。有司請蠲議賑。莆人虔禱於神。夜夢神示
之曰:『人多不道, 厥罰常陰,故上天困此一方人。今爾眾虔恭,我
為爾奏於帝,帝矜之,越三日 當大霽,且錫有秋之貺』。至期,果見
扶桑破曉,暘谷春生,早禾得水而桀,西 成大熟。省官奏聞,奉旨加
封「助順」,以報厥功。 ●平大奚寇 戊午秋,大奚寇作亂,調發閩省
舟師討之,舳艫相接,將士枕戈。島寇巨艦銜 尾而至,銳不可當。眾
懼,各請神,香火以行。與賊遇於中流,彼居上風,難 以取勝。眾禱
於神曰:『願藉神力掃妖氛,上慰天子討叛之心,下救萬民蹂躪之
苦』。頃刻間昏霧四塞,返風旋波,神光赫濯顯現。遂衝突無前,渠
魁就擒,餘 凶或溺或潰,掃蕩無遺。凱奏,具陳神陰佑大勛,奉旨詔
神為國家討賊,其議 加封號以答神庥。 ●一家榮封 慶元六年(一二
○○),朝廷以神妃護國庇民,功參玄造,人本乎親,慶自先 貽,於是
頒詔封妃父為「楨慶侯」,又改封「威靈侯」,又以顯赫有裨民社,
加 封為「靈感嘉佑侯」;母王氏封「顯慶夫人」;兄封「靈應仙
官」;神姊封為「慈 惠夫人」,佐神。 ●紫金山助戰 宋寧宗開禧改
元乙丑(一二○五)冬,金人僕散揆從八迭灘潛渡淮,聚哨淮 甸,王
師啟行北伐,人心洶湧,求庇於神。至直隸安豐,戎馮戒嚴。神示夢
於 將領異再遇等曰:『金人犯順,北顧貽憂,若等銳志克敵,吾當助
威以佐天 子』。初戰於花靨鎮,神現靈雲端。眾望空中若有萬馬馳騁
狀,知為神力呵護, 賈勇向前,大炮碎其酋長;賊遂卻。又會戰於柴
金山,賊甚猖獗。臨陣時,複 見旌旗閃空,將領嚴令督戰,兵士擁楯
而進,敵乃披靡,獲馬百餘匹,斬馘數 百人。賊複大聚合肥,聞雲端
鏘鏘有劍戟聲,賊益懼,且戰且退,遂解合肥之 圍。全師返旆,人唱
鐃歌。天子聞神兵陰助,有護國大功,加封「顯衛」,以答 神庥。 ●
助擒周六四 嘉定改元戊辰(一二○八)秋,草寇周六四哨聚犯境,舟
艦不可勝計。時久旱 後,人窮無賴者多,既困赤地,遂入綠林,乘亂
劫掠,廬舍寥落。闔邑哀禱於 神。神示之夢曰:『六四罪已貫盈,特
釜中游魚耳;當為爾殲之』。越四日入 境,喊聲動地,忽望空中有劍
戟旗幟之形,各相驚疑,退下舟,遽衝礁閣淺。 尉司駕艇追之,獲其
首,餘凶悉就俘。寇平,境內悉安。奏上天子,奉旨加封 「護國、助
順、嘉應、英烈妃」。 ●錢塘助堤 宋理宗嘉熙元年(一二三七),浙
省錢塘潮翻,江堤橫潰,大為都省患。波湧浩 蕩,版築難施。都人號
祝於神妃。忽望水波洶湧,時濤頭上艮山祠,若有所限 拒而水勢倒流
不前者,因之水不衝溢,堤障得成,永無泛圯之患。眾咸稱神力 捍
禦。有司特奏於朝,奉旨神功赫濯,大有裨於朝家,議加封號,以答
靈感。 ●拯興泉飢 寶佑改元(一二五三),莆與泉大旱,穀值騰湧,
飢困弗支,老幼朝夕向祠前拜 禱。夢神夜告曰:『若無憂,米艘即至
矣』。 初,廣地賈客挺裝米上浙越,偶一夜神示夢曰:『興泉若飢,
米貴,速往可得 利』。客寤而喜謂神示必獲利滋倍,遂載入興、入
泉。南艘輻輳,民藉以不飢, 米價反平。郡人頗矜天幸,商人怏怏,
言神夢不驗。詢其得夢之由,方悟神為 二郡拯飢。又思前夕米艘即至
之夢,果屬不虛。咸嘆再造神功,焚香拜謝。天 子聞之,詔褒封「助
順、嘉應、英烈、協正妃」。三年(一二五五),又以顯靈 加封「靈
惠、助順、嘉應、慈濟妃」。四年丙辰(一二五六),以浙江堤岸告
成,加封「靈惠、協正、嘉應、善慶妃」。 ●火燒陳長五 開慶改元,
歲在己未(一二五九),陳長五兄弟縱橫海上,去來於興、泉、漳之
間,殺掠逞凶,家無安堵,三那困。請命於神。郡守徐公夢神示之
曰:『當殄此 賊,以靖地方』。徐公素敬信神妃,即率寨官石玉等勵
兵備之。朝廷督王憲使鎔 克期剿賊。越八月,賊三舟入湄島,將屠掠
蓼禧,禱於神,弗允,解衣偃臥廊 廡下,悖慢不敬。俄有火焚其身,
肉綻皮爛,痛楚哀呼。賊大懼,退遁舟中。 神起順風,誘之出港,忽
天日晦冥,大雨驟至。及開霽,賊三舟已在沙埔上膠 淺不動,憲使王
鎔曰:『此神授也,逆賊當殲滅矣』!揮兵急擊,賊奔潰,先擒 長
五。郭敬叔等帥兵追至莆禧,擒長六。長七乘潮退遁,後追至福清,
並俘 之,磔於市,脅從者罔治。徐公具陳神妃庇助之功,憲使奏上天
子,勒議典 禮,進封「顯濟妃」,兩司捐萬楮助修宮殿,以報神貺。
●怒濤濟溺 天歷元年(一三二八)夏,備海道萬戶府分司運糧,至大
海,遭颶風驟起,巨 浪連天,七日夜不息,人困力疲,運艘幾於翻
覆。舟人哀號,仰禱神妃求佑。 會日暮,有形從空而下,掩映舟中,
輝耀如畫,宛見神靈陟降。少頃,怒濤頓 平。船上覺異香繽鬱。自此
水道無虞,徑抵直沽都省。奏聞,奉旨差翰林國史 院學士普顏實理欽
齎禦香,馳驛致祭。 二年(一三二九),漕運複藉神妃默庇無失,加
封「護國、輔聖、庇民、顯佑、 廣濟、靈感、助順、福惠、徽烈、明
著天妃」,遣官黃份等馳傳具禮,專詣湄洲 特祭,並致祭淮、浙、閩
海等處各神廟,共祭一十八所。 ●神助漕運 至順元年庚午(一三三
○)春,糧船七百八十隻,自太平江路太倉劉家港開 洋,遇大風突
起,波撼星辰,桅檣飄蕩,數千人戰慄哀號。官吏懇禱於神妃, 言未
已,倏陰雲掩靄,恍見空中有朱衣擁翠蓋,佇立舟前,旋有火照竿
頭,晶 光如虹。舟人且驚且喜。無何,風平浪息,七百餘艘飄流四
散,正集合整理篷 漿解纜而進,又聞空中有語云:『可向東南孤島暫
泊』,眾郎撐舟依孤島旁。方 拋碇,江上狂飆迅發,暴雨倒峽。舟人
相慰曰:『非神靈指示,我等皆在鼉宮蛟 窟矣』!次日晴霽,遂達直
沽交卸。中書奏神護相之功,奉旨賜額曰「靈慈」。 ●擁浪濟舟 洪武
七年甲寅(一三七四),泉州衛指揮周坐領戰船哨捕,忽遇颶風大
作,衝泊 閣礁。舟人環泣稽首,呼神妃求庇。黑夜間倏見神火懸空畢
照,桅檣皆現。周 喜曰:『吾聞海上危急時,得神火照耀,雖危亦
安。神其佑我乎』!俄而巨浪躍 起,將船蕩浮,從𥒥隙真逾磯北,順
流駛至岸邊。時天欲曙,差認港跡,始得 無恙。歸至泉,立廟奉祀。
仍運木赴湄嶼,修整宮殿。其杉木未載者,浮水面 自飄流到湄,木頭
各有「天妃」二字,眾皆奇之。自是重建寢殿及香亭、鼓 樓、山門,
複塑聖像,制旗鼓,沿途鼓欲,送至祖廟。 時又有張指揮領兵出海,
默祝神妃保佑,果得顯應,由泉裝載大料來湄洲,構 一閣於正殿之
左,名曰「朝天閣」。 ●藥救呂德 洪武十八年(一三八五),興化衛
官呂德出海守鎮,得病甚危篤,求禱於神。夢 寐間見一神女儼然降
臨,命侍鬼持丸藥,輝瑩若晶珀,示之曰:『服此當去二 豎』。正接
而吞之,遽寤,香氣猶藹藹未散。口渴甚,取湯飲,嘔出二塊物,頓
覺神氣爽豁,宿痾皆除,遂平複如初。是夕夢神云:『疇昔之夜,持
藥而救爾 者,乃慈悲觀音菩薩示現也,當敬奉大士』。呂德感神靈赫
奕,遂捐金創建觀音 堂于湄嶼。 ●廣州救太監鄭和 永樂元年(一四○
三),欽差太監鄭和等往暹邏國。至廣州大星洋遭風,舟將 覆。舟工
請禱於天妃。和祝曰:『和奉命出使外邦,忽遭風濤危險,身固不足
惜,恐無以報天子,且數百人之命懸呼吸,望神妃救之』!俄聞喧然
鼓吹聲, 一陣香風颯颯飄來,宛見神妃立於桅端。自此風恬浪靜,往
返無虞。歸朝複 命,奏上,奉旨遣官整理祖廟。和自備寶鈔五百貫,
親到湄嶼致祭。 ●舊港戮寇 永樂三年(一四○五),欽差太監等官往
西洋,舟至舊港,遇萑苻截劫,順流連 艦而至,勢甚危急。眾望空羅
拜,懇禱天妃。忽見空中旌旗旆旆雲巔,影耀滄 溟,突而江流激浪,
幟轉帆翻,賊艘逆潮不前。官兵忽蕩進上流,乘潮揮戈逐 之,一擊而
魁首就俘,再擊而餘孽遠潰。自此往返平靜。回京奏神功廣大,奉 旨
著福建守鎮官整蓋廟宇以答神庥。 ●夢示陳指揮全勝 永樂七年(一四
○九),欽差太監統領指揮陳慶等往西洋,賊覘知,垂涎寶貨, 率數
十艘於中流截劫。正值上風,奔流如飛,我舟被困,眾俱股慄。陳慶
曰: 『奉君命到此,數百人在茫茫大海中,須決雌雄,尚可生還。騎
虎之勢,安可 中下?兵法謂置之死地而後生,正在今日』!眾曰:
『不若拜禱天妃』。慶從 之。是宵,陳慶夢神語曰:『今夜風急,可
乘昏霧,溯流而上,翌日佐爾一帆 風,殲此醜類』!慶以告內使,棹
向前。比曉,已居上流。賊逆風不得進。我 舟離賊已遠。眾欲遠遁。
慶複曰:『長江萬里,西國迢遙,回首不見家山。彼狡 爾鯨鯤,豈能
忘情於我?若飄泊偷安,恐賊黨出沒煙波,終入其網。今風信順 便,
殆神授也,急擊勿失』!遂勵兵奔衝而下。遠望神儼現空中,閃爍如
虹如 電。賊駭愕。風急舟騁,賊篷被官桅倒插破裂。陳慶揮刃越舟,
賊首投水,鉤 而俘之,餘悉就擒,獲貨物軍器無算。內使及陳指揮率
眾叩謝神妃曰:『反敗為 功,轉禍為福,再造之德,山高水深』。複
命奏上,奉旨褒嘉,委官重置廟中器 皿,親齎詣廟致祭。 ●助戰破蠻
永樂十八年(一四二○)正月,倭寇哨兵渡海,欽差都指揮張翥統領
浙江定海 衛水軍防禦,距海相持。日本慣習水戰,分舟師據海口。我
師樵汲道絕,兵士 困甚,同叩禱天妃,拜請水仙。忽波心撼激,賊舟
蕩漾浪中,撐東湧西,我舟 與賊船首尾相擊。半晷間,賊篷繂繩斷,
我舟中一兵披髮跳躍大呼曰:『速越舟 破賊』!翥發令曰:『此神所
命,先登者重賞』!遂奮勇衝殺,擒獲甚多,其投 水死者不計其數;
全收破蠻之功。事聞於上,奉旨遣御史劉麟、內官孔用、唐 貞詣廟致
祭,送長生鹿二對。 ●東海護內使張源 永樂十九年(一四二一),欽
差內使張源往榜葛剌國。於鎮東海洋中,官舟遭大 風,掀翻欲溺。舟
中喧泣。源急叩天妃求佑。言未畢,忽見狂風旋舞,中有赤 旆飛揚。
眾疑其不祥。須臾,風息浪平,舟人踊躍歡忭,皆曰:『頃赤旆飛
揚, 實神靈返颶之力』。及自外國還,特制袍幡詣廟拜謝。 本年,
太監王貴通等又奉命往西洋,禱祝顯應。奏上,遣內官修整祖廟,備
禮 致祭。 ●琉球救太監柴山 洪熙元年(一四二五)四月,欽差內官
柴山往琉球,載神香火以行。至外洋, 一夕,雲霧晦冥,山方假寐,
夢神撫其幾曰:『若輩有水厄,當慎之!吾將為汝 解』。及寤,不敢
明言,只嚴戒舵工加謹。正揚帆而進,突陰霾蔽天,濤翻浪 滾,咫尺
不相辨,孤舟飄泊於洪波之中,桅檣顛倒,舟中墜水者數人。舵工急
取大板亂擲水中,數人攀木而浮,隨波上下,呼天求救,哀聲震天。
迨薄暮, 見燈光自天而來,風倏靜,浪倏平,舵工函撥棹力救,墮水
者爭攀附登舟,感 慶再生之賜。回京奏上,奉旨遣官致祭,拜答神
功。 ●庇太監楊洪使諸番八國 宣德五年庚戌(一四三○)十二月,欽
差太監楊洪統領指揮千百戶及隨從人 等,駕船大小三十隻,裝載彩
幣,賞賜阿丹、暹羅、爪哇、滿剌加、蘇門答 刺、木骨都束、卜剌
哇、竹步八國,虔恭奉祀神妃,朝夕拜禱保佑。一日,舟 至中流,天
日清霧,遠望大嶼橫峙海中,上多怪石,錯生海物。眾曰:『舟中沉
鬱已久,盍登岸少舒』。各奪磴而上。又見旁有小磯,一女子攜筐採
螺蜃,競赴 磯迫視之。洪恐其肆慢,趨前呵止。女子忽不見。回首大
嶼已沒,方知前所登 嶼,即巨鰲浮現,其美女乃天妃現身救此數十人
也。各叩首謝。歸奏上,奉旨 齎香致祭。 ●托夢除奸 嘉靖中,奸臣
嚴嵩當權,殘害忠義。御史林公諱潤,擬附本糾之。夜間草槁未 畢,
乃曰:『似此必無兩靜,但含默非吾初志』。假寐幾上,夢神妃語之
曰:『權 奸蠹國,公報主忠誠,必俞所奏,當不負厥梗直』。寤而嘆
曰:『奸臣播虐忠 良,神人共憤,天妃乃有除奸之靈!若此本得旨,
當廟祀血食春秋』。果章奏而 帝俞允,遂建廟於涵江東卓地面,以答
英光。 ●妝樓謝過 天啟乙丑、戊辰(一六二五、一六二六)間,萑苻
草寇李魁奇出沒南溟,結伙 入吉了抄掠,複迤𨓦到賢良港。港人擁神
像江頭,示以神靈梓鄉,冀免擾害。 神乃顯夢於酋長曰:『而焚掠了
城,為禍酷烈,今尚欲困吾父母之邦,若不速 退,將殲爾類』!仍嘯
聚弗去。俄而狂飆躍浪,蕩散其舟,大舡沉溺,餘者淪 落波中。自是
悔罪乞宥,風且不靜。願起蓋梳妝樓一座,並塑聖像以謝過,乃 得風
靖。遂移舟出港,備牲醴、香花到湄,買置木料,裝運前來建造,俯
伏叩 拜。 ●清朝助順加封 康熙庚申年(一六八○)二月十九日,舟師
征剿,駐崇武,與敵對壘。夜夢天 妃告之曰:『吾佐一航北汛,上風
取捷,隨使其遠遁』。次日,果得北風驟起, 敵遂披靡,大敗而退。
至二十六日舍廈門入台灣。內地海宇,自是清寧。萬將 軍大感神助,
立即具本奏神保佑之力。聖上甚慰陰功,欽賜御香、御帛,差官 齎詔
到湄廟加封致祭。 ●起蓋鐘鼓樓及山門 大總督姚奉命征剿,以海道艱
虞,風波險阻,不易報效,中心懇摯,極力圖 維,素信神靈赫濯,禱
應如響,懇祈陰光默佑,協順破逆。於康熙二十一年 (一六八二)差
官到湄洲祖廟,就神前致祝許願,俾不負徵剿上命,即重修宮 殿,答
謝鴻庥。乃於二十二年(一六八三)三月二十三日天妃悅旦,特委興
化 府正堂蘇到湄廟設醮致祭,隨帶各匠估置木料,擇吉起蓋鐘鼓二樓
及山門一 座;宮宇由是壯觀。 ●大闢宮殿 大總督姚時議征剿,雖不
辭責重任大之艱,而逾塹越滄,不無風波飄蕩之慮。 一片忠誠孚格,
惟恃神靈默相。以故天威一震,寰服人心,於康熙二十二年七 月初
旬,台灣果傾心向化,舉島輸誠。總督捧頒恩敕前至台灣,因少西北
正 風,又恐逗留詔命,自福省放舟,於八月二十三日親到湄洲,詣廟
具疏神前, 虔祝順風,願大闢殿宇,以報神功。於是神前拈;。准將
東邊朝天閣改為正 殿。舟尚未開,二十五夜見船上放光,深感神明有
赫,即捐金付興防廳張同、 同知林升估價置買木料,乃邊朝天閣另為
起蓋。遂擇吉建造正殿,已經安基豎 梁,緣興防廳張丁艱謝事。 總
督祈禱疏文 福建總督姚啟聖謹抒愚衷、上請天妃主裁而言曰:四海廣
闊,惟神是憑;風濤 順逆,亦惟神是主。是神之權大、德尊,適足侔
天地而並日月也。今者,荷神 有靈助,除六十年猖狂之大寇,竟停
五、六月台颶之大風,除生靈之大害,立 朝廷之殊功。啟聖得以安享
太平,皆尊神之默佑也。今啟聖親總舟師,遴福寧 州總兵黃大來、參
政道劉仔捧頒恩敕前至台灣,因尚少西北正風,是以越廟求 神,冀借
一帆,早到台地。啟聖百叩稽首之下,見廟貌尚有未妥,寸心甚為不
安;況正殿朝南,而朝天樓、山門各俱西向、亦非宜於神靈之所憑依
也。今啟 聖議以正殿既朝南,則朝天樓、鐘鼓樓、山門俱宜開闢朝
南。此為一議。如神 意定於朝西,則門山、鐘鼓樓止須蓋完,惟將朝
天樓升高改為正殿,而以原廟 為神寢宮。此又為一議。若神意不准二
議,原欲仍舊向,啟聖亦惟神是聽,不 敢有違。啟聖既經目擊,不敢
吝惜,敬陳三議,分列三闢,惟神裁定!
●托夢護舟 隨征同知林升同總兵官游澎奉委往撫台灣,於康熙二十
二年九月初五日由湄洲 放洋,初六晚至台灣。十五日自彼開駕,而十
八夜夢天妃在船;有四人戴紅帽 從水仙門而上,問其所來,答曰:
『舟船有厄,將為爾護』。十九早,舟過柑桔 嶼,舟次擱淺,舵折四
尺,將溺,眾驚懼,投拜神前,懇求庇佑。倏見天妃現 身降靈保護,
乃得平穩。十九晚收進八罩,報複成功。總督慰甚。同知林升到 家虔
誠答謝。 ●湧泉給師 靖海將軍侯施於康熙二十一年十月奉命征剿,大
師雲屯於平海。此地斥鹵,樵 汲維艱。只有神宮前小井一口,甚淺,
當炎天旱候,尤為枯竭;數萬軍取給炊 爨,弗繼。將軍侯乃祝諸神,
以大師札住,願藉神力,俾源源可足軍需。禱 畢,而泉水湧溢,真不
異耿恭拜井之奇。因是千萬軍取用不竭。爰額之曰「師 泉井」,作師
泉志以著神庥。 師泉井記 今上御極之二十一載壬戌孟冬,予以奉命
統率舟師,徂征台灣。貔虎之校,犀 甲之士,簡閱而從者三萬有餘。
眾駐集平海之澳,俟長風,破巨浪,以靖掃鮫 窟。爰際天時暘亢,泉
流殫竭,軍中取汲之道,遙遙難致。而平澳遷徙之壤, 介在海陬,昔
之井廛,盡成堙廢。始得一井於天妃行宮之前,距海不盈數十 武,漬
鹵浸潤,厥味咸苦。其始未達深源,其流亦複易罄。詢諸土人,咸稱
是 井曩僅可供百家之需,至隆冬澤愆水涸,用益不贍。允若茲,則三
軍之士所藉 以朝饔夕餐者果奚恃歟? 予乃殫攄誠愫,祈籲神聰。拜
禱之餘,不崇朝而泉流斯溢,味轉甘和。綆汲挹 取之聲,晝夜靡間,
歕湧滋溉,略不顯其虧盈之跡。凡三萬之眾,咸資飲沃, 而無呼癸之
慮焉。自非靈光幽贊,佐佑戎師,殲殄妖氛,翼衛王室,未有弘闡 嘉
祥,湛澤汪濊,若斯之渥者也。因鐫石紀異,名曰師泉,昭神貺也。
在易,地中有水曰師。師之行於天下,猶水之行於地中;既著容民畜
眾之義, 必協行險而順之和。是知師以眾正,乃克副大君討貳撫順、
懷柔萬邦之命。而 揚旌海外,發軔涯涘,神異初彰,闓惠覃布,誕惟
聖天子赫濯之威,以致百靈 效順,山海征奇,亶其然乎! 昔貳師劍
刺大宛之山,而流水溢出;耿恭拜禱䟽勒之井,而清泉奔湧;並能拯
軍士於渴乏,著萬里之奇功。乃今井養不窮,三軍獲福,予之不敏,
曷以答茲 鴻嘉之賜哉!是用勒之貞氏,以志不朽云。
●燈光引護舟人 將軍侯施於康熙二十一年十月舟次平海。因謀進
取,於十二月二十六夜開船。 一宵一日,僅到烏丘洋,因無風不得
行,令駕回平海。未到澳而大風倏起,浪 湧滔天,戰艦上下,隨濤浮
漾外洋,天水淼茫,十無一存之勢。次早風定,差 船尋覓。及到湄州
澳中,見人船無恙。且喜且駭曰:『似此風波,安得兩全』? 答曰:
『昨夜波浪中,我意為魚腹中物矣!不意昏暗之中,恍見船頭有燈
籠,火 光晶晶,似人挽厥纜而徑流至此』。眾曰:『此皆天妃默
佑』!即棹回報上。將 軍侯因於康熙二十二年正月初四早,率各鎮營
將領赴湄致謝,遍觀廟宇,捐金 調各匠估價買料,重興梳妝樓、朝天
閣,以顯靈惠。
●澎湖神助得捷 康熙二十二年六月內,將軍侯奉命征剿台灣。澎湖
系台灣中道之衝,萑苻竊 踞,出沒要津,難以徑渡。侯於是整奮大
師,嚴飭號令。士卒舟中,咸謂恍見 神妃如在左右,遂皆賈勇前進。
敵大發火炮,我舟中亦發大炮,喊聲震天,煙 霧迷海。戰艦銜尾而
進,左衝右突,凜凜神威震懾,一戰而殺傷彼眾,並淹沒 者不計其
數。其頭目尚踞別嶼,我舟放炮攻擊,遂伏小舟而遁。澎湖自是肅
清。先是,未克澎湖之時,署左營千總劉春夢天妃告之曰:『二十一
日必得澎 湖,七月可得台灣』。果於二十二日澎湖克捷,其應如響。
又是日方進戰之頃, 平海鄉人入天妃宮,咸見天妃衣袍透濕,其左右
二神將兩手起泡,觀者如市。 及報是日澎湖得捷,方知此時即神靈陰
中默助之功。將軍侯因大感神力默相, 奏請敕封,並議加封。奉旨:
神妃已經敕封,即差禮部郎中雅虎等齎禦香、御 帛到湄,詣廟致祭。
時將軍侯到湄陪祭,見佛殿僧房尚未克竣,隨即捐金二兩 湊起。
●琉球陰護冊使 康熙二十二年,欽差冊封琉球,賜蟒玉正一品汪、
林等官時在福省,於六月二 十日諭祭天妃於怡山院。是時東風正猛,
不意行禮甫畢,旗幟忽皆北向,遂解 纜而行。所有應歷水程,悉若飛
渡而下,才二晝夜即到馬齒山,遽至那霸港, 直達迎恩亭前。琉球之
人皆謂從來封駕未有若此飛渡而來。迄夫典禮告竣,開 駕而回,狂濤
震撼,巨浪滔天。舟中人皆顛覆,煙灶等物盡委逝波,茫無彼 岸,誠
萬難獲全。天使官肅將簡命,共籲神妃求佑:『返節無恙,當為奏請
春秋 祀典,永荷神庥』!虔禱方終,神應如響。黑夜中漂泊,眾見舟
竿上有二燈籠 光焰在前。時束桅鐵箍巳斷十三,桅應散而尚全;系篷
之頂繩斷不可續,篷宜 墮而猶懸:桅拴裂逾尺,桅應倒而仍柱。船不
及壞,因急駛往歸閩海港。中使 □□□□□複□奏請春秋(以下殘闕十餘
字)。
附錄 天上聖母源流因果
●第一章求佳兒大士賜丸 天後,林氏女也。先世自唐迄宋,代有功
績,世勛承襲,遂家於莆田。父惟愨 公尤好善樂施,敬奉大士,年四
旬餘,止一子,焚香祝天,願得佳兒。己未六 月,夜夢大士告曰:
『上帝式佑爾善』;授以丸藥,遂孕。
●第二章聞異香我後降世 宋太祖建隆元年庚申三月二十三日,方
夕,紅光射室,異香氤氳,乃誕天後, 為惟愨公第六女也。
●第三章遇道人秘傳玄訣 後生而聰穎。八歲悉解文義,十歲即好佛
經。十三歲,遇老道士曰:『若具佛 性,應得度入正果』;授以玄微
秘法。
●第四章窺古井喜得靈符 後年十六,時與諸女游,窺古井,忽見神
人捧銅符一雙,上有仙官擁護;群女 駭奔,後受之不疑。自此法力玄
通,屢顯神異。
●第五章運神機停梭救父 時值九秋,後父、兄兩舟濟海,西風正
急,波濤震奔。後方織,忽心動,遂閉 睫神馳,手持梭,足踏機軸,
若有所挾而恐失之之意。
●第六章聞疾呼失柁哭兄 機上凝神,毋怪急乎。後醒而泣曰:『父
得保全,兄已沒矣』!始知頃所足踏者 父之舟,手持者兄之舵。呼醒
舵摧,竟不獲救。
●第七章資民食瀉油生菜 湄有小嶼,在旁流中。後游其地,適母遺
以菜子油,後即傾地;皆抽菜甲,燦 然青黃,布滿山塍。至今四時不
絕,遂名為「菜子嶼」。
●第八章渡滄海指席為帆 一日,後欲渡海,舟楫不整,舟人難之。
後指草席曰:『無妨,即此可憑矣』。 懸之竿,若鳧鷗之出沒,追狂
飆而鼓棹,破巨浪而旋槎。觀者驚為飛渡。
●第九章救舟人小草成杉 嶼西有山曰夾山,礁石林立,船不敢近。
一日,風濤震撼,舟人哀號,人莫能 救。後擲草數根,化成大杉排
空,舟得以附焉。
●第十章解旱災甘霖沛野 後年二十一,莆田大旱,父老咸稱『非神
姑莫解』。尹詣請,許之,擬壬午申刻 當雨。至期,大沛甘霖,遂獲
有秋。人皆歡呼頌德。
●第十一章策鐵馬代楫渡江 一日,渡江無楫,遂策簷前鐵馬,快若
奔騰,人駭為青驄。行水上天,馬驟空 中,只不見其解鞍嘶秣耳。
●第十二章收神將演咒施法 後年二十三,收順風耳、千里眼為將。
先是二神為祟西北,民間苦之,求治於 後。後曰:『此金水之精,乘
旺所鍾,我當以火土克之』。乃演咒施法,二神遂 懼而皈依焉。今俱
封為將軍。
●第十三章率水族龍子來朝 東海多神怪,後乃命枻中流,風日澄
霽,中見水族駢集,龍子鞠恭於前。後敕 免朝,即退。至今天後誕
辰,猶然慶賀;是日漁者不敢施罟下網。
●第十四章投法繩晏公歸部 有晏公者,浮海為怪。後先施法力制
之;雖仗神威,未能誠服。後又逞色變 龍,興濤滾浪,來犯後舟。後
投下䋖繩,隨攝隨粘,牢固難解,始懼而伏罪, 後囑曰:『東溟險
阻,爾當護民』。收為部下總管。
●第十五章莆田尹求符救疫 歲祲疫,莆田縣尹合家病篤,吏告以請
救,尹乃齋戒詣求。後曰:『此天災,何 敢妄干;念其仁慈素著,代
為懺悔』。取菖蒲九節,書符貼,並煎飲之,立瘥。 自此名徹寰中
矣。
●第十六章高里鬼現相投誠 高里鄉突有陰怪為祟。人咸求治於後。
符咒貼處如鳥飛遁。後跡其穴,掃除, 見一團黑氣中惟鷦鷯小鳥踏空
而墜,化為枯發;焚之,即現本相,乃一小鬼 也,叩拜投服焉。
●第十七章逐雙龍春夏雨止 後年二十六歲,自春至夏,霪雨不止。
省官奉天子命,所在祈禱。莆人詣請於 後,後允為邑造福。後見白虯
奔躍,二龍游蕩,乃畫靈符鎖住白虯,遽有金甲 神人逐二龍遁。莆即
大霽,秋且告稔。奉旨致幣報功。
●第十八章驅二孛南北津通 吉蓼城西有橋跨海,南北通津。忽一
日,怪風掃地,橋柱盡折,行人病涉焉。 後知二孛為祟,遙見黑氣衝
霄,即演靈術驅之。人渡如故。
●第十九章破魔道二嘉伏地 時有二魔:一曰嘉應,一曰嘉佑。或於
荒丘中,或於巨浪中為害。或於客舟中 流現赤面金裝,當前鼓躍。後
化寶舟,出沒波濤間,嘉佑舍客舟而就後船。後 以咒壓之,遂懼伏。
嘉應從山路犯後,後拂塵霾,任其騰躍,終不越故處,遂 悚懼而遁。
然魔心未淨,後歲複作,乃得歸正。
●第二十章証仙班九日升天 宋太宗雍熙四年丁亥重九日,同諸姊登
高。於湄峰山巔,恍聞空中絲管韻葉, 八音齊奏,仰見鑾輿翠蓋,儀
皂幢旛,雜踏而至。後乃跨雲而上,眾咸欷歔驚 異。俄而彩雲布合,
不複見矣。嗣後屢呈靈異。相率立祠,號曰「通賢靈女」。
●第二十一章示地利創始建廟 宋高宗紹興二十六年丙子,以郊典特
封「靈惠夫人」。次年秋,神來相宅,取莆 城東之水示民曰;『白湖
夢示章、邰二族』。丞相陳後卿聞之,驗地果吉,興工 創建廟宇。
●第二十二章驅水怪咸願捐金 商人三寶貨船忽椗膠不起。舟人入
水,見一怪坐椗。各驚惶,詣祠祈禱。恍見 神後飄渺前來,怪即遁,
椗立起。三寶許願捐金,改觀廟貌。
●第二十三章憑枯楂聖墩立廟 宋哲宗元佑元年丙寅,莆東有墩常現
光,跡之,一枯楂也。漁人拾之歸,楂自 還故處。再試亦然。鄉人獲
夢,知楂為神所憑。制干支公聞之,募建廟,號為 「聖墩」。
●第二十四章得銅爐錦屏建祠 哲宗元符初,莆之南有地曰楓亭,其
溪通津達海。戊寅潮長時,漂一銅爐,寶 光陸離。楓人收之,同夢後
囑。爰備香花,奉至錦屏山下建祠以祀。
●第二十五章護糧船額頒靈惠 元文宗至順元年庚午春,糧船開洋遇
風,桅檣漂蕩,戰慄哀號。忽祥雲靄靄, 見空中朱衣擁蓋,燈火垂
光。既而風息,得獲全安。奉旨賜額曰「靈惠」。
●第二十六章療民疫井號聖泉 宋孝宗乾道二年春,大疫。神降於民
李本家言曰:『白湖旁,可鑿泉得飲,以除 疫病』。果然,泉味清
冽,飲如甘露,朝吸而夕瘥焉。人感回生之功,甃為井。 號曰「聖
泉」。
●第二十七章答神庥千秋崇祀 海邦履險,臨於不測之機;神靈呵
護,應於非常之際。或化蝴蝶、蜻蜓,繞桅 檣而垂引;或令瑞禽、燕
雀,示舟楫以無虞。至於明燈璀璨,慈悲靈濟於若隱 若現之間,瑞氣
氤氳,顯赫神通乎可望可即之下,總在一誠可格,未可思議名 言者
也。
●第二十八章助皇師一將成功 孝宗淳熙十年癸卯,福建都巡檢羌特
立奉命征剿溫、台二府草寇,相持意怯, 共祝神靈垂庇。恍見神立雲
端,旗幡飛飆,儼如虹電。我師乘風騰流,賊舟在 後,急撥棹擊之,
獲其首而擒其黨。請於朝,更加封焉。
●第二十九章止陰潦轉歉為豐 宋寧宗慶元四年戊午,甌閩霪潦,民
不聊生。禱於神,夢曰:『人多不道,上天 困此一方耳。予念若輩恭
虔,奏請矜赦』。越三日大霽,且錫有秋。
●第三十章除水患收魔為將 後念嘉應未歸正道,究為妖孽,乃化一
舟乘之。應見,即衝潮登舟,坐於桅 前。及岸,見後立船頭,應乃倉
皇請宥,並收為將。
●第三十一章明前跡神槎再現 莆東寧海橋頭,眾方渡,見光中縹
渺,浮一古木,其狀絕異。順流而前,人莫 之識。至夕,鄉人得夢,
知當年顯應神槎雲。
●第三十二章助討逆合家受封 大奚寇作亂,閩師討之。賊勢甚銳,
眾請香火以行,得藉神威,返風旋波,擒 其渠魁,掃蕩無遺。具奏陰
佑大勛,詔議加封,合家榮贈。寧宗慶元六年,朝 廷以神妃護國庇
民,功參玄造。人本乎親,慶自先貽。於是頒詔,封妃父為 「積慶
侯」,又改封「威靈侯」。又以顯赫有裨民社,加封為「靈感嘉佑
侯」。母 王氏,封「顯慶夫人」。兄封「靈應仙官」。神姊封為「慈
惠夫人」。
●第三十三章顯聖威金人碎首 宋寧宗開禧改元乙丑,金人僕散揆潛
渡淮,王師啟行,夢神告曰:『吾當助 威』。初戰花靨鎮,再戰紫金
山,三戰合淝,皆雲端顯聖。王師賈勇,賊將披 靡,大炮碎其酋長,
斬馘無算。上聞,加封「靈惠」。
●第三十四章率神將周寇亡身 寧宗嘉定改元戊辰,草寇周六四犯
境。災後,人民無賴,既困赤地,遂入綠 林,劫掠日盛。尉師襲之,
夢神示助。越四日入境。忽見空中有旗幟之影,賊 驚懼退舟,遽衝礁
擱淺。尉師駕艇追之,獲其首,餘凶悉平。奏上加封。
●第三十五章錢塘江遏水成第堤 宋理宗嘉熙元年,錢塘潮決潰堤,
湧波為患。郡人號祝。忽望艮山祠若有限 拒,水勢倒流,人得以施版
築,遂獲堤成。
●第三十六章興泉郡招商買米 理宗寶佑改元,興、泉旱,飢困弗
支,求禱者絡繹。神乃示夢云:『若無憂米即 至矣』!因又示夢廣商
云:『興、泉苦飢,速往可倍利』。舶集價平共相怏怏。 人語感夢之
由始悟救二郡生靈也。
●第三十七章廟廊下火焚惡黨 理宗開慶改元己未賊陳長五兄弟三人
殺掠興、泉、漳三郡。八月,賊 三舟入湄島,登岸,據廟裸體偃臥。
神火燒之,退遁舟中。忽而晦冥,誘之出 港,擱淺。憲使王鎔會兵擊
之,至福清俘磔,乃神助之力也。詔複加封「顯 濟」。
●第三十八章波濤中默佑漕船 元文宗天歷元年,運漕入海遇風,七
晝夜不息。舟人哀禱。見燈光從 空掩映,異香 馥鬱,遂爾波恬浪
靜。奉旨遣官致祭浙、閩等處廟一十五處,並加徽號。
●第三十九章現火光明師無恙 明太祖洪武七年,泉州衛指揮周坐領
戰船哨捕,遇風擱淺。舟人環呼神救。忽 見神火熒煌,俄而巨浪送船
進港。指揮周立廟泉州以報德。
●第四十章授丸藥呂德回生 洪武十八年,興化衛呂德疾篤,夢神授
丹,令吞之,嘔物二枚,遂痊。複夢告 曰:『救爾者,乃大士示現,
爾當敬奉之』!德乃捐金建觀音堂于湄。
●第四十一章聞仙樂鄭和免險 明成祖永樂元年,欽差太監鄭和等往
暹羅,經大星洋,舟將覆。禱之。俄聞天 樂浮空,異香縹渺,宛見神
立桅左,返風滅浪,乃得挂帆。奏請遣官致祭。
●第四十二章過小磯楊洪脫災 明宣宗宣德五年。欽差太監楊洪等齎
賜物於諸番。一日,至中流,見大山橫 峙。舍舟登山,以舒沉鬱。見
旁一小磯,有女子攜筐採螺,因往觀之。其大山 忽不見。大山者,巨
鰲也。方知神後點悟云。
●第四十三章草彈章托夢除奸 明世宗嘉靖間,嚴嵩專權誤國。御史
林潤擬糾彈草。假寐間,夢神告曰:『公心 忠誠,本上必准』。後果
然。遂建廟於涵江。
●第四十四章憫軍行流泉解渴 康熙二十一年十月,靖海將軍侯施奉
命征剿,師屯平海,地多斥鹵,樵汲維 艱。惟神宮前一小井,炊爨弗
繼。將軍求禱之,而清泉泛溢,不異耿恭拜井之 奇。爰曰「師泉」,
作志以著靈顯。
●第四十五章平澎湖陰麾神將 康熙二十二年六月,將軍侯奉命征
台,路過澎湖。萑苻竊踞要津,難以經渡。 於是整奮大師,連發火
炮。恍見神麾旗率將助戰,遂克共眾。欽差齎禦香帛致 祭。
●第四十六章過𥑠硈夢佑王臣 康熙二十二年,總督姚既基台灣。有
隨征同知林升、總兵游澎自台回,夢帶紅 帽四人至前。問所從來。
曰:『護爾』。及過𥑠硈,舵折將覆,竟無虞;並見天 後護焉。
●第四十七章晝夜順風護冊使 康熙二十二年,欽差汪楫、林麟𦨭等
冊封琉球。正東風甚猛,諭祭於怡山院, 甫畢,而南風三畫夜,直達
迎恩亭。琉球駭為飛渡。複命,奏請春秋祀典。
●第四十八章春秋崇祀沛皇恩 康熙五十八年己亥。冊封琉球使海
寶、徐葆光等往返海道,風少不順,則祈禱 天後,即獲安吉。後複
命,奏准春秋祀典。
●第四十九章佑漕船利運天津 道光六年,江南漕船從上洋海運。二
月二十六、七等日,西北風暴大作,勢甚 猛烈。漕船正抵黑水大洋,
迭遭風暴,各船齊下太平筐䉡,隨風漂淌,歷數日 夜。危急之頃,若
有神助。往返水程幾萬里,一千餘號漕船齊抵天津,米石毫 無漂失。
在船舵工、水手二、三萬人並未損傷一名,尤為向來未有之事。巡撫
陶奏請,海運化險為平,顯應尤著,加封「安瀾利運」扁額。
●第五十章送冊使奉詔中山 道光十九年己亥,冊封琉球國正使翰林
院修撰林鴻年、副使翰林院編修高人鏗 途中兩次猝遇風暴。正在汪洋
萬頃之中,人力莫施,舉舟惶悚。虔誠祈禱,皆 獲化險為夷。奏請加
封「澤潭海宇」四字。
●第五十一章警憊兵顯靈上海 道光二十一年,英夷犯浙,蘇松戒
嚴。有客兵駐札上海潮州會館,裸臥神前, 穢褻殊甚。七月十五夜,
兵於夢中似有人擊,駭奔呼救。鄰人亦驚起。但見黑 衣人無數,提械
追擊。從此兵皆叩頭悔罪焉。
天后本支世系考
唐天子詹事諱披,生九子,皆官刺史,世稱九牧。第六子唐邵州刺
史,謚忠 烈,諱蘊,生子諱願。願生四子。第三子圉,仕閩王審知為
州牧,即後之高祖 也。子保吉,棄官隱於賢良港。保吉生子孚,為福
建總管。孚生惟愨,為都巡 官。惟愨生洪毅及六女。後,其第六女
也。洪毅生一子,傳數世而成巨族,皆 居於港。現分為六房。其祖祠
所奉,乃本支之先代也。所修家乘,昭穆亦複秩 然。世有以後尊榮,
奄為己房所出,將其先代而改易之。按後之高曾祖父兄皆 出仕,其父
兄又經敕封,奚堪泯沒?當年端州刺史公房提學(諱麟𦨭)所作序
文,已昭然可考,毋煩置辨。又有云:後父名願,不應犯六世祖諱;
細思五代 遞及宋初,紛紛多事,且托處海濱,想亦末計及此。今閱其
祖祠神主及其族 譜,皆稱惟愨,則相傳名願者非。
賢良港祖祠考
港之祖祠,前代已有建立。明永樂十九年,上以天後屢著靈異,聞
祖祠圯壞, 特命內官赴港修整。及嘉靖時,倭人擾攘,民居盡被毀,
獨祠不壞。祠內供奉 始祖唐邵州刺史公暨後之高曾祖父兄並後寶像。
順治辛丑年,奉文遷界,子姓 將神主寶像暫寄於涵江天後宮,祠遂
圯。康熙二十年,展界複回,鄉人同子姓 鳩工建造,赴涵請歷代神主
供於寢堂,寶像供於中廳。春秋二祭,皆在於斯。 世傳祠內寶像系異
人妝塑,各處供奉之像皆不能及。以遷界寄奉涵江。至複界 時,子姓
到涵請回。涵之里人不肯。乃同詣神前卜筊,得九十九聖筊。涵江裏
人遂備船,用彩亭鼓吹,送寶像登舟。船甫開,雷雨驟至,隨船之
後,而船不 沾濡。既入祠,雷雨大作,水溢堂廡。鄉族之人不能行
禮,口祝於後。雷雨實 時屏息,風掃地乾。瞻拜者莫不詫異。嗣後凡
有到祠請香火者,多有雷雨隨 之,至今猶然。
湄洲廟考
天后於宋雍熙四年九月九日到湄洲飛升,里人立祠祀焉。僅落落數
椽,而祈禱 報賽殆無虛日。後有商人三寶感戴神庥,捐金創建廟宇。
宋仁宗天聖中,神光 屢現,荷庇佑者鳩資廣大其地,廟廡益增巍峨。
明洪武七年,指揮周坐重建寢 殿、香亭、鼓樓、山門,複塑寶像。又
有張指揮建一閣於正殿左邊,名朝天 閣。永樂初年,詔擴大廟宇,不
時致祭。宣德六年,遣官修整廟宇。國朝康熙 二十二年,總督姚起蓋
鐘鼓樓山門,又將東邊朝天閣改為正殿。將軍施建梳妝 樓及朝天閣、
佛殿、僧房,廟宇由是壯觀。 按天後宮廟建立者多,即莆田一邑,已
有平海、涵江、莆禧、黃石、吉了、白 湖、聖墩、江口及城中之文峰
宮、西岩等處,不可盡述。茲以湄洲為後升天之 地,故獨詳焉考之。
冊使顯應記九則
嘉靖十三年,冊使陳侃、高澄舟至姑米山,發漏;呼禱得塞而濟。
歸值颶風, 桅檣俱折,忽有紅光燭舟,乃請筊起柁,又有蝶雀示象。
冠服禱請立碑,風乃 弛。還,請春秋祀典。
嘉靖四十年,冊使郭汝霖、李際春回閩日,颶將發,有二雀集舟之
異。及颶 發,失柁,汝霖等為文以告,風乃息。更置柁,一異鳥集桅
不去。
萬歷七年,冊使蕭崇業、謝傑針路舛錯,且柁叶失去、虔禱之次,
俄有一燕、 一蜻蜓飛繞船左右,遂得易柁。
萬歷三十年,冊使夏子揚、王士楨舟過花瓶嶼,無風而浪。禱於
神,得風順 濟。歸舟柁索四斷。失柁者三,大桅亦折。水面忽見神
燈,異雀來集,東風助 順。
崇禎元年,冊使杜三策、楊掄歸舟颶作,折柁牙數次,勒索皆斷。
舟中有奇楠 木,高三尺。三策等捐千金,購刻神像。俄有奇鳥集檣
端,舟行若飛,一夜抵 閩。
本朝康熙二年,冊使張學禮、王垓歸舶過姑米,颶作,桅左右欹,
龍骨半折。 忽有火光熒熒,霹靂起風雨中,截斷僕桅,柁旋不止,勒
索皆斷。禱神起柁, 三禱三應。易繩下柁,有一鳥若雁,綠嘴紅足,
集戰台上。舟人喜曰:『天妃遣 來引導也』!遂達定海。
康熙二十二年,冊使汪楫、林麟𦨭歸舟,颶三晝夜,舟上下傾反,
水滿艙中。 虔禱天妃,許請春秋祀典。桅篐斷而桅不散,頂繩斷而篷
不落,與波上下,竟 保無虞。
八
康熙五十八年,冊使海寶、徐葆光多用卯針,幾至落漈。虔禱得改
用乙辰針, 又筊許二十八日見山;果見葉堅。複禱得西北風,一夜抵
港。歸舟至鳳尾山, 旋風轉船,篷柁俱側;呼神複正。至七星山,颶
作椗走,幾觸礁;呼神獲免。
乾隆二十一年,冊使全魁、周煌舟泊姑米候風,忽颶台作,連三晝
夜,椗繩盡 斷,龍骨觸礁而折,底穿入水。呼籲之頃,眾見神火起於
桅頂,焚招風旗而 落。又海面燈光浮來,若煙霧籠罩狀,船遂牢擱礁
上,得不沉溺,以次獲濟登 岸。歸舟至石盤,阻霧不進。禱得見山。
既起椗,霧複合,風雨雷電交作,落 帆葉不下,舟欹甚。再禱再霽,
賴以安行。
述異記二則
邇年有洋船失風,飄至一島,金光耀目,不能正視。抵岸,乃金
也。岸旁沙石 皆紫金。同舟者甚喜,競持錘鑿取之。俄見山頂一人,
金冠、金甲、朱褌、跣 足、舞劍而來,疾若飛,逼舟。眾懼,海舟素
奉後,供瓣香求救。忽後降一客 曰:『此金山神也。汝等竊金,為禍
不小。今我來救汝』。即持槍登檣杪,命舟 中嗚金鼓助戰,與神拒敵
良久,神不能勝而去。舟無所損,遂免於厄。
海怪多作黑浪,浪中鬼物,披發登舟,舟人持兵器驅逐之。或出沒
乘船,靈旗 豹尾,天昏日慘,投以香餅或紙錢始沒。海鰍如駕奔濤撞
舟,兩目如日,牙如 山峰。或舟行入蜃氣中,樓閣城市,宛然陰翳,
白日忽雨,多至壤船。舟人叩 請天後,降神見星,星如流火,集帆檣
上。呼吸之間,百靈成集,澄波一色, 水平如鏡。共相慶幸,得免沈
溺矣。
汪冊使靈異記二則
汪楫錄有神異一條。康熙二十年九月十四日黎明,夢與同官喬萊登
一山瞻仰, 有碧霞元君廟,疑為泰山神,下拜。神衣飾如妃後。命
坐,辭。神曰:『公操人 爵之柄,坐宜也』。因坐。已複賜食一器。
覺以告萊。二十一年元旦,謁關帝, 得簽詩,有「一紙官書火速催,
扁舟東下浪如雷」句。三月,與中書林麟𦨭同 充冊封琉球國使。葢林
字石萊,喬字石林,乃知夢與簽詩莫非預定。獨疑與泰 山神無涉。行
次杭州,楫時方疏請諭祭天妃。及登吳山,謁天妃宮,見旛書 「碧霞
元君」。越日,於孩兒巷得天妃經一函,詳書歷代封號,始知崇禎十
三年 加封「碧霞元君」;示夢者蓋即天後也。
又云使臣登舟,必先迎請天妃,奉柁樓上,而以拏公從祀。拏公
者,福建拏口 人。嘗行賈,臥舟中,聞神語曰:『某日將行毒於某
處』。公謹伺之。至期,果 見一人拋毒物水中。公投水收取,盡食
之,遂卒。以是面作靛色,後為土神。 明兵攻閩不即下,出牌誓曰:
『入城不留一人』!公化為耆老進曰:『若改殺為 留,當獻城』。從
之。請以水燈為號。時荻蘆門水深不設備,而居民以神誕日放 燈於
此。明兵望燈入,公擁沙助之,遂克城。果不殺一人。後以功封「護
國天 下兵馬司」,協佑尊王。海船必奉之者,以海上多礁霧,專藉神
力導引云。臣周 煌亦循例奉迎香火上船。姑米之險,石塘之霧,神實
有靈焉。因詳訪。閩人 云:『公實卜姓,以業拏舟,為神,故稱拏
公。今各省藩司庫神,皆明時命以公 主之,故人亦多奉為財神。
莆田令顯應記二則
一
國朝乾隆丙午,台灣林爽文作亂,均奉委隨福公相東渡,生擒林
逆。丁未五 月,凱旋內渡。舟行四日,時將晚,已望見大旦門矣。舟
子曰:『日將夕,未可 入口;請寄椗,明早再進』。公相云:『已望
見廈門,尚欲在海中飄蕩一夜 耶』!下令進口。其時已近黃昏,清風
徐來,舟乃旁行。頃刻,晦暗不知所 向,舟人大恐,乃下二椗,舟竟
不停。舉船皆惶懼。正在危急間,舟子忽喜 曰:『前有火光,媽祖來
也』!眾前望,隱約之間,如有人坐小舟中,以火刀擊 石,碎火四
出。舟子曰:『速轉舵向火行』!一瞬息而舟已進口矣。自古渡台,
未有夜進大旦門者;蓋門邊多石,夜行難以趨避故耳。公相大悅,實
時登岸。 次晨赴天後宮進香,許願在京師蓋媽祖廟云。
國朝乾隆丁未冬,福公相總督閩浙,因海賊林明灼率匪船十餘只在
浙、閩洋面 行劫,商旅患之。公相飭兩省舟師圍捕,知舟師未肯出
力,特派均同守備鄭玉 楷二人率兵五百,駕商船十隻,出洋督緝,兼
令查舟師之勤惰而密報焉。均與 守備鄭玉楷同日出洋,首先拏獲大盜
陳開開一名解省,公相大悅,批稟獎勵。 均等在海上搜捕,一日下
午,舟人曰:『天太暖,恐夜間有風,現已望見斗米, 應收澳』。正
言間,忽大霧彌漫,四望不見,不能收澳。時已將暮,轉開出外 洋,
以定南針。向東行二寸香,又向西行,如此往返,舟如顛簸。夜深,
風愈 大。時約三更,舟子在天后座前燒香,大驚曰:『媽祖去矣』!
頃刻,香火延燒 座前紅彩,舉船皆大驚。而風浪更巨,忽報蓬下水
矣,又報桅損矣,又聞大響 一聲,舟子哭曰:『舵出門矣』!船全賴
舵,而舵又賴肚帶以系之,今肚帶斷而 舵出門,船不能主,聽死而
已。其時兵丁中有名番仔者,能下水。舟子曰:『如 伊下水,能將肚
帶按好,亦萬死之一生也』。因喚番仔,告以故,並厚賞之。番 仔
曰:『此時要錢何用?同一死也,不過要我先死。我願先死,諸人苟
能不死, 善視我妻子可也』。遂慨然脫衣下水去。約有一更次,忽聞
舵工曰:『舵上有人 聲,豈番仔來耶』?乃放索系其上船。番仔怒
曰:『我為汝一船百餘人性命下 水,汝等乃不我接應耶』?眾唯唯遜
謝之。舵工即令人收船頭小輪。良久又大 響一聲,眾驚以為船破。舟
人曰:『其聲似舵歸門,非破也』。乃執火焚香,大 喜曰:『媽祖來
矣』!均問汝何以知之。曰:『來!試視之』!均匍匐而往,見 神像
滿面汗珠流下。均驚駭伏地。其時風浪尚大,舟子曰:『媽祖來,且
毋 恐』!乃以二錢在神前卜曰:『向東去,神當助我』。乃令舵工轉
舵向東,水聲 盈耳,語不聞聲。約一時許,天將明,舟人上桅頂遙望
曰:『已見羅湖澳,可速 行』。不多時,舟忽屹然不動。方驚訝間,
舟子笑曰:『已進口,在沙上擱淺 矣』。均乃出艙登岸。其餘九船亦
相繼而至,眾相慶焉。偏看船上無一物不損, 而船竟無恙。實時登
岸,覓船匠修整器具,仍與鄭守戎分船出洋,抵白犬,賊 船望見,斬
椗而逃。我船尾追,至磁澳,賊船衝礁登山,我兵分頭往捕,獲賊 五
十餘名,即回五虎門,而公相已先五日赴粵,督兵安南矣。此一役
也,遇霧 之夜,聖像汗流,神佑彰彰,均親目所見,是以終身敬奉弗
敢懈云。 嘉慶庚午春,均轉餉入都,舟過清江,敬詣天後宮拈香。本
廟道士問天後出身 及家鄉事跡。均訝曰:『本廟奉敕建立,於今多
年,何志書竟未之見耶』?道士 曰:『豈但道士未見,即往來大人先
生偶然言及,亦下問於道士,而道士茫無以 對』。均即於神前焚香,
心許願歸去刷印志書一百部,寄奉廟中,囑道士分送往 來士大夫披
覽,俾得知神靈普濟,且廣見聞也。福建興化府莆田縣知縣候選同 知
軍功世襲恩騎尉廣寧張均謹識。
蘇總兵靈應事
簡放福建漳州鎮總兵官鑲白旗蒙古英保佐領下蘇勒芳阿前因入覲丹
墀,仰蒙天 訓,奉命南旋,於庚辰荷月下浣舟抵天妃閘。時河流橫
急,船只被衝旁倒,幸 得履險如夷,悉賴天后聖母神靈默佑。回念神
功,敬謹捐刷天後顯跡志書百部 施送,以昭靈貺云爾。
跋一
按天后志書不一,有敕封志、顯聖錄、顯應錄、昭應錄、述異記,
要皆各就所 見,以記其事。自乾隆戊戌圖志全集之書成,而天下皆奉
為善本矣。第流傳日 廣,翻刻日多,若不慎為校正,恐滋承訛之誚。
舊本聖跡圖,自大士賜丸至春秋崇祀,凡四十八圖;以下三圖系道光
年間上洋 壽恩堂增入。咸豐丁巳,乍川陳氏立願重梓其板,旋遭兵
燹。同治乙丑,武彞 潘、邱二氏複經翻刻,板存閩中建群會館。今同
人以刷印未便,謀為重刊,先 屬孫孝廉承謨參閱,並增入金、柳二將
軍封號、奏片及汪委員靈應記。茲複為 編次刪定,因序而付之梓,梓
成並書緣起於後。蛟川周巨漣。
跋二
原本天后敕封志、顯應錄、昭應錄刻板俱存福建興化,而江、浙二
省未見善 板。況原本亦屬少見。今虔誠繪像拜里居古跡,繪圖敬刻。
又靈笘聖簽及道光 六年海運加封事實一半補刻,名之曰天后聖母聖跡
圖志。幸望貴商船主發心許 願,敬印天后聖母聖跡圖志,布送各省,
傳流廣大,功實無量。但船在海洋許 願,只知敬戲。而敬戲、一日之
誠,敬送是書,顯彰聖跡,綿傳百世之功,較 之敬戲勝萬倍也。信心
高明善士必以為然者也。 聖跡圖志板存於浙西木商,毀於兵燹。顧後
之靈顯何與於是書,而奉後者究不 可無是書。脫不踵而梓之,將窮鄉
僻壤曷以知神靈之歷久彌彰、封典之有加無 已耶?浙商爰取舊本,校
其訛字,付之剞劂,寄板於閩之安瀾會館,俾奉祀者 資印訂焉。 同
治庚午孟夏,鎮海孫承謨敬識。