Compare commits

...

8 Commits

Author SHA1 Message Date
Jacob Guenther 3f86cc8a23 clean backlog. 2021-09-17 00:36:45 -08:00
Jacob Guenther b28ad9ca73 cargo fmt 2021-09-16 22:50:10 -08:00
Jacob Guenther bd15e7bc0f ignore built files. 2021-09-16 22:49:53 -08:00
Jacob Guenther f07d833e52 cleaning up backlog. 2021-09-16 22:47:48 -08:00
Jacob Guenther 4efd001ba6 cleaning up backlog. 2021-09-16 22:46:16 -08:00
Jacob Guenther 7c38707686 Clearing backlog 2021-09-16 22:40:37 -08:00
Jacob Guenther 27bc498a96 Clearing backlog. 2021-09-16 22:40:16 -08:00
Jacob Guenther 5ef2a6f9fc clearing backlog. 2021-09-16 22:39:02 -08:00
72 changed files with 3608 additions and 541 deletions

View File

@ -1,37 +0,0 @@
<html>
<head>
<meta charset="utf-8">
<title>chmod777's tilde</title>
<meta name="description" content="">
<meta name="author" content="chmod777">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<header>
<h1>~chmod777</h1>
<nav>
<a href="/~chmod777/">Home</a>
</nav>
</header>
<main>
<h2></h2>
<p></p>
</main>
<footer>
<nav>
<span>~</span>
<a href="#">Top</a>
<span>~</span>
<a href="/~chmod777/">Home</a>
<span>~</span>
</nav>
<br>
<a id="page-source" href="https://tildegit.org/chmod777/my_blog">Page source</a>
</footer>
</body>
</html>

6
.gitignore vendored Normal file → Executable file
View File

@ -1,2 +1,8 @@
drafts/*
botany_builder/*
Cargo.lock
# Added by cargo
/target

11
Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "my_blog"
version = "0.1.0"
edition = "2018"
[dependencies]
tera = "1.12.1"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.64"

View File

@ -1,80 +0,0 @@
:root {
--background-color: #111;
--border-color: #222;
--text-color: #fb5;
--link-color: #f70;
--link-highlight-color: #f20;
--header-color: #ccc;
}
body {
background-color: var(--background-color);
color: var(--text-color);
display: block;
}
@media screen and (min-width: 800px) {
body {
width: 800px;
}
}
@media screen and (min-width: 1000px) {
body {
margin: auto;
display: grid;
width: 1000px;
grid-template-columns: 200px auto 200px;
grid-template-areas:
'head head head'
'nav main .'
'foot foot foot';
}
body > header {
grid-area: head;
}
body > nav {
grid-area: nav;
position: sticky;
top: 0;
height: min-content;
}
body > main {
grid-area: main;
}
body > footer {
grid-area: foot;
}
}
h1, h2, h3, h4, h5, h6 {
color: var(--header-color);
}
body > header {
text-align: center;
}
a {
color: var(--link-color);
font-weight: bold;
}
a:hover {
color: var(--link-highlight-color);
}
img {
max-width: 100%;
}
.icon {
background-color: #aaa;
padding: 5px;
width: 64px;
height: 64px;
}
pre {
background-color: var(--border-color);
color: var(--header-color);
max-width: min-content;
padding: 20px;
border-radius: 5px;
}
footer {
margin: 20px 0px 200px 0px;
text-align: center;
}

52
config.json Normal file
View File

@ -0,0 +1,52 @@
{
"posts": [
{
"url": "/blog/posts/casting_an_aluminium_settlers_of_catan_board.html",
"title": "Casting an Aluminium Settlers of Catan Board",
"date_published": "1 September 2021",
"date_modified": null,
"summary": "",
"template_name": "blog/posts/casting_an_aluminium_settlers_of_catan_board.html"
},
{
"url": "/blog/posts/pi_pico_first_impressions.html",
"title": "Pi Pico First Impressions",
"date_published": "1 September 2021",
"date_modified": null,
"summary": "",
"template_name": "blog/posts/pi_pico_first_impressions.html"
},
{
"url": "/blog/posts/designing_my_first_pcb.html",
"title": "Designing my First PCB",
"date_published": "1 September 2021",
"date_modified": null,
"summary": "",
"template_name": "blog/posts/designing_my_first_pcb.html"
}
],
"archived": [
],
"blogs_that_i_read": [
],
"projects": [
{
"url": "/projects/project/creative_commons_icons.html",
"title": "Creative Commons Icons",
"image": "/assets/svg/paper-list-icon.svg",
"summary": "Icon assets licensed under CC BY-NC-SA 4.0",
"template_name": "projects/project/creative_commons_icons.html"
}
],
"tech_demos": [
{
"url": "/tech_demos/demos/svg_pong.html",
"title": "SVG Pong",
"image": "/assets/svg/pong.svg",
"summary": "The game of Pong using SVG graphics and animations.",
"template_name": "tech_demos/demos/svg_pong.html"
}
]
}

View File

@ -1,40 +0,0 @@
# ~chmod777
## Introductions
Hello!
Around the web I mostly go by chmod777. Feel free to ask me anything.
I am a recent computer science graduate with no clue what they are doing in life.
I just set this up so ther is more to add.
## Contact info
* fediverse/mastodon: @chmod777@linuxrocks.online
* irc.tilde.chat: chmodrwx
* gitea: tildegit.org/chmod777
## What you will find here
Blog posts about
* Software dev
* Hardware dev
* Aluminium casting
* Gardening
* Baking
* Other hobby projects
* Ramblings
You can find the web version of my blog at
=> http://tilde.club/~chmod777 ~chmod777
I just started working on a .html to .gmi converter for the posts in this gemlog so that my content on my blog will also be available here. Some features of the converter are still missing so if it looks like something is missing from one of these posts it might be but it also might be that I gave up writing halfway through.
=> https://tildegit.org/chmod777/html2gemini_rs html2gemini_rs
## Posts

View File

@ -1,78 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>chmod777's tilde</title>
<meta name="description" content="chmod777's tilde where they share their projects and stuff">
<meta name="author" content="chmod777">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/css/styles.css">
</head>
<body>
<header>
<h1 id="title">~chmod777</h1>
<p>You can also find this blog on gemini at</p>
<a href="gemini://tilde.club/~chmod777">gemini://tilde.club/~chmod777</a>
</header>
<nav>
<ul>
<li><a href="#introductions">Introductions</a></li>
<li><a href="#contact-info">Contact info</a></li>
<li><a href="#find-here">What you will find here</a></li>
<li><a href="#posts">Posts</a></li>
<li><a href="#botany">My Botany Plant</a></li>
</ul>
</nav>
<main>
<section id="introductions">
<h2>Introductions</h2>
<p>Hello!</p>
<p>On the internet I go by chmod777. Feel free to ask me anything.</p>
<p>A recent computer science graduate with no clue what they are doing in life.</p>
<p>I just set this up so there is more to add.</p>
</section>
<section id="contact-info">
<h2>Contact info</h2>
<ul>
<li>fediverse/mastodon: @chmod777@tilde.zone</li>
<li>irc.tilde.chat: chmodrwx</li>
<li>gitea: tildegit.org/chmod777</li>
</ul>
</section>
<section id="find-here">
<h2>What you will find here</h2>
<p>Blog posts about</p>
<ul>
<li>Software dev</li>
<li>Hardware dev</li>
<li>Aluminium casting</li>
<li>Gardening</li>
<li>Baking</li>
<li>Other hobby projects</li>
<li>Ramblings</li>
</ul>
</section>
<section id="posts">
<h2>Posts</h2>
</section>
</main>
<footer>
<nav>
<span>~</span>
<a href="#">Top</a>
<span>~</span>
</nav>
<br>
<a id="page-source" href="https://tildegit.org/chmod777/my_blog">Page source</a>
</footer>
</body>
</html>

661
license.txt Normal file
View File

@ -0,0 +1,661 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.

View File

@ -1,55 +0,0 @@
<!DOCYTPE html>
<html>
<head>
<meta charset="utf-8">
<title>chmod777's tilde - Casting Aluminium Settlers of Catan Board</title>
<meta name="description" content="">
<meta name="author" content="chmod777">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/css/styles.css">
</head>
<body>
<header>
<h1>~chmod777</h1>
<nav>
<a href="/~chmod777/">Home</a>
</nav>
</header>
<main>
<h2 id="settlers-catan-casting">Casting Aluminium Settlers of Catan Board</h2>
<p>A couple years ago now I started casting Settlers of Catan game tiles in aluminium. I have only gotten as far as casting the mountain(ore) tiles but I plan on eventually casting the rest.</p>
<p>To start I model a tile using Blender. Modeling the base is faily straight forward. Create a hexagon, scale it to the size you want, extrude it upwards, and then use a difference modifier to create cutouts for towns and roads. The mountains are created using an image as a height map on a seperate plain and then combined with the base using a union modifier.</p>
<p>After modeling the tile in blender I export the file then print it on a 3D printer. The print will be the form for the mold that I will cast into. Using smaller layers in the print is better as the sand tends to cling to the ridges and you get smaller horizontal lines.</P>
<p>Befor I could cast the first piece I first had to make a molding box. To do this I used four pieces of 2x4 lumber for each side and screwed them together. Then I added some scrap lumber strips to the sides of each half to act as guides so the 2 sides don't shift. Now that I have the form, the casting box, and sand that I ordered I can place the mold, into the box, and pack sand around it and the sprew(form for the pouring hole).</p>
<p>My furnace setup is very low tech. It consists of a pile of rocks stacked to resemble a furnace, a bag of charcole, and a small fan. A small trench is dug under the rocks to allow for airflow while skinny rocks are placed accross the trench to prevent the charcole from falling into it.</p>
<p>The furnace is started with wood and the crucible is placed into it to heat it up gradually. Once the furnace is started charcole is added, then small ingots are placed in thecrucible. It usually takes 40 minutes from lighting the "furnace" to pouring with this "setup".</p>
<p>And here are the results. They still need to be cleaned up a bit.</p>
<ul>
<li><img src="assets/jpeg/catan-mountain-1.jpeg" title="Ore Tile 1" alt="Photo of an aluminium Settlers of Catan ore tile."></li>
<li><img src="assets/jpeg/catan-mountain-2.jpeg" title="Ore Tile 2" alt="Photo of an aluminium Settlers of Catan ore tile."></li>
<li><img src="assets/jpeg/catan-mountain-3.jpeg" title="Ore Tile 3" alt="Photo of an aluminium Settlers of Catan ore tile."></li>
</ul>
<p>These where my first casts so I made a lot of mistakes throughout this whole process. You can see on the third piece that instead of pouring directly into the mold I poured to the side and carved a gate in the sand to piece. The sides are so thin the sand broke away and I need to do a lot of filing to remove the excess material. This also meant that there is a large divit on the bottom because aluminium shrinks when it cools and there was no sprew to feed more aluminum into the back.</p>
<p>There are also several ways I could have improved my molds. The first being angling the cutouts in the mountains so that when the form is pulled out it doesn't catch the sand. You can see in the first piece I had to do a lot off grinding to remove the aluminium where the sand collapsed.</p>
<p>If anybody can tell my why the third tile has that texture on the flat parts that would be great. I think it's because I cast it too hot?</p>
<p>It was a great expierment and I hope to have an update this summer when I cast more of the tiles.</p>
</main>
<footer>
<nav>
<span>~</span>
<a href="#">Top</a>
<span>~</span>
<a href="/~chmod777">Home</a>
<span>~</span>
</nav>
<br>
<a id="page-source" href="https://tildegit.org/chmod777/my_blog">Page source</a>
</footer>
</body>
</html>

View File

@ -1,55 +0,0 @@
<!DOCYTPE html>
<html>
<head>
<meta charset="utf-8">
<title>chmod777's tilde - Gamepad PCB</title>
<meta name="description" content="">
<meta name="author" content="chmod777">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/css/styles.css">
</head>
<body>
<header>
<h1>~chmod777</h1>
<nav>
<a href="/~chmod777/">Home</a>
</nav>
</header>
<main>
<h2>Designing a PCB for a Gamepad rev1</h2>
<p>I have a vague plan on making my own Raspberry Pi compute module powered handheld gaming device but I don't know anything about designing PCBs. To learn how to create a PCB I decided to start small. Really small. I decided to make a gamepad with just 11 buttons and some header pins for an Arduino Nano.</p>
<p>Mistakes where made but I learned a lot about the process and now I see many ways I can improve and expand on my design.</p>
<img src="assets/jpeg/gamepad-rev1.jpeg" alt="An image of the gamepad pcb with an Arduino Nano inserted in the header pins.">
<p>Fixing some of the problems with it</p>
<ul>
<li>Use a two sided PCB so headers can be inserted from the top and solded to the back instead instead of being awkwardly raised above the board and soldered to side they come out of.
<li>Add rounded corners to the board.</li>
<li>Better text for the silkscreen. Add a revision number.</li>
</ul>
<p>Expanding on the current design</p>
<ul>
<li>More buttons</li>
<li>Shoulder buttons</li>
<li>Joystick</li>
<li>Headers so the pins can be accessed to allow for easy experimentation.</li>
<li>Use a cheaper micro controller. Even the knockoff Arduino Nanos are expensive.</li>
<li>While out of the scope of this project the next controller might want a case.</li>
</ul>
</main>
<footer>
<nav>
<span>~</span>
<a href="#">Top</a>
<span>~</span>
<a href="/~chmod777">Home</a>
<span>~</span>
</nav>
<br>
<a id="page-source" href="https://tildegit.org/chmod777/my_blog">Page source</a>
</footer>
</body>
</html>

View File

@ -1,41 +0,0 @@
<!DOCYTPE html>
<html>
<head>
<meta charset="utf-8">
<title>chmod777's tilde</title>
<meta name="description" content="">
<meta name="author" content="chmod777">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/css/styles.css">
</head>
<body>
<header>
<h1>~chmod777</h1>
<nav>
<a href="/~chmod777/">Home</a>
</nav>
</header>
<main>
<h2>Icons</h2>
<p>Below is a list of icons I have made for various reasons. These icons are in the public domain.</p>
<ul>
<li><img class="icon" src="assets/svg/gears-icon.svg" title="Gears" alt="An icon with two interlocking gears."></li>
<li><img class="icon" src="assets/svg/chat-bubbles-icon.svg" title="Chat Bubbles" alt="An icon with two overlapping chat bubbles."></li>
<li><img class="icon" src="assets/svg/paper-list-icon.svg" title="Character Sheet" alt="An icon with two stacked pieces of paper and a bullet list on the top piece."></li>
</ul>
</main>
<footer>
<nav>
<span>~</span>
<a href="/~chmod777">Home</a>
<span>~</span>
</nav>
<br>
<a id="page-source" href="https://tildegit.org/chmod777/my_blog">Page source</a>
</footer>
</body>
</html>

View File

@ -1,52 +0,0 @@
<!DOCYTPE html>
<html>
<head>
<meta charset="utf-8">
<title>chmod777's tilde - Roll Lang</title>
<meta name="description" content="An article about Roll Lang a domain specific language for interpreting dice rolls and math operations common in tabletop rpgs.">
<meta name="author" content="chmod777">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/css/styles.css">
</head>
<body>
<header>
<h1>~chmod777</h1>
<nav>
<a href="/~chmod777/">Home</a>
</nav>
</header>
<main>
<h2>Roll Lang</h2>
<h3>Project links</h3>
<ul>
<li><a href="https://github.com/jacobguenther/roll_lang">Repository</a></li>
<li><a href="https://github.com/jacobguenther/roll_lang/wiki">Wiki</a></li>
<li><a href="https://github.com/jacobguenther/projects/1">Project Board</a></li>
</ul>
<p>Roll Lang is a domain specific language for interpreting dice rolls and math operations common in tabletop rpgs. It implements it's own variation of dice notation.</p>
<a href="https://en.wikipedia.org/wiki/Dice_notation">Wikipedia Article on Dice Notation</a>
<h3>Examples</h3>
<p>/r d20 + 5</p>
<p>(12)+5=17</p>
<br>
<p>[[d20 + 5]]</p>
<p>(17)</p>
</main>
<footer>
<nav>
<span>~</span>
<a href="#">Top</a>
<span>~</span>
<a href="/~chmod777/">Home</a>
<span>~</span>
</nav>
<br>
<a id="page-source" href="https://tildegit.org/chmod777/my_blog">Page source</a>
</footer>
</body>
</html>

2
public/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
feed.rss
index.html

1
public/about/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.html

View File

Before

Width:  |  Height:  |  Size: 874 KiB

After

Width:  |  Height:  |  Size: 874 KiB

View File

Before

Width:  |  Height:  |  Size: 389 KiB

After

Width:  |  Height:  |  Size: 389 KiB

View File

Before

Width:  |  Height:  |  Size: 940 KiB

After

Width:  |  Height:  |  Size: 940 KiB

View File

Before

Width:  |  Height:  |  Size: 702 KiB

After

Width:  |  Height:  |  Size: 702 KiB

View File

Before

Width:  |  Height:  |  Size: 576 KiB

After

Width:  |  Height:  |  Size: 576 KiB

1
public/assets/svg/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.svg

1
public/blog/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.html

1
public/blog/posts/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.html

View File

@ -0,0 +1,16 @@
fieldset {
width: min-content;
margin-left: auto;
margin-right: auto;
}
fieldset > summary {
text-align:center;
}
fieldset > div {
display: grid;
grid-gap: 5px;
grid-template-columns: max-content min-content;
}
fieldset > div > label {
justify-self: right;
}

View File

@ -0,0 +1,26 @@
#project-list {
list-style-type: none;
}
.project-card {
display: grid;
grid-template-areas:
'project-img project-title'
'project-img project-description';
grid-template-columns: max-content 1fr;
grid-template-rows: min-content 1fr;
}
.project-img {
grid-area: project-img;
display: inline-block;
height: 128px;
}
.project-title {
grid-area: project-title;
margin: 10px 0px 0px 10px;
padding: 0px 0px 0px 0px;
}
.project-description {
grid-area: project-description;
margin: 5px 0px 0px 15px;
}

219
public/css/styles.css Executable file
View File

@ -0,0 +1,219 @@
.default-font {
font-size: 110%;
}
.monospace-font {
font-family: monospace;
font-size: 125%;
}
.dark-theme {
--background-color: #111;
--border-color: #222;
--text-color: #fb5;
--header-color: #ccc;
--link-color: #f70;
--link-hover-color: #f20;
--menu-hover-color: #222;
--post-card-background: #333;
}
.classic-theme {
--background-color: #fff;
--border-color: #222;
--text-color: #000;
--header-color: #000;
--link-color: #00f;
--link-hover-color: #00f;
--menu-hover-color: #bbb;
--post-card-background: #bbb;
}
body {
background-color: var(--background-color);
color: var(--text-color);
display: block;
}
@media screen and (min-width: 800px) {
body {
width: 800px;
}
}
@media screen and (min-width: 1000px) {
body {
margin: auto;
display: grid;
width: 1000px;
grid-template-columns: auto 1000px auto;
grid-template-areas:
'header header header'
'. accessibility .'
'. main .'
'footer footer footer';
}
body > form {
grid-area: accessibility;
width: max-content;
min-width: min-content;
justify-self: center;
}
body > header {
grid-area: header;
}
body > footer {
grid-area: footer;
}
main {
grid-area: main;
margin: auto;
display: grid;
width: 100%;
grid-gap: 5px;
grid-template-columns: auto 1fr;
grid-template-areas: 'main-aside page-content';
}
main > div {
grid-area: page-content;
min-width: min-content;
width: 100%;
}
main > aside {
grid-area: main-aside;
position: sticky;
top: 0;
height: min-content;
width: 300px;
min-width: 120px;
max-width: 380px;
}
}
h1, h2, h3, h4, h5, h6 {
color: var(--header-color);
}
.link-list > li, .link-list > li > a, .link-padding {
padding: 10px 10px 10px 10px;
}
body > header {
text-align: center;
}
body > header > nav > ul > li {
display: inline-block;
}
body > header > nav > ul > li > a {
padding: 20px 20px 20px 20px;
}
body > header > nav > ul > li > a:hover {
background-color: var(--menu-hover-color);
border-radius: 8px;
}
body > footer {
margin: 20px 0px 200px 0px;
text-align: center;
}
body > form {
margin-left: auto;
margin-right: auto;
max-width: 90%;
}
body > form > fieldset {
display: grid;
width: max-content;
max-width: 90%;
grid-template-columns: auto 1fr;
grid-gap: 10px;
grid-template-areas:
'describe describe'
'color-label color-select'
'fonts-label fonts-select'
'apply apply'
}
body > form > fieldset > p {
grid-area: describe;
}
#color-theme-label {
grid-area: color-label;
text-align: left;
}
#color-theme {
grid-area: color-select;
}
#fonts-label {
grid-area: fonts-label;
text-align: left;
}
#fonts {
grid-area: fonts-select;
}
body > form > fieldset > input {
grid-area: apply;
width: max-content;
min-width: min-content;
justify-self: center;
}
main > aside > nav > ul {
padding-left: 15px;
}
.post-card {
padding: 5px 5px 5px 5px;
margin: 5px 5px 5px 5px;
background-color: var(--post-card-background);
border-radius: 5px;
}
.post-card-grid {
display: grid;
grid-template-columns: auto;
grid-template-areas:
'post-card-title'
'post-card-published'
'post-card-modified'
'post-card-content';
}
.post-card-title {
grid-area: post-card-title;
}
.post-card-published {
grid-area: post-card-published;
}.post-card-modified {
grid-area: post-card-modified;
}.post-card-content {
grid-area: post-card-content;
}
a {
color: var(--link-color);
font-weight: bold;
}
a:hover {
color: var(--link-hover-color);
}
img {
max-width: 100%;
}
.icon {
background-color: #aaa;
padding: 5px;
width: 64px;
height: 64px;
}
pre {
background-color: var(--border-color);
color: var(--header-color);
max-width: min-content;
padding: 20px;
border-radius: 5px;
}

601
public/js/library.js Normal file
View File

@ -0,0 +1,601 @@
"use strict";
/**
*
* @source http://tilde.club/~chmod777/ts/base.ts
*
* @license AGPL-3.0-only
* @licstart
* Copyright (c) 2021 chmod777
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* @licend
*/
let pong;
window.onload = function () {
pong = new Pong(document);
};
function error(id, elementName) {
return `Failed to find ${elementName} element with id "${id}"`;
}
function getHTMLInput(id) {
const element = document.getElementById(id);
if (element instanceof HTMLInputElement)
return element;
throw error(id, 'html button');
}
function getHTMLSpan(id) {
const element = document.getElementById(id);
if (element instanceof HTMLSpanElement)
return element;
throw error(id, 'html span');
}
function getSVGRectElement(svgDocument, id) {
const element = svgDocument.getElementById(id);
if (element instanceof SVGRectElement)
return element;
throw error(id, 'svg rect');
}
function getSVGTextElement(svgDocument, id) {
const element = svgDocument.getElementById(id);
if (element instanceof SVGTextElement)
return element;
throw error(id, 'svg text');
}
function getSVGCircleElement(svgDocument, id) {
const element = svgDocument.getElementById(id);
if (element instanceof SVGCircleElement)
return element;
throw error(id, 'svg circle');
}
function getSVGAnimateMotionElement(svgDocument, id) {
const element = svgDocument.getElementById(id);
if (element instanceof SVGAnimateMotionElement)
return element;
throw error(id, 'svg animate motion');
}
function getSVGPathElement(svgDocument, id) {
const element = svgDocument.getElementById(id);
if (element instanceof SVGPathElement)
return element;
throw error(id, 'svg path');
}
/**
*
* @source http://tilde.club/~chmod777/ts/pong.ts
*
* @license AGPL-3.0-only
* @licstart
* Copyright (c) 2021 chmod777
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* @licend
*/
class Vec2 {
constructor(x, y) {
this.x = x;
this.y = y;
}
static zero() {
return new Vec2(0, 0);
}
static one() {
return new Vec2(1, 1);
}
clone() {
return new Vec2(this.x, this.y);
}
add(other) {
return new Vec2(this.x + other.x, this.y + other.y);
}
sub(other) {
return new Vec2(this.x - other.x, this.y - other.y);
}
mul(s) {
return new Vec2(this.x * s, this.y * s);
}
div(s) {
return new Vec2(this.x / s, this.y / s);
}
cross(other) {
return this.x * other.y - this.y * other.x;
}
dot(other) {
return this.x * other.y + this.y * other.y;
}
magnitude2() {
return this.x * this.x + this.y * this.y;
}
magnitude() {
return Math.sqrt(this.magnitude2());
}
asUnit() {
return this.div(this.magnitude());
}
static numberAsString(n) {
if (n != Math.floor(n)) {
n.toFixed(2);
}
return n.toString();
}
asString() {
return `${Vec2.numberAsString(this.x)},${Vec2.numberAsString(this.y)} `;
}
asAbsolute() {
return `M${this.asString()}`;
}
asLine() {
return `L${this.asString()}`;
}
}
class Line {
constructor(p1, p2) {
this.p1 = p1;
this.p2 = p2;
}
lineLineIntersect(l2) {
const p = this.p1;
const r = this.p2.sub(p);
const q = l2.p1;
const s = l2.p2.sub(q);
const r_cross_s = r.cross(s);
const q_minus_p = q.sub(p);
if (r_cross_s === 0) {
return null;
// let q_minus_p_cross_r = q_minus_p.cross(r);
// if (q_minus_p_cross_r === 0)
// return null; // collinear
// else
// return null; // parallel
}
else {
const t = q_minus_p.cross(s.div(r_cross_s));
const u = q_minus_p.cross(r.div(r_cross_s));
if (0 <= t && t <= 1 && 0 <= u && u <= 1) {
if (t === 0)
return q.add(s.mul(u));
else
return p.add(r.mul(t));
}
else {
return null; // divergent
}
}
}
}
class PongElements {
constructor(svgContent) {
this.playerPaddle = getSVGRectElement(svgContent, 'pong-player-paddle');
this.aiPaddle = getSVGRectElement(svgContent, 'pong-ai-paddle');
this.playerScoreElement = getSVGTextElement(svgContent, 'pong-player-score');
this.aiScoreElement = getSVGTextElement(svgContent, 'pong-ai-score');
this.ball = getSVGCircleElement(svgContent, 'pong-ball');
this.ballAnimation = getSVGAnimateMotionElement(svgContent, 'pong-ball-animation');
this.ballPath = getSVGPathElement(svgContent, 'pong-ball-path');
this.collisionPath = getSVGPathElement(svgContent, 'pong-collision-path');
this.resetButton = getHTMLInput('pong-reset');
this.serveButton = getHTMLInput('pong-serve');
this.upButton = getHTMLInput('pong-paddle-up');
this.stopButton = getHTMLInput('pong-paddle-stop');
this.downButton = getHTMLInput('pong-paddle-down');
this.fps = getHTMLSpan('fps');
const WIDTH_STRING = Pong.PADDLE_WIDTH.toString();
this.aiPaddle.setAttribute('width', WIDTH_STRING);
this.playerPaddle.setAttribute('width', WIDTH_STRING);
const BALL_RADIUS_STRING = Pong.BALL_RADIUS.toString();
this.ball.setAttribute('r', BALL_RADIUS_STRING);
this.resetPaddles();
this.resetBall();
}
resetBall() {
this.ballPath.setAttribute('d', Pong.ABSOLUTE_CENTER);
this.collisionPath.setAttribute('d', Pong.ABSOLUTE_CENTER);
this.ballAnimation.beginElement();
}
resetPaddles() {
translateToPosition(this.playerPaddle, Pong.PLAYER_STARTING_POSITION);
translateToPosition(this.aiPaddle, Pong.AI_STARTING_POSITION);
}
resetScores() {
this.playerScoreElement.innerHTML = '0';
this.aiScoreElement.innerHTML = '0';
}
}
class PongState {
constructor() {
this.lastAnimationFrame = 0;
this.playerPosition = Pong.PLAYER_STARTING_POSITION.clone();
this.aiPosition = Pong.AI_STARTING_POSITION.clone();
this.ballSpeed = Pong.BALL_BASE_SPEED;
this.ballVelocity = Vec2.zero();
this.running = false;
this.shouldServe = false;
this.playerServe = false;
this.time = 0;
this.lastTime = 0;
this.serveTime = 0;
this.dt_ms = 0;
this.dt = 0;
this.playerScore = 0;
this.aiScore = 0;
this.scoreDuration = 0;
this.collisionDuration = 0;
this.collisionPoint = Vec2.zero();
this.moveUp = false;
this.moveDown = false;
}
get timeSinceServe() { return (this.time - this.serveTime) / 1000; }
update_dt(time) {
this.lastTime = this.time;
this.time = time;
this.dt_ms = this.time - this.lastTime;
this.dt = this.dt_ms / 1000;
}
resetBall() {
this.ballSpeed = Pong.BALL_BASE_SPEED;
this.ballVelocity = Vec2.zero();
}
resetPaddles() {
this.playerPosition = Pong.PLAYER_STARTING_POSITION.clone();
this.aiPosition = Pong.AI_STARTING_POSITION.clone();
this.moveUp = false;
this.moveDown = false;
}
}
class Pong {
constructor(svgContent) {
this.state = new PongState();
this.elements = new PongElements(svgContent);
this.elements.resetButton.addEventListener('click', () => { this.reset(); });
this.elements.serveButton.addEventListener('click', () => {
if (!this.state.running) {
this.state.running = true;
this.state.shouldServe = true;
}
});
this.elements.upButton.addEventListener('click', () => {
this.state.moveUp = true;
this.state.moveDown = false;
});
this.elements.downButton.addEventListener('click', () => {
this.state.moveUp = false;
this.state.moveDown = true;
});
this.elements.stopButton.addEventListener('click', () => {
this.state.moveUp = false;
this.state.moveDown = false;
});
document.addEventListener('keydown', (event) => { this.handleKeydown(event); });
document.addEventListener('keyup', (event) => { this.handleKeyup(event); });
this.state.lastAnimationFrame = window.requestAnimationFrame((timestamp) => {
this.update(timestamp);
});
}
serve() {
this.state.shouldServe = false;
this.state.serveTime = this.state.time;
this.state.ballVelocity.x = genRandom();
this.state.ballVelocity.y = genRandom();
this.state.ballVelocity = this.state.ballVelocity.asUnit().mul(this.state.ballSpeed);
if (this.state.ballVelocity.x > 0) {
this.state.playerServe = true;
}
this.buildBallPaths(Pong.CENTER);
}
reset() {
this.state = new PongState();
window.cancelAnimationFrame(this.state.lastAnimationFrame);
this.updatePaddles();
this.elements.resetScores();
this.elements.resetBall();
}
resetBall() {
this.state.resetBall();
this.elements.resetBall();
}
resetPaddles() {
this.state.resetPaddles();
this.updatePaddles();
}
updatePaddles() {
translateToPosition(this.elements.playerPaddle, this.state.playerPosition);
translateToPosition(this.elements.aiPaddle, this.state.aiPosition);
}
update(timestamp) {
this.state.update_dt(timestamp);
const fps = 1 / this.state.dt;
this.elements.fps.innerHTML = fps.toString();
if (this.state.shouldServe) {
this.serve();
}
this.updatePlayer();
if (this.state.running) {
this.updateAI(this.elements.aiPaddle, this.state.aiPosition);
this.processScore();
if (this.state.running) {
this.processHit();
}
}
this.state.lastAnimationFrame = window.requestAnimationFrame((timestamp) => {
this.update(timestamp);
});
}
isColliding(paddle) {
return paddle.y + Pong.PADDLE_HEIGHT > this.state.collisionPoint.y &&
paddle.y < this.state.collisionPoint.y;
}
processScore() {
if (this.state.timeSinceServe > this.state.scoreDuration) {
if (this.state.playerServe) {
this.state.playerScore++;
this.elements.playerScoreElement.innerHTML = this.state.playerScore.toString();
}
else {
this.state.aiScore++;
this.elements.aiScoreElement.innerHTML = this.state.aiScore.toString();
}
this.state.running = false;
this.resetBall();
this.resetPaddles();
}
}
processHit() {
if (this.state.timeSinceServe > this.state.collisionDuration) {
let position = this.state.playerPosition;
let collisionOffset = 0.1;
if (this.state.playerServe) {
position = this.state.aiPosition;
collisionOffset = -collisionOffset;
}
if (this.isColliding(position)) {
this.state.ballVelocity.x = -this.state.ballVelocity.x;
this.state.ballSpeed += Pong.BALL_SPEED_INCREASE;
this.state.serveTime = this.state.time;
this.state.playerServe = !this.state.playerServe;
this.state.collisionPoint.x += collisionOffset;
this.buildBallPaths(this.state.collisionPoint);
}
}
}
clampPaddlePosition(paddlePosition) {
paddlePosition.y = Math.max(Math.min(paddlePosition.y, Pong.PADDLE_MAX_POSITION), 0);
}
updatePlayer() {
if (this.state.moveUp && this.state.moveDown
|| !(this.state.moveUp || this.state.moveDown)) {
return;
}
const dy = this.state.dt * Pong.PADDLE_VELOCITY;
if (this.state.moveDown) {
this.state.playerPosition.y += dy;
}
else {
this.state.playerPosition.y -= dy;
}
this.clampPaddlePosition(this.state.playerPosition);
translateToPosition(this.elements.playerPaddle, this.state.playerPosition);
}
updateAI(paddle, position) {
let targetPosition;
if (this.state.playerServe) {
targetPosition = this.state.collisionPoint.y;
}
else {
targetPosition = Pong.HALF_HEIGHT;
}
targetPosition -= Pong.PADDLE_HALF_HEIGHT;
const targetRange = Pong.PADDLE_HALF_HEIGHT / 2;
const dy = this.state.dt * Pong.PADDLE_VELOCITY;
let shouldMove = false;
if (position.y > targetPosition + targetRange) {
shouldMove = true;
position.y -= dy;
}
else if (position.y < targetPosition - targetRange) {
shouldMove = true;
position.y += dy;
}
if (shouldMove) {
this.clampPaddlePosition(position);
translateToPosition(paddle, position);
}
}
buildBallPath(startingPosition, dir, bounds) {
const path = new Line(startingPosition, startingPosition.add(dir));
const points = [];
while (true) {
const maybeIntersect = this.findNextCollision(path, bounds);
if (maybeIntersect !== null) {
const [point, isEnd] = maybeIntersect;
if (isEnd) {
if (point.x > Pong.HALF_WIDTH)
point.x += 0.01;
else
point.x -= 0.01;
}
else {
if (point.y > Pong.HALF_HEIGHT)
point.y -= 0.01;
else
point.y += 0.01;
}
points.push(point);
if (isEnd) {
break;
}
dir.y = -dir.y;
path.p1 = point;
path.p2 = point.add(dir);
}
else {
console.error("intersect is null");
break;
}
}
return points;
}
buildBallPaths(startingPosition) {
const dir = this.state.ballVelocity.mul(1000);
const animationPoints = this.buildBallPath(startingPosition, dir.clone(), Pong.BOARD_BOUNDS);
const collisionPoints = this.buildBallPath(startingPosition, dir, Pong.PADDLE_COLLISION_BOUNDS);
this.state.collisionPoint = collisionPoints[collisionPoints.length - 1].clone();
this.state.ballVelocity = dir.div(1000);
const animationPath = this.buildSVGPathFromPoints(startingPosition, animationPoints);
this.elements.ballPath.setAttribute('d', animationPath);
this.state.scoreDuration = this.elements.ballPath.getTotalLength() / this.state.ballSpeed;
this.elements.ballAnimation.setAttribute('dur', this.state.scoreDuration.toString());
const collisionPath = this.buildSVGPathFromPoints(startingPosition, collisionPoints);
this.elements.collisionPath.setAttribute('d', collisionPath);
this.state.collisionDuration = this.elements.collisionPath.getTotalLength() / this.state.ballSpeed;
this.elements.ballAnimation.beginElement();
}
buildSVGPathFromPoints(start, points) {
let directions = start.asAbsolute();
for (const point of points) {
directions = directions.concat(point.asLine());
}
return directions;
}
findNextCollision(path, bounds) {
for (const [line, isEnd] of bounds) {
const maybeIntersect = path.lineLineIntersect(line);
if (maybeIntersect !== null) {
return [maybeIntersect, isEnd];
}
}
return null;
}
handleKeydown(event) {
const key = event.key;
if (key === ',') {
this.state.moveUp = true;
}
else if (key === '.') {
this.state.moveDown = true;
}
else if (key === 's') {
if (!this.state.running) {
this.state.running = true;
this.state.shouldServe = true;
}
}
else if (key === 'n') {
this.reset();
}
}
handleKeyup(event) {
const key = event.key;
if (key === ',') {
this.state.moveUp = false;
}
else if (key === '.') {
this.state.moveDown = false;
}
}
}
/*
x w
y +---------------------+
| | |
h | 0 |
| | |
+---------------------+
*/
Pong.WIDTH = 512;
Pong.HEIGHT = 256;
Pong.HALF_WIDTH = Pong.WIDTH / 2;
Pong.HALF_HEIGHT = Pong.HEIGHT / 2;
Pong.CENTER = new Vec2(Pong.HALF_WIDTH, Pong.HALF_HEIGHT);
Pong.ABSOLUTE_CENTER = Pong.CENTER.asAbsolute();
Pong.PADDLE_WIDTH = 4;
Pong.PADDLE_HEIGHT = 28;
Pong.PADDLE_HALF_WIDTH = Pong.PADDLE_WIDTH / 2;
Pong.PADDLE_HALF_HEIGHT = Pong.PADDLE_HEIGHT / 2;
Pong.PADDLE_MAX_POSITION = Pong.HEIGHT - Pong.PADDLE_HEIGHT;
Pong.PADDLE_VELOCITY = 150;
Pong.BALL_RADIUS = 5;
Pong.BALL_SPEED_INCREASE = 10;
Pong.BALL_BASE_SPEED = 200;
Pong.PADDLE_STARTING_POSITION_Y = Pong.CENTER.y - Pong.PADDLE_HALF_HEIGHT;
Pong.PLAYER_STARTING_POSITION = new Vec2(0, Pong.PADDLE_STARTING_POSITION_Y);
Pong.AI_STARTING_POSITION = new Vec2(Pong.WIDTH - Pong.PADDLE_WIDTH, Pong.PADDLE_STARTING_POSITION_Y);
Pong.RAW_CORNERS = [
// top left
new Vec2(0, 0 + Pong.BALL_RADIUS),
// top right
new Vec2(Pong.WIDTH, 0 + Pong.BALL_RADIUS),
// bottom right
new Vec2(Pong.WIDTH, Pong.HEIGHT - Pong.BALL_RADIUS),
// bottom left
new Vec2(0, Pong.HEIGHT - Pong.BALL_RADIUS)
];
Pong.BOARD_CORNERS = [
// top left
new Vec2(Pong.RAW_CORNERS[0].x - Pong.BALL_RADIUS, Pong.RAW_CORNERS[0].y),
// top right
new Vec2(Pong.RAW_CORNERS[1].x + Pong.BALL_RADIUS, Pong.RAW_CORNERS[1].y),
// bottom right
new Vec2(Pong.RAW_CORNERS[2].x + Pong.BALL_RADIUS, Pong.RAW_CORNERS[2].y),
// bottom left
new Vec2(Pong.RAW_CORNERS[3].x - Pong.BALL_RADIUS, Pong.RAW_CORNERS[3].y)
];
Pong.PADDLE_COLLISION_CORNERS = [
// top left
new Vec2(Pong.RAW_CORNERS[0].x + Pong.PADDLE_WIDTH + Pong.BALL_RADIUS, Pong.RAW_CORNERS[0].y),
// top right
new Vec2((Pong.RAW_CORNERS[1].x - Pong.PADDLE_WIDTH) - Pong.BALL_RADIUS, Pong.RAW_CORNERS[1].y),
// bottom right
new Vec2((Pong.RAW_CORNERS[2].x - Pong.PADDLE_WIDTH) - Pong.BALL_RADIUS, Pong.RAW_CORNERS[2].y),
// bottom left
new Vec2(Pong.RAW_CORNERS[3].x + Pong.PADDLE_WIDTH + Pong.BALL_RADIUS, Pong.RAW_CORNERS[3].y)
];
Pong.BOARD_BOUNDS = [
// top
[new Line(Pong.BOARD_CORNERS[0], Pong.BOARD_CORNERS[1]), false],
// left
[new Line(Pong.BOARD_CORNERS[0], Pong.BOARD_CORNERS[3]), true],
// bottom
[new Line(Pong.BOARD_CORNERS[3], Pong.BOARD_CORNERS[2]), false],
// right
[new Line(Pong.BOARD_CORNERS[1], Pong.BOARD_CORNERS[2]), true]
];
Pong.PADDLE_COLLISION_BOUNDS = [
// top
[new Line(Pong.PADDLE_COLLISION_CORNERS[0], Pong.PADDLE_COLLISION_CORNERS[1]), false],
// left
[new Line(Pong.PADDLE_COLLISION_CORNERS[0], Pong.PADDLE_COLLISION_CORNERS[3]), true],
// bottom
[new Line(Pong.PADDLE_COLLISION_CORNERS[3], Pong.PADDLE_COLLISION_CORNERS[2]), false],
// right
[new Line(Pong.PADDLE_COLLISION_CORNERS[1], Pong.PADDLE_COLLISION_CORNERS[2]), true]
];
// generate random number in range(-1, 1)
function genRandom() {
return (Math.random() - 0.5) * 2;
}
function translateToPosition(element, position) {
translateTo(element, position.x, position.y);
}
function translateTo(element, x, y) {
element.setAttribute('transform', `translate(${x}, ${y})`);
}
//# sourceMappingURL=library.js.map

1
public/js/library.js.map Normal file

File diff suppressed because one or more lines are too long

83
public/js/themes.js Normal file
View File

@ -0,0 +1,83 @@
/**
*
* @source http://tilde.club/~chmod777/js/themes.js
*
* @license AGPL-3.0-only
* @licstart
* Copyright (c) 2021 chmod777
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* @licend
*/
const color_theme_id = "color-theme";
const font_id = "fonts";
function save_theme_settings(theme, font) {
document.cookie = "theme=" + theme + "; path=/";
document.cookie = "font=" + font +"; path=/";
}
function get_saved_theme_settings() {
let cookies = document.cookie.split("; ");
let theme = null;
let font = null;
for (let cookie of cookies) {
let [key, value] = cookie.split("=");
if (key == "theme") {
theme = value;
}
if (key == "font") {
font = value;
}
}
if (theme != null) {
let color_theme = document.getElementById(color_theme_id);
for (option of color_theme.options) {
if (option.value == theme) {
option.selected = true;
break;
}
}
}
if (font != null) {
let fonts = document.getElementById(font_id);
for (option of fonts.options) {
if (option.value == font) {
option.selected = true;
break;
}
}
}
return [theme, font];
}
function load_theme_settings(theme, font) {
const body = document.getElementsByTagName("body")[0];
if (theme && theme.length != 0) {
body.setAttribute("class", theme);
}
if (font && font.length != 0) {
let class_attribute = body.getAttribute("class");
body.setAttribute("class", class_attribute+" "+font);
}
}
function apply_theme_options() {
const theme = document.getElementById(color_theme_id).value;
const font = document.getElementById(font_id).value;
save_theme_settings(theme, font);
load_theme_settings(theme, font);
}
function first_load() {
let [theme, font] = get_saved_theme_settings();
load_theme_settings(theme, font);
}

1
public/projects/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.html

1
public/projects/project/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.html

1
public/tech_demos/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.html

1
public/tech_demos/demos/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.html

1
public/ts/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.ts

4
rustfmt.toml Normal file
View File

@ -0,0 +1,4 @@
hard_tabs = true
condense_wildcard_suffixes = true
imports_layout = "Vertical"
max_width = 80

267
src/main.rs Normal file
View File

@ -0,0 +1,267 @@
use std::fs;
use std::fs::File;
use std::path::Path;
extern crate tera;
use tera::{
Context,
Tera,
};
use serde::{
Deserialize,
Serialize,
};
#[derive(Clone, Debug, Serialize, Deserialize)]
struct SVGConfig {
svgs: Vec<SVGMetadata>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
struct SVGMetadata {
template: String,
title: String,
description: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
struct Post {
full_url: Option<String>,
url: String,
title: String,
summary: String,
date_published: String,
date_modified: Option<String>,
template_name: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
struct Project {
full_url: Option<String>,
url: String,
title: String,
image: String,
summary: String,
template_name: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
struct Config {
posts: Vec<Post>,
tech_demos: Vec<Project>,
projects: Vec<Project>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
struct MyContext {
title: String,
description: String,
canonical_url: String,
favicon_image: String,
page_image: String,
og_type: String,
og_locale: String,
og_site_name: String,
twitter_card: String,
posts: Vec<Post>,
tech_demos: Vec<Project>,
projects: Vec<Project>,
}
impl Default for MyContext {
fn default() -> Self {
Self {
title: "chmod777's homepage".to_owned(),
description: "A place where chmod777 puts their blog posts, project updates, and tech demos.".to_owned(),
canonical_url: "http://tilde.club/~chmod777".to_owned(),
favicon_image: "http://tilde.club/~chmod777/favicon.svg".to_owned(),
page_image: "http://tilde.club/~chmod777/favicon.svg".to_owned(),
og_type: "website".to_owned(),
og_locale: "en-US".to_owned(),
og_site_name: "tilde.club".to_owned(),
twitter_card: "summary".to_owned(),
posts: Vec::new(),
tech_demos: Vec::new(),
projects: Vec::new(),
}
}
}
fn get_file(path: &str) -> File {
let path = Path::new(path);
let display = path.display();
match File::create(path) {
Ok(file) => file,
Err(error) => panic!("Couldn't create file {}: {}", &display, &error),
}
}
fn read_file(path: &str) -> String {
fs::read_to_string(path).expect(&format!("Failed to read file: {}", path))
}
fn append_str(base: &str, extend: &str) -> String {
let mut s = base.to_owned();
s.push_str(extend);
s
}
fn main() {
{
fs::copy("ts/src/base.ts", "public/ts/base.ts").unwrap();
fs::copy("ts/src/pong.ts", "public/ts/pong.ts").unwrap();
}
{
let svg_tera = match Tera::new("svg_templates/**/*") {
Ok(tera) => tera,
Err(error_s) => panic!("Parsing error(s): {}", error_s),
};
let svg_config_json_string = read_file("svg_config.json");
let svg_config: SVGConfig =
serde_json::from_str(&svg_config_json_string).unwrap();
for metadata in svg_config.svgs.iter() {
let temp_path = append_str("templates/svg/", &metadata.template);
let path = append_str("public/assets/svg/", &metadata.template);
svg_tera
.render_to(
&metadata.template,
&Context::from_serialize(&metadata).unwrap(),
get_file(&temp_path),
)
.unwrap();
fs::copy(temp_path, path).unwrap();
}
}
let tera = match Tera::new("templates/**/*") {
Ok(tera) => tera,
Err(error_s) => panic!("Parsing error(s): {}", error_s),
};
let config_json_string = read_file("config.json");
let config: Config = serde_json::from_str(&config_json_string).unwrap();
let mut context = MyContext::default();
let base_url = "http://tilde.club/~chmod777";
for mut post in config.posts.iter().cloned() {
post.full_url = Some(append_str(base_url, &post.url));
context.posts.push(post);
}
for mut demo in config.tech_demos.iter().cloned() {
demo.full_url = Some(append_str(base_url, &demo.url));
context.tech_demos.push(demo)
}
for mut project in config.projects.iter().cloned() {
project.full_url = Some(append_str(base_url, &project.url));
context.projects.push(project);
}
tera.render_to(
"index.html",
&Context::from_serialize(&context).unwrap(),
get_file("public/index.html"),
)
.unwrap();
{
context.title = "About JavaScript".to_owned();
context.canonical_url =
"http://tilde.club/~chmod777/about/javascript.html".to_owned();
let blog_context = Context::from_serialize(&context).unwrap();
tera.render_to(
"javascript.html",
&blog_context,
get_file("public/about/javascript.html"),
)
.unwrap();
}
{
context.title = "chmod777's blog".to_owned();
context.canonical_url =
"http://tilde.club/~chmod777/blog/blog.html".to_owned();
let blog_context = Context::from_serialize(&context).unwrap();
tera.render_to(
"blog/blog.html",
&blog_context,
get_file("public/blog/blog.html"),
)
.unwrap();
tera.render_to("feed.rss", &blog_context, get_file("public/feed.rss"))
.unwrap();
context.og_type = "article".to_owned();
for post in context.posts.iter() {
context.canonical_url = post.full_url.clone().unwrap();
context.description = post.summary.clone();
let path = append_str("public", &post.url);
tera.render_to(
&post.template_name,
&Context::from_serialize(&context).unwrap(),
get_file(&path),
)
.unwrap();
}
}
{
context.title = "chmod777's projects".to_owned();
context.og_type = "website".to_owned();
context.canonical_url =
"http://tilde.club/~chmod777/projects/projects.html".to_owned();
context.description = "".to_owned();
tera.render_to(
"projects/projects.html",
&Context::from_serialize(&context).unwrap(),
get_file("public/projects/projects.html"),
)
.unwrap();
for project in context.projects.iter() {
context.canonical_url = project.full_url.clone().unwrap();
context.description = project.summary.clone();
let path = append_str("public", &project.url);
tera.render_to(
&project.template_name,
&Context::from_serialize(&context).unwrap(),
get_file(&path),
)
.unwrap();
}
}
{
context.title = "chmod777's tech demos".to_owned();
context.canonical_url =
"http://tilde.club/~chmod777/tech_demos/tech_demos.html".to_owned();
context.description = "".to_owned();
tera.render_to(
"tech_demos/tech_demos.html",
&Context::from_serialize(&context).unwrap(),
get_file("public/tech_demos/tech_demos.html"),
)
.unwrap();
for demo in context.tech_demos.iter() {
context.canonical_url = demo.full_url.clone().unwrap();
context.description = demo.summary.clone();
let path = append_str("public", &demo.url);
tera.render_to(
&demo.template_name,
&Context::from_serialize(&context).unwrap(),
get_file(&path),
)
.unwrap();
}
}
}

25
svg_config.json Normal file
View File

@ -0,0 +1,25 @@
{
"svgs": [
{
"template": "chat-bubbles-icon.svg",
"title": "Chat Bubbles Icon",
"description": "Two overlapping chat bubbles."
},
{
"template": "gears-icon.svg",
"title": "Gears Icon",
"description": "Two interlocking gears that spin on mouse hover."
},
{
"template": "paper-list-icon.svg",
"title": "Stacked Papers with Bulleted List Icon",
"description": "Two stacked sheet of paper. A bullet list is depicted on the top sheet."
},
{
"template": "pong.svg",
"title": "Pong (Video Game) Table",
"description": "Two rectangle paddles one on either end; A horizontal dashed line and a circle in the center; Boardered by a gradiant from left to right, from green to red."
}
]
}

View File

@ -1,8 +1,17 @@
<svg viewBox="0 0 64 64" preserveAspectRatio="xMinYMin meet"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink= "http://www.w3.org/1999/xlink">
{% import "macros.xml" as macros %}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 64 64"
width="64"
height="64"
preserveAspectRatio="xMinYMin meet"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink= "http://www.w3.org/1999/xlink">
<title>Chat Bubble Icon</title>
<desc>Two overlapping chat bubbles.</desc>
<title>{{ title | safe }}</title>
<desc>{{ description | safe }}</desc>
{{ macros::metadata() }}
<defs>
<mask id="chat-mask">

Before

Width:  |  Height:  |  Size: 843 B

After

Width:  |  Height:  |  Size: 986 B

View File

@ -1,10 +1,15 @@
{% import "macros.xml" as macros %}
<svg viewBox="0 0 65 65"
width="32" height="32"
preserveAspectRatio="none"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
width="64"
height="64"
preserveAspectRatio="xMinYMin meet"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Gears Icon</title>
<desc>Two interlocking gears.</desc>
<title>{{ title | safe }}</title>
<desc>{{ description | safe }}</desc>
{{ macros::metadata() }}
<defs>
<circle id="gear_hole" r="3" cx=" 12" cy="0" />
@ -52,11 +57,41 @@
</defs>
<g transform="translate(24 40) rotate(-9)"><g>
<use xlink:href="#large_gear" class="gear forward_gear" />
</g></g>
<g transform="translate(24 40) rotate(-9)">
<g>
<use xlink:href="#large_gear" class="gear forward_gear" />
</g>
</g>
<g transform="translate(49 15) rotate(9) scale(0.65 0.65)"><g>
<use xlink:href="#small_gear" class="gear reverse_gear" />
</g></g>
<g transform="translate(49 15) rotate(9) scale(0.65 0.65)">
<g>
<use xlink:href="#small_gear" class="gear reverse_gear" />
</g>
</g>
<style>
.gear {
animation-duration: 10s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-play-state: paused;
}
.forward_gear {
animation-name: rotate_gear_forward;
}
.reverse_gear {
animation-name: rotate_gear_reverse;
}
@keyframes rotate_gear_forward {
from {transform: none;}
to {transform: rotate(-720deg);}
}
@keyframes rotate_gear_reverse {
from {transform: none;}
to {transform: rotate(720deg);}
}
svg:hover .gear {
animation-play-state: running;
}
</style>
</svg>

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

32
svg_templates/macros.xml Normal file
View File

@ -0,0 +1,32 @@
{% macro metadata() %}
<metadata id="license"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#">
<rdf:RDF>
<cc:Work rdf:about="http://tilde.club/~chmod777/svg/chat-bubbles-icon.svg">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:creator>chmod777</dc:creator>
<dc:title>{{ title | safe }}</dc:title>
<dc:description>{{ description | safe }}</dc:description>
<cc:license rdf:resource="http://creativecommons.org/licenses/by-nc-sa/4.0/" />
</cc:Work>
<cc:License rdf:about="http://creativecommons.org/licenses/by-nc-sa/4.0/">
<cc:lecalcode rdf:resource="http://creativecommons.org/licenses/by-nc-sa/4.0/legalcode.txt" />
<cc:permits rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:permits rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:requires rdf:resource="http://creativecommons.org/ns#ShareAlike" />
<cc:prohibits rdf:resource="http://creativecommons.org/ns#CommercialUse "/>
</cc:License>
</rdf:RDF>
</metadata>
{% endmacro metadata %}

View File

@ -1,11 +1,15 @@
{% import "macros.xml" as macros %}
<svg viewBox="0 0 64 64"
preserveAspectRatio="none"
width="64" height="64"
width="64"
height="64"
preserveAspectRatio="xMinYMin meet"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink= "http://www.w3.org/1999/xlink">
<title>Paper List Icon</title>
<desc>Two stacked pieces of paper with a list on the top piece.</desc>
<title>{{ title | safe }}</title>
<desc>{{ description | safe }}</desc>
{{ macros::metadata() }}
<defs>
<g id="item">

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

78
svg_templates/pong.svg Normal file
View File

@ -0,0 +1,78 @@
{% import "macros.xml" as macros %}
<svg viewBox="0 0 532 276"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<title>{{ title | safe }}</title>
<desc>{{ description | safe }}</desc>
{{ macros::metadata() }}
<defs>
<linearGradient id="pong-gradient" x1="0%" y1="0%" x2="100%" y2="0%">
<stop id="pong-gradiant-begin" offset="0%" />
<stop id="pong-gradiant-end" offset="100%" />
</linearGradient>
</defs>
<rect id="pong-boarder" width="100%" height="100%" />
<svg x="10" y="10" width="512" height="256" >
<rect id="pong-board" width="100%" height="100%" />
<path id="pong-ball-path" d="M256 128" />
<path id="pong-collision-path" d="M256 128" />
<line id="pong-center-line" x1="256" y1="0" x2="256" y2="256" />
<rect id="pong-player-paddle" width="2" height="28" transform="translate(0, 114)"/>
<rect id="pong-ai-paddle" width="2" height="28" transform="translate(510, 114)"/>
<text id="pong-player-score" class="pong-score" x="85.33" y="64">0</text>
<text id="pong-ai-score" class="pong-score" x="426.66" y="64">0</text>
<circle id="pong-ball" r="3">
<animateMotion id="pong-ball-animation" dur="1.0s" repeatCount="indefinite">
<mpath xlink:href="#pong-ball-path"/>
</animateMotion>
</circle>
</svg>
<style>
#pong-gradiant-begin {
stop-color:blue;
stop-opacity:1;
}
#pong-gradiant-end {
stop-color:red;
stop-opacity:1;
}
#pong-boarder {
fill:url(#pong-gradient);
}
#pong-board {
fill:black;
}
#pong-ball-path {
stroke:blue;
}
#pong-collision-path {
stroke:red;
stroke-dasharray:1;
}
#pong-center-line {
stroke:white;
stroke-dasharray:5;
stroke-width:2;
}
#pong-ai-paddle,#pong-player-paddle,.pong-score {
fill:white;
}
.pong-score {
font-family:'Courier New',Courier,monospace;font-size:2em;
}
#pong-ball {
fill:white;
}
</style>
</svg>

26
templates/base.html Executable file
View File

@ -0,0 +1,26 @@
<!doctype html>
<html lang="en">
<head>
{% include "base_head_inner.html" %}
{% block page_specific_head %}{% endblock page_specific_head %}
</head>
<body class="dark-theme monospace-font" onload="first_load()">
{% include "header.html" %}
{% include "theme_options.html" %}
<main>
<aside>
{% block page_aside %}{% endblock page_aside %}
</aside>
<div id="page-content">
{% block page_content %}{% endblock page_content %}
</div>
</main>
{% include "footer.html" %}
</body>
</html>

View File

@ -0,0 +1,23 @@
<meta charset="utf-8">
<title>{{ title | safe }}</title>
<meta name="description" content="{{ description | safe }}">
<meta name="author" content="chmod777">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:type" context="{{ og_type | safe }}">
<meta property="og:title" context="{{ title | safe }}">
<meta property="og:description" context="{{ description | safe }}">
<meta property="og:url" context="{{ canonical_url | safe }}">
<meta property="og:image" context="{{ page_image | safe }}">
<meta property="og:local" context="{{ og_locale | safe }}">
<meta property="og:site_name" context="{{ og_site_name | safe }}">
<meta property="twitter:card" context="{{ twitter_card | safe }}">
<meta property="twitter:title" context="{{ title | safe }}">
<meta property="twitter:description" context="{{ description | safe }}">
<meta property="twitter:url" context="{{ canonical_url | safe }}">
<meta property="twitter:image" context="{{ page_image | safe }}">
<link rel="canonical" href="{{ canonical_url | safe }}">
<link rel="stylesheet" href="/css/styles.css">
<script src="/js/themes.js"></script>

42
templates/blog/blog.html Normal file
View File

@ -0,0 +1,42 @@
{% extends "base.html" %}
{% import "macros.html" as macros %}
{% block page_specific_head %}
<link rel="alternate" type="application/rss+xml" href="/feed.rss" title="RSS feed for chmod777's blog" >
{% endblock page_specific_head %}
{% block page_aside %}
<aside id="skip-links">
<nav>
<a type="application/rss+xml" href="/feed.rss">RSS feed for this blog</a>
<h3>Posts</h3>
<ul class="link-list">
{% for post in posts %}
<li><a href="#post-card-{{ post.title }}">skip to "{{ post.title | safe }}"</a></li>
{% endfor %}
</ul>
<!--
<h3><a href="/blog/archived.html">Archived Posts</a></h3>
-->
<h3>Posts From Blogs That I Read</h3>
<ul class="link-list">
<li><a href="https://rhapsode.adrian.geek.nz/2020/10/31/why-auditory.html">Why an Auditory Browser?</a></li>
</ul>
</nav>
</aside>
{% endblock page_aside %}
{% block page_content %}
<section tabindex="0">
<h2>Posts</h2>
{% for post in posts %}
{{ macros::post_card(post=post) }}
{% endfor %}
</section>
<section tabindex="0">
<h2>Posts From Blogs That I Read</h2>
</section>
{% endblock page_content %}

View File

@ -0,0 +1,109 @@
{% extends "base.html" %}
{% import "macros.html" as macros %}
{% block page_aside %}
<nav>
<h3>Skip Links</h3>
<ul class="link-list">
<li><a href="#article-header">skip to "Pi Pico First Impressions"</a></li>
<li><a href="#language-support">skip to "Language Support"</a></li>
<li><a href="#real-applications">skip to "Real Applications"</a></li>
</ul>
</nav>
{% endblock page_aside %}
{% block page_content %}
<header id="article-header" aria-label="Pi Pico First Impressions" tabindex="0">
<h2>Pi Pico First Impressions</h2>
<p>Specs? Who need those. I wont go deep into the specs because that would be a waist of our time. You can look them up <a href="">somewhere else</a>.</p>
<h3>What is this dual core ARM M0+ microprocessor good for?</h3>
<p></p>
<h3>What shouldn't you use it for?</h3>
<p>This isn't a linux computer like the other Raspberry Pis so don't bother trying to host a server on it or use it to emulate your favorite retro device. Though you certaintly can if you <a href="">try</a>.</p>
<p>It doesn't have wireless connectivity built into it like the esp devices so you have to bring your own at which point you might consider an integrated solution.</p>
</header>
<section id="language-support" aria-label="Language Support" tabindex="0">
<h3>Language Support</h3>
<p>The Raspberry Pi foundation supports two languages on the Pi Pico. C and their port of MicroPython to the board.</p>
<p></p>
<table>
<summary>Table summary</summary>
<thead>
<th>Language</th>
<th>Backer</th>
<th>Recommended IDE</th>
<th>Documentation</th>
</thead>
<tr>
<td>C</td>
<td>Raspberry Pi Foundation</td>
<td>Visual Studio Code</td>
<td>
<ul>
<li>PDF</li>
<li>Website</li>
</ul>
</td>
</tr>
<tr>
<td>MicroPython</td>
<td>Raspberry Pi Foundation</td>
<td>Thonny</td>
<td>
<ul>
<li>PDF</li>
<li>MicroPython Website</li>
</ul>
</td>
</tr>
<tr>
<td>CircuitPython</td>
<td>Adafruit</td>
<td>MuPython</td>
<td>
<ul>
<li>Website</li>
</ul>
</td>
</tr>
<tr>
<td>Arduino C</td>
<td>Arduino</td>
<td>Arduino IDE</td>
<td>
<ul>
<li>Website</li>
</ul>
</td>
</tr>
</table>
</section>
<section id="real-applications" aria-label="Real Applications" tabindex="0">
<h3>Real Applications</h3>
<h4>C++ and MicroPython Support</h4>
<p>To test the language support I created the same program in both MicroPython and C++ using the C SDK. In each program I wrote a driver for the <a href="">MPU-6050</a> a sensor with 6 degrees of freedom, and used it to control 2 servos in order to level them.</p>
<figure>
<img src=""
title="Test Program Setup"
alt="A Pi Pico on a bread board connected to an MPU-6050 and two servos via jumper wires.">
<figcaption>The MPU-6050 is connected to one of the Pico's i2c busses while the servos are connected to PWM pins.</figcaption>
</figure>
<h4>Programmable IO (PIO)</h4>
<p>To test the PIO feature of the board I wrote two programs using the C SDK. Each of them poll a <a href="">key matrix</a> similar to what you would find on a USB keyboard. The first program does it by setting GPIO pins using one of the main cores of the microcontroller while the other polls the keys using the programmable IO state machines.</p>
<figure>
<img src=""
title="Keyboard Matrix Wiring Diagram"
alt="A wiring diagram for a 3 by 3 keyboard matrix.">
<figcaption>Each row is connected to each column by a diode and a button in parrallel. The diodes are oriented so that current flows from the rows to the columns.</figcaption>
</figure>
</section>
{% endblock page_content %}

25
templates/feed.rss Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>chmod777's blog</title>
<link>http://tilde.club/~chmod777/blog/blog.html</link>
<description>chmod777's blog where they post about their tech and non tech projects.</description>
<language>en-us</language>
<category>blog</category>
<managingEditor>chmod777@tilde.club</managingEditor>
<webMaster>chmod777@tilde.club</webMaster>
{% for post in posts %}
<item>
<title>{{ post.title | safe }}</title>
<link>{{ post.full_url | safe }}</link>
<description>{{ post.summary | safe }}</description>
{% if post.image %}
<image>{{ post.image | safe }}</image>
{% endif %}
</item>
{% endfor %}
</channel>
</rss>

13
templates/footer.html Normal file
View File

@ -0,0 +1,13 @@
<footer>
<a class="link-padding" href="#">jump to top</a>
<br>
<br>
<a class="link-padding" id="page-source" target="_blank" href="https://tildegit.org/chmod777/my_blog">page source (tildegit in new tab)</a>
<br>
<br>
<p>The contents of this site unless otherwise denoted are licensed under</p>
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)</a>
<br>
<br>
<a href="/about/javascript" rel="jslicense">JavaScript license information</a>
</footer>

16
templates/header.html Normal file
View File

@ -0,0 +1,16 @@
<header>
<h1 id="title">{{ title | safe }}</h1>
<a href="#page-content">skip to page content</a>
<p>Since February 2021</p>
<!--
<p>There is a version of this site available as a <a href="gemini://tilde.club/~chmod777">gemini capsule</a>. It may or may not be up to date.</p>
-->
<nav>
<ul class="link-list">
<li><a href="/">home</a></li>
<li><a href="/blog/blog.html">blog</a></li>
<li><a href="/projects/projects.html">projects</a></li>
<li><a href="/tech_demos/tech_demos.html">tech demos</a></li>
</ul>
</nav>
</header>

58
templates/index.html Normal file
View File

@ -0,0 +1,58 @@
{% extends "base.html" %}
{% import "macros.html" as macros %}
{% block page_aside %}
<nav>
<h3>skip links</h3>
<ul class="link-list">
<li><a href="#introductions">skip to "Introductions"</a></li>
<li><a href="#contact-info">skip to "Contact Info"</a></li>
<li><a href="#latest-posts">skip to "Latest Posts"</a></li>
<li><a href="#botany">skip to "My Botany Plant"</a></li>
</ul>
</nav>
{% endblock page_aside %}
{% block page_content %}
<section id="introductions" aria-label="Introductions">
<h2>Introductions</h2>
<p>Hello!</p>
<p>On the internet I go by chmod777. Feel free to ask me anything.</p>
<p>A computer science graduate with only vague ideas of what they are doing in life.</p>
<p>I just finished working a seasonal job that took up all of my free time so I am excited to get back into my projects and hobbies which will be the the focus of this blog.</p>
<p>If you follow me on mastodon you may have seen my posts about one of my projects Roll Lang. It is a dice notation interpreter with similar syntax to Roll20's. It's getting close to a 1.0 version. You can expect a post about it soon.</p>
<p>A project that I just started is a RISC V assembler. I wanted to get away from comming up with my own spec for a language for a while and figured an assembly language would be one of the simplest to implement.</p>
<p>Gardening is a hobby of mine. I'll give an update on the garden when I prune the cherry and apple trees this fall.</p>
<p>I've slowly been building an aluminium Settlers of Cattan board out of casted aluminum tiles. This is my longest running project mostly due to the weather, my casting setup, and motivation to deal with both. Also my 3D modeling skills could use some work.</p>
<p>It's been years since I've used an arduino but I recently bought a Raspberry Pi Pico and have been tinkering with it, as well as diving into KiCad. I've been designing a wireless controller for future electronics projects which may include a wheeled robot, and/or a drone.</p>
<p>I've started many Vulkan, OpenGL, and WebGL projects with grand intentions. One of these days I'll get around to getting one of them into a state that I feel is worth sharing.</p>
<p>I don't want this just to be a void where I put stuff. If you have any questions or want to discuss what I put here send me a message.</p>
</section>
<section id="contact-info" aria-label="Contact Info">
<h2>Contact Info</h2>
<ul>
<li>fediverse/mastodon: @chmod777@tilde.zone</li>
<li>irc.tilde.chat: chmod777</li>
<li>gitea: tildegit.org/chmod777</li>
</ul>
</section>
<section id="latest-posts" aria-label="Latest Posts">
<h2>Latest Posts</h2>
{% for post in posts | slice(end=3) %}
{{ macros::post_card(post=post) }}
{% endfor %}
<ul>
<li><a href="/blog/blog.html">blog home page</a></li>
<!--
<li><a href="/blog/archived.html">archived posts</a></li>
-->
</ul>
</section>
<section id="botany" tabindex="0" aria-label="My Botany Plant">
<h2>My Botany Plant</h2>
</section>
{% endblock page_content %}

43
templates/javascript.html Normal file
View File

@ -0,0 +1,43 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>About JavaScript</title>
<meta name="description" content="">
<meta name="author" content="chmod777">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="http://tilde.club/chmod777/about/javascript.html">
</head>
<body class="dark-theme monospace-font" onload="first_load()">
<nav>
<a href="/">chmod777's homepage</a>
</nav>
<main>
<table id="jslicense-labels1">
<tr>
<th>JavaScript</th>
<th>License</th>
<th>Source</th>
</tr>
<tr>
<td><a href="/js/library.js">library.js</a></td>
<td><a href="http://www.gnu.org/licenses/agpl-3.0.html">AGPL-v3-only</a></td>
<td>
<a href="/ts/base.ts">base.ts</a>
<a href="/ts/pong.ts">pong.ts</a>
</td>
</tr>
<tr>
<td><a href="/js/themes.js">themes.js</a></td>
<td><a href="http://www.gnu.org/licenses/agpl-3.0.html">AGPL-v3-only</a></td>
</tr>
</table>
</main>
{% include "footer.html" %}
</body>
</html>

24
templates/macros.html Normal file
View File

@ -0,0 +1,24 @@
{% macro post_card(post) %}
<section class="post-card post-card-grid" id="post-card-{{ post.title | safe }}">
<h3 class="post-card-title"><a href="{{ post.url | safe }}">{{ post.title | safe }}</a></h3>
<span class="post-card-published">date published: <time datetime="{{ post.date_published | safe }}">{{ post.date_published | safe }}</time></span>
{% if post.date_modified %}
<span class="post-card-modified">last modified: <time datetime="{{ post.date_modified | safe }}">{{ post.date_modified | safe }}</time></span>
{% endif %}
<p class="post-card-content">{{ post.summary }}</p>
</section>
<br>
{% endmacro post_card %}
{% macro project_card(project) %}
<li class="post-card">
<a class="project-card" href="{{ project.url | safe }}">
<img class="project-img"
src="{{ project.image | safe }}">
<h2 class="project-title">
{{project.title | safe}}
</h2>
<p class="project-description">{{ project.summary | safe }}</p>
</a>
</li>
{% endmacro post_card %}

View File

@ -0,0 +1,56 @@
{% extends "base.html" %}
{% import "macros.html" as macros %}
{% block page_specific_head %}
{% endblock page_specific_head %}
{% block page_aside %}
{% endblock page_aside %}
{% block page_content %}
<h2>Creative Commons Icons</h2>
<p>The icons on this page are licensed under the <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode">Creative Commons Attribution-NonCommercial-ShareAlike 4.0</a> license.</p>
<ul>
<li class="post-card">
<figure>
{% include "svg/paper-list-icon.svg" %}
<figcaption>Two stacked sheets of paper. The top sheet depicts a bulleted list.</figcaption>
</figure>
<a href="/assets/svg/paper-list-icon.svg" download>Download Stacked Sheets</a>
</li>
<li class="post-card">
<figure>
{% include "svg/chat-bubbles-icon.svg" %}
<figcaption>Two overlapping chat bubbles.</figcaption>
</figure>
<a href="/assets/svg/chat-bubbles-icon.svg" download>Download Chat Bubbles</a>
</li>
<li class="post-card">
<figure>
{% include "svg/gears-icon.svg" %}
<figcaption>Two interlocking gears. Hover to see them spin.</figcaption>
</figure>
<a href="/assets/svg/gears-icon.svg" download>Download Gears</a>
</li>
</ul>
<style>
li {
display: flex;
}
li a {
justify-self: center;
margin-top: auto;
margin-bottom: auto;
padding: 10px 10px 10px 10px;
}
figure {
display: inline-block;
background: #444;
}
figcaption {
width: 220px;
}
</style>
{% endblock page_content %}

View File

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% import "macros.html" as macros %}
{% block page_specific_head %}
<link rel="stylesheet" href="/css/project_styles.css">
{% endblock page_specific_head %}
{% block page_aside %}
{% endblock page_aside %}
{% block page_content %}
<ul id="project-list">
{% for project in projects %}
{{ macros::project_card(project=project) }}
{% endfor %}
</ul>
{% endblock page_content %}

1
templates/svg/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.svg

View File

@ -0,0 +1,26 @@
{% extends "base.html" %}
{% block page_specific_head %}
<link rel="stylesheet" href="/css/pong_settings.css">
<script defer="true" type="text/javascript" src="/assets/js/library.js"></script>
{% endblock page_specific_head %}
{% block page_aside %}
{% include "tech_demos/demos/svg_pong/about_pong.html" %}
{% endblock page_aside %}
{% block page_content %}
{% include "tech_demos/demos/svg_pong/about_svg_pong.html" %}
<p>fps: <span id="fps"></span></p>
{% include "tech_demos/demos/svg_pong/pong.svg" %}
{% include "tech_demos/demos/svg_pong/pong_controlls.html" %}
<!--
{% include "tech_demos/demos/svg_pong/pong_settings.html" %}
{% include "tech_demos/demos/svg_pong/pong_game_summary_table.html" %}
{% include "tech_demos/demos/svg_pong/pong_latest_games_table.html" %}
-->
{% endblock page_content %}

View File

@ -0,0 +1,15 @@
<header>
<h2>The Game of Pong</h2>
From <a href="">Wikipedia's Pong article</a>
</header>
<br>
<section>
"Pong is a table tennisthemed arcade sports video game, featuring simple two-dimensional graphics, manufactured by Atari and originally released in 1972. It was one of the earliest arcade video games"
<hr>
"Pong was the first commercially successful video game, and it helped to establish the video game industry along with the Magnavox Odyssey. Soon after its release, several companies began producing games that closely mimicked its gameplay."
<hr>
"The game was remade on numerous home and portable platforms following its release. Pong is part of the permanent collection of the Smithsonian Institution in Washington, D.C., due to its cultural impact."
</section>
<footer>
</footer>

View File

@ -0,0 +1,56 @@
<article>
<header>
<h2>About This Project</h2>
<p>About three years ago(2018) I created a pong game that used Scalable Vector Graphics(SVG) for
the graphics instead of a traditional HTML canvas. This is its story.
</p>
<p>Some resources related to SVGs.</p>
<ul>
<li><a href="https://www.wikipedia.org/wiki/Scalable_Vector_Graphics">Scalable Vector Graphics (Wikipedia Article)</a></li>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/SVG">SVG: Scalable Vector Graphics (Mozilla Documentation)</a></li>
</ul>
</header>
<h3>Just Why</h3>
<p>The main reason for this project was to learn about SVG and SVG
animations. Before starting this I had never used an SVG in my own
websites. My only interactions with them was seeing them used on other
websites and the one time I opened up InkScape. Back in the days when I
cared about fancy websites I was envious of the cool animations some
sites had and wanted them for myself.</p>
<p>The thing that motivated me to create a game was seeing the 13k game
jam. A jam that only accepts games whos entire contents fit in 13kb
including all their assets. I had only heard about it after it was already
over that year but that wasn't going to stop me from creating a tiny
game.</p>
<p>Why Pong?</p>
<p>Pong is second only to Tetris[Citation Needed] though I had never played it.
Plus with a game as simple as pong it would be impossible for me not to finish it.
And as it turns out anything is possible.</p>
<h3>Was it a Success?</h3>
<p>Partially. I did create a game that used an SVG instead of an
HTMLCanvas. I learned how to move the paddles using the transform
attribute from JavaScript, as well as move the ball along a path using a
nanimateMotion tag.</p>
<p>As a bonus the game was 9kb when compressed when I had "finnished it".
That included the svg, html, and transpiled typescript.</p>
<p>However the game wasn't finnished when I stopped working on it three years
ago but I feel I achieved my goal. Or rather the pong game took me as far
as it could on my SVG adventure. Or at least that's what I thought back
then...</p>
<h3>The Revitalized SVG Pong</h3>
<p>What you see below is the new and improved SVG Pong, with far fewer bugs,
a cleaner(TM) codebase, and better preformace.</p>
<p>I revisted this project because I thought it would be fun. That really is
the main reason. And guess what. It was fun. I got to track down weird
bugs related to collisions and missing state. The project truely was just
slapped together over a weekend and it show(ed/s).</p>
<p>Try to have fun against the restless AI.</p>
<footer>
<p>If you like SVGs checkout some of my
<a href="/projects/project/creative_commons_icons.html">SVG icons</a>
I made for a now defunct project.</p>
</footer>
</article>

View File

@ -0,0 +1,72 @@
<svg viewBox="0 0 532 276" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Pong</title>
<desc>Two paddles, a ball, vertical dashed line in the center, and two numbers for player scores.</desc>
<defs>
<linearGradient id="pong-gradient" x1="0%" y1="0%" x2="100%" y2="0%">
<stop id="pong-gradiant-begin" offset="0%" />
<stop id="pong-gradiant-end" offset="100%" />
</linearGradient>
</defs>
<rect id="pong-boarder" width="100%" height="100%" />
<svg x="10" y="10" width="512" height="256" >
<rect id="pong-board" width="100%" height="100%" />
<path id="pong-ball-path" d="M256 128" />
<path id="pong-collision-path" d="M256 128" />
<line id="pong-center-line" x1="256" y1="0" x2="256" y2="256" />
<rect id="pong-player-paddle" width="2" height="28" transform="translate(0, 114)"/>
<rect id="pong-ai-paddle" width="2" height="28" transform="translate(510, 114)"/>
<text id="pong-player-score" class="pong-score" x="85.33" y="64">0</text>
<text id="pong-ai-score" class="pong-score" x="426.66" y="64">0</text>
<circle id="pong-ball" r="3">
<animateMotion id="pong-ball-animation" dur="1.0s" repeatCount="indefinite">
<mpath xlink:href="#pong-ball-path"/>
</animateMotion>
</circle>
</svg>
<style>
#pong-gradiant-begin {
stop-color:blue;
stop-opacity:1;
}
#pong-gradiant-end {
stop-color:red;
stop-opacity:1;
}
#pong-boarder {
fill:url(#pong-gradient);
}
#pong-board {
fill:black;
}
#pong-ball-path {
stroke:blue;
}
#pong-collision-path {
stroke:red;
stroke-dasharray:1;
}
#pong-center-line {
stroke:white;
stroke-dasharray:5;
stroke-width:2;
}
#pong-ai-paddle,#pong-player-paddle,.pong-score {
fill:white;
}
.pong-score {
font-family:'Courier New',Courier,monospace;font-size:2em;
}
#pong-ball {
fill:white;
}
</style>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,21 @@
<form>
<fieldset>
<legend>Controlls</legend>
<div>
<label id="pong-reset-label" for="pong-reset">New Game shortcut 'N'</label>
<input id="pong-reset" name="pong-reset" type="button" value="New Game">
<label id="pong-serve-label" for="pong-serve">Serve shortcut 'S'</label>
<input id="pong-serve" name="pong-serve" type="button" value="Serve">
<label id="pong-paddle-up-label" for="pong-paddle-up">Paddle Up shortcut '&#x3c'</label>
<input id="pong-paddle-up" name="pong-paddle-up" type="button" value="Paddle Up">
<label id="pong-paddle-stop-label" for="pong-paddle-stop"></label>
<input id="pong-paddle-stop" name="pong-paddle-stop" type="button" value="Paddle Stop">
<label id="pong-paddle-down-label" for="pong-paddle-down">Paddle Down shortcut '>'</label>
<input id="pong-paddle-down" name="pong-paddle-down" type="button" value="Paddle Down">
</div>
</fieldset>
</form>

View File

@ -0,0 +1,20 @@
<table>
<summary>Game Summary</summary>
<tr>
<td>Difficulty</td>
<th>Won</th>
<th>Lost</th>
<th>Tied</th>
<th>Incomplete</th>
<th>Longest Volley</th>
</tr>
<tr>
<th>Easy</th>
</tr>
<tr>
<th>Normal</th>
</tr>
<tr>
<th>Hard</th>
</tr>
</table>

View File

@ -0,0 +1,10 @@
<table>
<summary>Latest Games</summary>
<tr>
<th>Difficulty</th>
<th>Won/Lost/Tied/Incomplete</th>
<th>Player Score</th>
<th>AI Score</th>
<th>Longest Volley</th>
</tr>
</table>

View File

@ -0,0 +1,23 @@
<form>
<fieldset>
<legend>Game Settings</legend>
<summary></summary>
<div>
<label for="ai-difficulty">AI Difficulty</label>
<select id="ai-difficulty" name="ai-difficulty">
<option value="easy">easy</option>
<option value="normal">normal</option>
<option value="hard">hard</option>
</select>
<label for="paddle-speed">Paddle Speed</label>
<input type="slider" id="paddle-speed" name="paddle-speed">
<label for="ball-speed">Ball Speed</label>
<input type="slider" id="ball-speed" name="ball-speed">
</div>
<input type="button" value="Apply Settings(starts a new game)">
</fieldset>
</form>

View File

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% import "macros.html" as macros %}
{% block page_specific_head %}
<link rel="stylesheet" href="/css/project_styles.css">
{% endblock page_specific_head %}
{% block page_aside %}
{% endblock page_aside %}
{% block page_content %}
<ul id="project-list">
{% for demo in tech_demos %}
{{ macros::project_card(project=demo) }}
{% endfor %}
</ul>
{% endblock page_content %}

View File

@ -0,0 +1,27 @@
<form>
<fieldset>
<legend aria-describedby="about-theme-options">Theme Options</legend>
<p id="about-theme-options">theme options requires javascript</p>
<script>
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-only
const id = "about-theme-options";
const element = document.getElementById(id);
element.innerHTML = element.innerHTML.concat(" (javascript enabled)");
// @license-end
</script>
<label id="color-theme-label" for="color-theme">color theme</label>
<select id="color-theme" name="color-theme">
<option value="dark-theme">dark (default)</option>
<option value="classic-theme">classic</option>
</select>
<label id="fonts-label" for="fonts">fonts</label>
<select id="fonts" name="fonts">
<option value="monospace-font">monospace (default)</option>
<option value="default-font">browser default</option>
</select>
<input type="button" value="apply settings" onclick="apply_theme_options()">
</fieldset>
</form>

73
ts/src/base.ts Normal file
View File

@ -0,0 +1,73 @@
/**
*
* @source http://tilde.club/~chmod777/ts/base.ts
*
* @license AGPL-3.0-only
* @licstart
* Copyright (c) 2021 chmod777
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* @licend
*/
let pong;
window.onload = function() {
pong = new Pong(document);
}
function error(id: string, elementName: string): string {
return `Failed to find ${elementName} element with id "${id}"`;
}
function getHTMLInput(id: string): HTMLInputElement {
const element = document.getElementById(id);
if (element instanceof HTMLInputElement)
return element;
throw error(id, 'html button');
}
function getHTMLSpan(id: string): HTMLSpanElement {
const element = document.getElementById(id);
if (element instanceof HTMLSpanElement)
return element;
throw error(id, 'html span');
}
function getSVGRectElement(svgDocument: Document, id: string): SVGRectElement {
const element = svgDocument.getElementById(id);
if (element instanceof SVGRectElement)
return element;
throw error(id, 'svg rect');
}
function getSVGTextElement(svgDocument: Document, id: string): SVGTextElement {
const element = svgDocument.getElementById(id);
if (element instanceof SVGTextElement)
return element;
throw error(id, 'svg text');
}
function getSVGCircleElement(svgDocument: Document, id: string): SVGCircleElement {
const element = svgDocument.getElementById(id);
if (element instanceof SVGCircleElement)
return element;
throw error(id, 'svg circle');
}
function getSVGAnimateMotionElement(svgDocument: Document, id: string): SVGAnimateMotionElement {
const element = svgDocument.getElementById(id);
if (element instanceof SVGAnimateMotionElement)
return element;
throw error(id, 'svg animate motion');
}
function getSVGPathElement(svgDocument: Document, id: string): SVGPathElement {
const element = svgDocument.getElementById(id);
if (element instanceof SVGPathElement)
return element;
throw error(id, 'svg path');
}

603
ts/src/pong.ts Normal file
View File

@ -0,0 +1,603 @@
/**
*
* @source http://tilde.club/~chmod777/ts/pong.ts
*
* @license AGPL-3.0-only
* @licstart
* Copyright (c) 2021 chmod777
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* @licend
*/
class Vec2 {
constructor(public x: number, public y: number) {}
static zero(): Vec2 {
return new Vec2(0, 0);
}
static one(): Vec2 {
return new Vec2(1, 1);
}
public clone(): Vec2 {
return new Vec2(this.x, this.y);
}
public add(other: Vec2): Vec2 {
return new Vec2(this.x + other.x, this.y + other.y);
}
public sub(other: Vec2): Vec2 {
return new Vec2(this.x - other.x, this.y - other.y);
}
public mul(s: number): Vec2 {
return new Vec2(this.x * s, this.y * s);
}
public div(s: number): Vec2 {
return new Vec2(this.x / s, this.y / s);
}
public cross(other: Vec2): number {
return this.x * other.y - this.y * other.x;
}
public dot(other: Vec2): number {
return this.x * other.y + this.y * other.y;
}
public magnitude2(): number {
return this.x * this.x + this.y * this.y;
}
public magnitude(): number {
return Math.sqrt(this.magnitude2());
}
public asUnit(): Vec2 {
return this.div(this.magnitude());
}
static numberAsString(n: number): string {
if (n != Math.floor(n)) {
n.toFixed(2);
}
return n.toString();
}
public asString(): string {
return `${Vec2.numberAsString(this.x)},${Vec2.numberAsString(this.y)} `;
}
public asAbsolute(): string {
return `M${this.asString()}`;
}
public asLine(): string {
return `L${this.asString()}`;
}
}
class Line {
constructor(public p1: Vec2, public p2: Vec2) {}
public lineLineIntersect(l2: Line): null | Vec2 {
const p = this.p1;
const r = this.p2.sub(p);
const q = l2.p1;
const s = l2.p2.sub(q);
const r_cross_s = r.cross(s);
const q_minus_p = q.sub(p);
if (r_cross_s === 0) {
return null;
// let q_minus_p_cross_r = q_minus_p.cross(r);
// if (q_minus_p_cross_r === 0)
// return null; // collinear
// else
// return null; // parallel
} else {
const t = q_minus_p.cross(s.div(r_cross_s));
const u = q_minus_p.cross(r.div(r_cross_s));
if (0 <= t && t <= 1 && 0 <= u && u <= 1) {
if (t === 0)
return q.add(s.mul(u));
else
return p.add(r.mul(t));
}
else {
return null; // divergent
}
}
}
}
class PongElements {
public playerPaddle: SVGRectElement;
public aiPaddle: SVGRectElement;
public playerScoreElement: SVGTextElement;
public aiScoreElement: SVGTextElement;
public ball: SVGCircleElement;
public ballAnimation: SVGAnimateMotionElement;
public ballPath: SVGPathElement;
public collisionPath: SVGPathElement;
public resetButton: HTMLInputElement;
public serveButton: HTMLInputElement;
public upButton: HTMLInputElement;
public stopButton: HTMLInputElement;
public downButton: HTMLInputElement;
public fps: HTMLSpanElement;
constructor(svgContent: Document) {
this.playerPaddle = getSVGRectElement(svgContent, 'pong-player-paddle');
this.aiPaddle = getSVGRectElement(svgContent, 'pong-ai-paddle');
this.playerScoreElement = getSVGTextElement(svgContent, 'pong-player-score');
this.aiScoreElement = getSVGTextElement(svgContent, 'pong-ai-score');
this.ball = getSVGCircleElement(svgContent, 'pong-ball');
this.ballAnimation = getSVGAnimateMotionElement(svgContent, 'pong-ball-animation');
this.ballPath = getSVGPathElement(svgContent, 'pong-ball-path');
this.collisionPath = getSVGPathElement(svgContent, 'pong-collision-path');
this.resetButton = getHTMLInput('pong-reset');
this.serveButton = getHTMLInput('pong-serve');
this.upButton = getHTMLInput('pong-paddle-up');
this.stopButton = getHTMLInput('pong-paddle-stop');
this.downButton = getHTMLInput('pong-paddle-down');
this.fps = getHTMLSpan('fps');
const WIDTH_STRING = Pong.PADDLE_WIDTH.toString();
this.aiPaddle.setAttribute('width', WIDTH_STRING);
this.playerPaddle.setAttribute('width', WIDTH_STRING);
const BALL_RADIUS_STRING = Pong.BALL_RADIUS.toString();
this.ball.setAttribute('r', BALL_RADIUS_STRING);
this.resetPaddles();
this.resetBall();
}
public resetBall() {
this.ballPath.setAttribute('d', Pong.ABSOLUTE_CENTER);
this.collisionPath.setAttribute('d', Pong.ABSOLUTE_CENTER);
this.ballAnimation.beginElement();
}
public resetPaddles() {
translateToPosition(this.playerPaddle, Pong.PLAYER_STARTING_POSITION);
translateToPosition(this.aiPaddle, Pong.AI_STARTING_POSITION);
}
public resetScores() {
this.playerScoreElement.innerHTML = '0';
this.aiScoreElement.innerHTML = '0';
}
}
class PongState {
public lastAnimationFrame = 0;
public playerPosition = Pong.PLAYER_STARTING_POSITION.clone();
public aiPosition = Pong.AI_STARTING_POSITION.clone();
public ballSpeed = Pong.BALL_BASE_SPEED;
public ballVelocity = Vec2.zero();
public running = false;
public shouldServe = false;
public playerServe = false;
public time = 0;
public lastTime = 0;
public serveTime = 0;
public dt_ms = 0;
public dt = 0;
public playerScore = 0;
public aiScore = 0;
public scoreDuration = 0;
public collisionDuration = 0;
public collisionPoint = Vec2.zero();
public moveUp = false;
public moveDown = false;
get timeSinceServe(): number { return (this.time - this.serveTime) / 1000; }
public update_dt(time: number) {
this.lastTime = this.time;
this.time = time;
this.dt_ms = this.time - this.lastTime;
this.dt = this.dt_ms / 1000;
}
public resetBall() {
this.ballSpeed = Pong.BALL_BASE_SPEED;
this.ballVelocity = Vec2.zero();
}
public resetPaddles() {
this.playerPosition = Pong.PLAYER_STARTING_POSITION.clone();
this.aiPosition = Pong.AI_STARTING_POSITION.clone();
this.moveUp = false;
this.moveDown = false;
}
}
class Pong {
/*
x w
y +---------------------+
| | |
h | 0 |
| | |
+---------------------+
*/
static readonly WIDTH = 512;
static readonly HEIGHT = 256;
static readonly HALF_WIDTH = Pong.WIDTH / 2;
static readonly HALF_HEIGHT = Pong.HEIGHT / 2;
static readonly CENTER = new Vec2(Pong.HALF_WIDTH, Pong.HALF_HEIGHT);
static readonly ABSOLUTE_CENTER = Pong.CENTER.asAbsolute();
static readonly PADDLE_WIDTH = 4;
static readonly PADDLE_HEIGHT = 28;
static readonly PADDLE_HALF_WIDTH = Pong.PADDLE_WIDTH / 2;
static readonly PADDLE_HALF_HEIGHT = Pong.PADDLE_HEIGHT / 2;
static readonly PADDLE_MAX_POSITION = Pong.HEIGHT - Pong.PADDLE_HEIGHT;
static readonly PADDLE_VELOCITY = 150;
static readonly BALL_RADIUS = 5;
static readonly BALL_SPEED_INCREASE = 10;
static readonly BALL_BASE_SPEED = 200;
static readonly PADDLE_STARTING_POSITION_Y = Pong.CENTER.y - Pong.PADDLE_HALF_HEIGHT;
static readonly PLAYER_STARTING_POSITION = new Vec2(0, Pong.PADDLE_STARTING_POSITION_Y);
static readonly AI_STARTING_POSITION = new Vec2(Pong.WIDTH - Pong.PADDLE_WIDTH, Pong.PADDLE_STARTING_POSITION_Y);
static readonly RAW_CORNERS: Array<Vec2> = [
// top left
new Vec2(0, 0+Pong.BALL_RADIUS),
// top right
new Vec2(Pong.WIDTH, 0+Pong.BALL_RADIUS),
// bottom right
new Vec2(Pong.WIDTH, Pong.HEIGHT-Pong.BALL_RADIUS),
// bottom left
new Vec2(0, Pong.HEIGHT-Pong.BALL_RADIUS)
];
static readonly BOARD_CORNERS: Array<Vec2> = [
// top left
new Vec2(
Pong.RAW_CORNERS[0].x-Pong.BALL_RADIUS,
Pong.RAW_CORNERS[0].y),
// top right
new Vec2(
Pong.RAW_CORNERS[1].x+Pong.BALL_RADIUS,
Pong.RAW_CORNERS[1].y),
// bottom right
new Vec2(
Pong.RAW_CORNERS[2].x+Pong.BALL_RADIUS,
Pong.RAW_CORNERS[2].y),
// bottom left
new Vec2(
Pong.RAW_CORNERS[3].x-Pong.BALL_RADIUS,
Pong.RAW_CORNERS[3].y)
];
static readonly PADDLE_COLLISION_CORNERS: Array<Vec2> = [
// top left
new Vec2(
Pong.RAW_CORNERS[0].x+Pong.PADDLE_WIDTH+Pong.BALL_RADIUS,
Pong.RAW_CORNERS[0].y),
// top right
new Vec2(
(Pong.RAW_CORNERS[1].x-Pong.PADDLE_WIDTH)-Pong.BALL_RADIUS,
Pong.RAW_CORNERS[1].y),
// bottom right
new Vec2(
(Pong.RAW_CORNERS[2].x-Pong.PADDLE_WIDTH)-Pong.BALL_RADIUS,
Pong.RAW_CORNERS[2].y),
// bottom left
new Vec2(
Pong.RAW_CORNERS[3].x+Pong.PADDLE_WIDTH+Pong.BALL_RADIUS,
Pong.RAW_CORNERS[3].y)
];
static readonly BOARD_BOUNDS: Array<[Line, boolean]> = [
// top
[new Line(Pong.BOARD_CORNERS[0], Pong.BOARD_CORNERS[1]), false],
// left
[new Line(Pong.BOARD_CORNERS[0], Pong.BOARD_CORNERS[3]), true],
// bottom
[new Line(Pong.BOARD_CORNERS[3], Pong.BOARD_CORNERS[2]), false],
// right
[new Line(Pong.BOARD_CORNERS[1], Pong.BOARD_CORNERS[2]), true]
];
static readonly PADDLE_COLLISION_BOUNDS: Array<[Line, boolean]> = [
// top
[new Line(Pong.PADDLE_COLLISION_CORNERS[0], Pong.PADDLE_COLLISION_CORNERS[1]), false],
// left
[new Line(Pong.PADDLE_COLLISION_CORNERS[0], Pong.PADDLE_COLLISION_CORNERS[3]), true],
// bottom
[new Line(Pong.PADDLE_COLLISION_CORNERS[3], Pong.PADDLE_COLLISION_CORNERS[2]), false],
// right
[new Line(Pong.PADDLE_COLLISION_CORNERS[1], Pong.PADDLE_COLLISION_CORNERS[2]), true]
];
private elements: PongElements;
private state = new PongState();
constructor(svgContent: Document) {
this.elements = new PongElements(svgContent);
this.elements.resetButton.addEventListener('click', () => { this.reset(); });
this.elements.serveButton.addEventListener('click', () => {
if (!this.state.running) {
this.state.running = true;
this.state.shouldServe = true;
}
});
this.elements.upButton.addEventListener('click', () => {
this.state.moveUp = true;
this.state.moveDown = false;
});
this.elements.downButton.addEventListener('click', () => {
this.state.moveUp = false;
this.state.moveDown = true;
});
this.elements.stopButton.addEventListener('click', () => {
this.state.moveUp = false;
this.state.moveDown = false;
});
document.addEventListener('keydown', (event) => { this.handleKeydown(event); });
document.addEventListener('keyup', (event) => { this.handleKeyup(event); });
this.state.lastAnimationFrame = window.requestAnimationFrame((timestamp) => {
this.update(timestamp);
});
}
private serve() {
this.state.shouldServe = false;
this.state.serveTime = this.state.time;
this.state.ballVelocity.x = genRandom();
this.state.ballVelocity.y = genRandom();
this.state.ballVelocity = this.state.ballVelocity.asUnit().mul(this.state.ballSpeed);
if (this.state.ballVelocity.x > 0) {
this.state.playerServe = true;
}
this.buildBallPaths(Pong.CENTER);
}
public reset() {
this.state = new PongState();
window.cancelAnimationFrame(this.state.lastAnimationFrame);
this.updatePaddles();
this.elements.resetScores();
this.elements.resetBall();
}
private resetBall() {
this.state.resetBall();
this.elements.resetBall();
}
private resetPaddles() {
this.state.resetPaddles();
this.updatePaddles();
}
private updatePaddles() {
translateToPosition(this.elements.playerPaddle, this.state.playerPosition);
translateToPosition(this.elements.aiPaddle, this.state.aiPosition);
}
private update(timestamp: number) {
this.state.update_dt(timestamp);
const fps = 1 / this.state.dt;
this.elements.fps.innerHTML = fps.toString();
if (this.state.shouldServe) {
this.serve();
}
this.updatePlayer();
if (this.state.running) {
this.updateAI(this.elements.aiPaddle, this.state.aiPosition);
this.processScore();
if (this.state.running) {
this.processHit();
}
}
this.state.lastAnimationFrame = window.requestAnimationFrame((timestamp) => {
this.update(timestamp);
});
}
private isColliding(paddle: Vec2): boolean {
return paddle.y + Pong.PADDLE_HEIGHT > this.state.collisionPoint.y &&
paddle.y < this.state.collisionPoint.y;
}
private processScore() {
if (this.state.timeSinceServe > this.state.scoreDuration) {
if (this.state.playerServe) {
this.state.playerScore++;
this.elements.playerScoreElement.innerHTML = this.state.playerScore.toString();
} else {
this.state.aiScore++;
this.elements.aiScoreElement.innerHTML = this.state.aiScore.toString();
}
this.state.running = false;
this.resetBall();
this.resetPaddles();
}
}
private processHit() {
if (this.state.timeSinceServe > this.state.collisionDuration) {
let position: Vec2 = this.state.playerPosition;
let collisionOffset: number = 0.1;
if (this.state.playerServe) {
position = this.state.aiPosition;
collisionOffset = -collisionOffset;
}
if (this.isColliding(position)) {
this.state.ballVelocity.x = -this.state.ballVelocity.x;
this.state.ballSpeed += Pong.BALL_SPEED_INCREASE;
this.state.serveTime = this.state.time;
this.state.playerServe = !this.state.playerServe;
this.state.collisionPoint.x += collisionOffset;
this.buildBallPaths(this.state.collisionPoint);
}
}
}
private clampPaddlePosition(paddlePosition: Vec2) {
paddlePosition.y = Math.max(Math.min(paddlePosition.y, Pong.PADDLE_MAX_POSITION), 0);
}
private updatePlayer() {
if (this.state.moveUp && this.state.moveDown
|| !(this.state.moveUp || this.state.moveDown))
{
return;
}
const dy = this.state.dt * Pong.PADDLE_VELOCITY;
if (this.state.moveDown) {
this.state.playerPosition.y += dy;
} else {
this.state.playerPosition.y -= dy;
}
this.clampPaddlePosition(this.state.playerPosition);
translateToPosition(this.elements.playerPaddle, this.state.playerPosition);
}
private updateAI(paddle: SVGRectElement, position: Vec2) {
let targetPosition: number;
if (this.state.playerServe) {
targetPosition = this.state.collisionPoint.y;
} else {
targetPosition = Pong.HALF_HEIGHT;
}
targetPosition -= Pong.PADDLE_HALF_HEIGHT;
const targetRange = Pong.PADDLE_HALF_HEIGHT / 2;
const dy = this.state.dt * Pong.PADDLE_VELOCITY;
let shouldMove = false;
if (position.y > targetPosition + targetRange) {
shouldMove = true;
position.y -= dy;
} else if (position.y < targetPosition - targetRange) {
shouldMove = true;
position.y += dy;
}
if (shouldMove) {
this.clampPaddlePosition(position);
translateToPosition(paddle, position);
}
}
private buildBallPath(startingPosition: Vec2, dir: Vec2, bounds: [Line, boolean][]): Vec2[] {
const path = new Line(startingPosition, startingPosition.add(dir));
const points: Array<Vec2> = [];
while (true) {
const maybeIntersect = this.findNextCollision(path, bounds);
if (maybeIntersect !== null) {
const [point, isEnd] = maybeIntersect;
if (isEnd) {
if (point.x > Pong.HALF_WIDTH)
point.x += 0.01;
else
point.x -= 0.01;
} else {
if (point.y > Pong.HALF_HEIGHT)
point.y -= 0.01;
else
point.y += 0.01;
}
points.push(point);
if (isEnd) {
break;
}
dir.y = -dir.y;
path.p1 = point;
path.p2 = point.add(dir);
} else {
console.error("intersect is null")
break;
}
}
return points;
}
private buildBallPaths(startingPosition: Vec2) {
const dir = this.state.ballVelocity.mul(1000);
const animationPoints = this.buildBallPath(startingPosition, dir.clone(), Pong.BOARD_BOUNDS);
const collisionPoints = this.buildBallPath(startingPosition, dir, Pong.PADDLE_COLLISION_BOUNDS);
this.state.collisionPoint = collisionPoints[collisionPoints.length - 1].clone();
this.state.ballVelocity = dir.div(1000);
const animationPath = this.buildSVGPathFromPoints(startingPosition, animationPoints);
this.elements.ballPath.setAttribute('d', animationPath);
this.state.scoreDuration = this.elements.ballPath.getTotalLength() / this.state.ballSpeed;
this.elements.ballAnimation.setAttribute('dur', this.state.scoreDuration.toString());
const collisionPath = this.buildSVGPathFromPoints(startingPosition, collisionPoints);
this.elements.collisionPath.setAttribute('d', collisionPath);
this.state.collisionDuration = this.elements.collisionPath.getTotalLength() / this.state.ballSpeed;
this.elements.ballAnimation.beginElement();
}
private buildSVGPathFromPoints(start: Vec2, points: Array<Vec2>): string {
let directions = start.asAbsolute();
for (const point of points) {
directions = directions.concat(point.asLine());
}
return directions;
}
private findNextCollision(path: Line, bounds: [Line, boolean][]): null | [Vec2, boolean] {
for (const [line, isEnd] of bounds) {
const maybeIntersect = path.lineLineIntersect(line);
if (maybeIntersect !== null) {
return [maybeIntersect, isEnd];
}
}
return null;
}
private handleKeydown(event: KeyboardEvent) {
const key = event.key;
if (key === ',') {
this.state.moveUp = true;
} else if (key === '.') {
this.state.moveDown = true;
} else if (key === 's') {
if (!this.state.running) {
this.state.running = true;
this.state.shouldServe = true;
}
} else if (key === 'n') {
this.reset();
}
}
private handleKeyup(event: KeyboardEvent) {
const key = event.key;
if (key === ',') {
this.state.moveUp = false;
}
else if (key === '.') {
this.state.moveDown = false;
}
}
}
// generate random number in range(-1, 1)
function genRandom() {
return (Math.random() - 0.5) * 2;
}
function translateToPosition(element: SVGElement, position: Vec2) {
translateTo(element, position.x, position.y);
}
function translateTo(element: SVGElement, x: number, y: number) {
element.setAttribute('transform', `translate(${x}, ${y})`);
}

32
ts/tsconfig.json Normal file
View File

@ -0,0 +1,32 @@
{
"compileOnSave": true,
"compilerOptions": {
"target": "es2017",
"module": "system",
"outFile": "./../public/js/library.js",
"sourceMap": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"alwaysStrict": true,
"diagnostics": true,
"listEmittedFiles": true,
"listFiles": false,
"locale": "en",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": false,
"strict": true,
"strictNullChecks": true,
},
"include": [
"*.ts",
"src/*",
"src/**/*",
],
}

View File

@ -1,7 +0,0 @@
#!/bin/bash
SOURCE_DIR=~/blog_source
$SOURCE_DIR/update_html_posts.sh
$SOURCE_DIR/update_gemlog.sh

View File

@ -1,37 +0,0 @@
#!/bin/bash
SOURCE_DIR=~/blog_source
ASSETS_DIR=$SOURCE_DIR/assets
GEM_DIR=~/public_gemini
rm -r $GEM_DIR/*
mkdir -p $GEM_DIR/assets/jpeg
mkdir -p $GEM_DIR/assets/svg
cp $ASSETS_DIR/jpeg/* $GEM_DIR/assets/jpeg/
cp $ASSETS_DIR/svg/* $GEM_DIR/assets/svg/
cp $SOURCE_DIR/index.gmi $SOURCE_DIR/index.gmi.temp
LINE=`grep -Fn 'Posts' $SOURCE_DIR/index.gmi | cut -d : -f 1`
LINE=$(($LINE+1))
for FILE in `ls -tr $SOURCE_DIR/posts | grep -v /`
do
NAME=${FILE%.html}
OUT="$GEM_DIR/$NAME.gmi"
~/bin/html2gemini_rs "${SOURCE_DIR}/posts/${FILE}" > "${OUT}"
SPACES=`tr -s '_' ' ' <<< "$NAME"`
ENTRY="posts/${FILE}"
TIME_MODIFIED=`stat -c %y ${ENTRY} | grep -oE "\w{4}-\w{2}-\w{2} \w{2}:\w{2}:\w{2}"`
sed -i "$LINE i => ${NAME}.gmi ${SPACES} ${TIME_MODIFIED} UTC" $SOURCE_DIR/index.gmi.temp
done
cp $SOURCE_DIR/index.gmi.temp $GEM_DIR/index.gmi
rm $SOURCE_DIR/index.gmi.temp

View File

@ -1,40 +0,0 @@
#!/bin/bash
SOURCE_DIR=~/blog_source
ASSETS_DIR=$SOURCE_DIR/assets
WEB_DIR=~/public_html
rm -r $WEB_DIR/*
cp $SOURCE_DIR/posts/*.html $WEB_DIR/
mkdir -p $WEB_DIR/assets/jpeg
mkdir -p $WEB_DIR/assets/png
mkdir -p $WEB_DIR/assets/svg
mkdir -p $WEB_DIR/assets/css
cp $ASSETS_DIR/jpeg/* $WEB_DIR/assets/jpeg/
# cp $ASSETS_DIR/assets/png/* $WEB_DIR/assets/png/
cp $ASSETS_DIR/svg/* $WEB_DIR/assets/svg/
cp $ASSETS_DIR/css/* $WEB_DIR/assets/css/
cp $SOURCE_DIR/index.html $SOURCE_DIR/index.html.temp
LINE=`grep -Fn '<h2>Posts</h2>' $SOURCE_DIR/index.html | cut -d : -f 1`
LINE=$(($LINE+1))
for FILE in `ls -tr $SOURCE_DIR/posts | grep -v /`
do
NAME=${FILE%.html}
SPACES=`tr -s '_' ' ' <<< "$NAME"`
ENTRY="posts/${FILE}"
TIME_MODIFIED=`stat -c %y ${ENTRY} | grep -oE "\w{4}-\w{2}-\w{2} \w{2}:\w{2}:\w{2}"`
sed -i "$LINE i \\\t\t<a href=\"https://tilde.club/~chmod777/${FILE}\">${SPACES}</a><p>Last modified on: <time datetime=\"${TIME_MODIFIED}\">${TIME_MODIFIED} UTC</time></p>" $SOURCE_DIR/index.html.temp
done
$($SOURCE_DIR/botany_builder/target/release/botany_html)
cp $SOURCE_DIR/index.html.temp $WEB_DIR/index.html
rm index.html.temp