release winning entries of IOCCC28 under the year 2024
Congratulations to: * 2024/anders - Prize in sound coding - layered music generator * 2024/burton - Prize in pentagrammatology - wordle hard mode solver * 2024/cable1 - Prize in bot talk - LLM inference engine * 2024/cable2 - Prize in murky waters - salmon recipe * 2024/carlini - Prize in perfect timing - Intel 4004 emulation * 2024/codemeow - Prize in tray planting - bonsai generator * 2024/endoh1 - Prize in patient pointillism - slow ray tracer in CPP * 2024/endoh2 - Prize in solid body physics - rotating rigid body simulation * 2024/ferguson1 - Prize in diabolical logistics - Oregon trail pact with the devil * 2024/ferguson2 - Prize in yil-tas - Navajo code talker translator * 2024/howe - Nice accent eh-ward - mini vi * 2024/kramer - Prize in linguistic arithmetic - natural language numerical calculator * 2024/kurdyukov1 - Prize in phased periodicity - phase of the Moon * 2024/kurdyukov2 - Prize in art restoration - JPEG artifact removal * 2024/kurdyukov3 - Prize in virtual quietus - gaming VM and doom * 2024/kurdyukov4 - Prize in embiggening - encode without literals * 2024/maffiodo - Prize in creative interpretation - Jav\*script interpreter * 2024/mills - Prize in ℤ₃ - Infocom v3 story interpreter * 2024/stedolan - Best one liner - icon from MD5 * 2024/straadt - Prize in imitative rebooting - OpenRISC CPU and Linux * 2024/tmarrec - Prize in cyclonic coding - 3D tornado simulation * 2024/tompng - Prize in quasi bijection - vortex encryptor decryptor * 2024/weaver - Sur prize - rickroll Ran `make update` to perform the above. new file: 2024/burton/.entry.json
This commit is contained in:
1 parent
10512e6c79
commit
09750f8899
443 files changed
+182938
-231
No files matched your search
@@ -0,0 +1,209 @@
|
||||
{
|
||||
"no_comment" : "mandatory comment: because comments were removed from the original JSON spec",
|
||||
"entry_JSON_format_version" : "1.2 2024-09-25",
|
||||
"award" : "Prize in solid body physics",
|
||||
"year" : 2024,
|
||||
"dir" : "endoh2",
|
||||
"entry_id" : "2024_endoh2",
|
||||
"title" : "rigid-body-simulation",
|
||||
"abstract" : "rotating rigid body simulation",
|
||||
"author_set" : [
|
||||
{
|
||||
"author_handle" : "Yusuke_Endoh"
|
||||
}
|
||||
],
|
||||
"manifest" : [
|
||||
{
|
||||
"file_path" : "prog.c",
|
||||
"inventory_order" : 20,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "c",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "entry source code"
|
||||
},
|
||||
{
|
||||
"file_path" : "Makefile",
|
||||
"inventory_order" : 30,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "makefile",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "entry Makefile"
|
||||
},
|
||||
{
|
||||
"file_path" : "prog.orig.c",
|
||||
"inventory_order" : 50,
|
||||
"OK_to_edit" : false,
|
||||
"display_as" : "c",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "original source code"
|
||||
},
|
||||
{
|
||||
"file_path" : "bottle.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a wine bottle"
|
||||
},
|
||||
{
|
||||
"file_path" : "cylinder.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a cylinder"
|
||||
},
|
||||
{
|
||||
"file_path" : "egg.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of an egg"
|
||||
},
|
||||
{
|
||||
"file_path" : "halo.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a halo"
|
||||
},
|
||||
{
|
||||
"file_path" : "stick.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a stick"
|
||||
},
|
||||
{
|
||||
"file_path" : "tippe-top.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a tippe top style 1"
|
||||
},
|
||||
{
|
||||
"file_path" : "tippe-top2.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a tippe top style 2"
|
||||
},
|
||||
{
|
||||
"file_path" : "tippe-top3.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a tippe top style 3"
|
||||
},
|
||||
{
|
||||
"file_path" : "top.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a classic top style 1"
|
||||
},
|
||||
{
|
||||
"file_path" : "top2.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a classic top style 2"
|
||||
},
|
||||
{
|
||||
"file_path" : "top3.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a classic top style 3"
|
||||
},
|
||||
{
|
||||
"file_path" : "top4.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a classic top style 4"
|
||||
},
|
||||
{
|
||||
"file_path" : "try.sh",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "shellscript",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "script to try entry"
|
||||
},
|
||||
{
|
||||
"file_path" : "umbrella.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of an umbrella"
|
||||
},
|
||||
{
|
||||
"file_path" : "vase.txt",
|
||||
"inventory_order" : 100,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "text",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "1/2 of a flower vase"
|
||||
},
|
||||
{
|
||||
"file_path" : "2024_endoh2.tar.bz2",
|
||||
"inventory_order" : 1415926535,
|
||||
"OK_to_edit" : false,
|
||||
"display_as" : "tbz2",
|
||||
"display_via_github" : false,
|
||||
"entry_text" : "download entry tarball"
|
||||
},
|
||||
{
|
||||
"file_path" : ".entry.json",
|
||||
"inventory_order" : 4000000000,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "json",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "entry summary and manifest in JSON"
|
||||
},
|
||||
{
|
||||
"file_path" : ".gitignore",
|
||||
"inventory_order" : 4000000000,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "gitignore",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "list of files that should not be committed under git"
|
||||
},
|
||||
{
|
||||
"file_path" : ".path",
|
||||
"inventory_order" : 4000000000,
|
||||
"OK_to_edit" : false,
|
||||
"display_as" : "path",
|
||||
"display_via_github" : false,
|
||||
"entry_text" : "directory path from top level directory"
|
||||
},
|
||||
{
|
||||
"file_path" : "README.md",
|
||||
"inventory_order" : 4000000000,
|
||||
"OK_to_edit" : true,
|
||||
"display_as" : "markdown",
|
||||
"display_via_github" : true,
|
||||
"entry_text" : "markdown source for this web page"
|
||||
},
|
||||
{
|
||||
"file_path" : "index.html",
|
||||
"inventory_order" : 4294967295,
|
||||
"OK_to_edit" : false,
|
||||
"display_as" : "html",
|
||||
"display_via_github" : false,
|
||||
"entry_text" : "this web page"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#
|
||||
# sort with: ../../bin/sgi.sh
|
||||
*~
|
||||
*.dSYM
|
||||
*.o
|
||||
.DS_Store
|
||||
.*.swp
|
||||
tipple
|
||||
@@ -0,0 +1 @@
|
||||
2024/endoh2
|
||||
Binary file not shown.
@@ -0,0 +1,237 @@
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# 2024/endoh2
|
||||
|
||||
#############################
|
||||
# shell used by this Makefile
|
||||
#############################
|
||||
|
||||
SHELL= bash
|
||||
|
||||
|
||||
#######################
|
||||
# common tool locations
|
||||
#######################
|
||||
|
||||
include ../../var.mk
|
||||
|
||||
|
||||
#####################
|
||||
# C compiler settings
|
||||
#####################
|
||||
|
||||
# Common C compiler warnings to silence
|
||||
#
|
||||
# Example: CSILENCE= -Wno-poison-system-directories
|
||||
#
|
||||
CSILENCE= -Wno-strict-prototypes
|
||||
|
||||
# Attempt to silence unknown warning options
|
||||
#
|
||||
CUNKNOWN= -Wno-unknown-warning-option
|
||||
|
||||
# Common C compiler warning flags
|
||||
#
|
||||
# NOTE: The addition of -pedantic to CWARN is a challenge that
|
||||
# You may wish to avoid if it proves too problematic.
|
||||
# There is NO penalty for removing -pedantic from CWARN.
|
||||
#
|
||||
CWARN= -Wall -Wextra -pedantic ${CSILENCE} ${CUNKNOWN}
|
||||
|
||||
# Compiler standard
|
||||
#
|
||||
CSTD= -std=gnu17
|
||||
|
||||
# Compiler bit architecture
|
||||
#
|
||||
# Example for 32-bitness: ARCH= -m32
|
||||
# Example for 64-bitness: ARCH= -m64
|
||||
#
|
||||
# NOTE: Normally one should NOT specify a specific architecture.
|
||||
#
|
||||
ARCH=
|
||||
|
||||
# Defines that are needed to compile
|
||||
#
|
||||
# WIDTH Screen width
|
||||
# HEIGHT Screen height
|
||||
# TIMESTEP Simulation time step (a smaller `dt` increases precision but slows down the simulation)
|
||||
# RESTITUTION Coefficient of restitution
|
||||
# FRICTION Coefficient of friction
|
||||
# RPM Initial rotation speed (in RPM)
|
||||
# FASTRPM Faster initial rotation speed (in RPM) for tipple tops
|
||||
# TILT Initial tilt angle (in degrees; 0 is upright; positive values tilt to the right)
|
||||
#
|
||||
WIDTH= 120
|
||||
HEIGHT= 24
|
||||
TIMESTEP= 0.01
|
||||
RESTITUTION= 0.5
|
||||
FRICTION= 0.5
|
||||
RPM= 750
|
||||
FASTRPM= 4000
|
||||
TILT= 5
|
||||
#
|
||||
CDEFINE= -DW=${WIDTH} -DH=${HEIGHT} -Ddt=${TIMESTEP} -De=${RESTITUTION} -Du=${FRICTION} -Drpm=${RPM} -Dtilt=${TILT}
|
||||
CDEFINE2= -DW=${WIDTH} -DH=${HEIGHT} -Ddt=${TIMESTEP} -De=${RESTITUTION} -Du=${FRICTION} -Drpm=${FASTRPM} -Dtilt=${TILT}
|
||||
|
||||
# Include files that are needed to compile
|
||||
#
|
||||
# Example: CINCLUDE= -include stdio.h
|
||||
#
|
||||
CINCLUDE=
|
||||
|
||||
# Other flags to pass to the C compiler
|
||||
#
|
||||
# Example: COTHER= -fno-math-errno
|
||||
#
|
||||
COTHER=
|
||||
|
||||
# Optimization
|
||||
#
|
||||
# NOTE: Feel free to change the level of compiler optimization.
|
||||
# The "-O3" is just a friendly default you might wish to try.
|
||||
#
|
||||
# Example: OPT= -O0 -g
|
||||
#
|
||||
OPT= -O3
|
||||
|
||||
# Default flags for ANSI C compilation
|
||||
#
|
||||
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${COTHER} ${OPT}
|
||||
CFLAGS2= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE2} ${CINCLUDE} ${COTHER} ${OPT}
|
||||
|
||||
# Libraries needed to build
|
||||
#
|
||||
# Example: LDFLAGS= -lncurses -lm
|
||||
#
|
||||
LDFLAGS=
|
||||
|
||||
# C compiler to use
|
||||
#
|
||||
# NOTE: The IOCCC Judges recommend you leave CC as just "cc"
|
||||
# and NOT set it to clang, or gcc, or something else
|
||||
# unless you have a STRONG reason to do so.
|
||||
#
|
||||
# Setting CC to something other than "cc" makes your
|
||||
# code less portable to those who do not have your
|
||||
# particular C compiler. **hint**
|
||||
#
|
||||
# If you want to test your code with a particular C compiler,
|
||||
# use the make command line. For example:
|
||||
#
|
||||
# make all CC=clang
|
||||
# make all CC=gcc
|
||||
#
|
||||
CC= cc
|
||||
|
||||
# Compiler add-ons or replacements for clang only
|
||||
#
|
||||
ifeq "$(findstring $(CLANG),${CC})" "$(CLANG)"
|
||||
#
|
||||
# NOTE: This code is only invoked when CC is "clang"
|
||||
# such as when you use the make command line:
|
||||
#
|
||||
# make all CC=clang
|
||||
#
|
||||
CSILENCE+= -Wno-comma -Wno-double-promotion -Wno-float-conversion \
|
||||
-Wno-implicit-float-conversion -Wno-missing-prototypes \
|
||||
-Wno-missing-variable-declarations -Wno-poison-system-directories \
|
||||
-Wno-shadow -Wno-strict-prototypes
|
||||
#
|
||||
CWARN+= -Weverything
|
||||
#
|
||||
endif
|
||||
|
||||
# Specific add-ons or replacements for gcc only
|
||||
#
|
||||
ifeq "$(findstring $(GCC),${CC})" "$(GCC)"
|
||||
#
|
||||
# NOTE: This code is only invoked when CC is "gcc"
|
||||
# such as when you use the make command line:
|
||||
#
|
||||
# make all CC=gcc
|
||||
#
|
||||
CSILENCE+=
|
||||
#
|
||||
CWARN+=
|
||||
#
|
||||
endif
|
||||
|
||||
|
||||
###########################################
|
||||
# Special Makefile variables for this entry
|
||||
###########################################
|
||||
|
||||
ENTRY= prog
|
||||
PROG= ${ENTRY}
|
||||
#
|
||||
OBJ= ${PROG}.o
|
||||
TARGET= ${PROG} tipple
|
||||
#
|
||||
ALT_OBJ=
|
||||
ALT_TARGET=
|
||||
|
||||
# list any data files supplied with your submission
|
||||
#
|
||||
# Example: DATA= curds whey
|
||||
#
|
||||
DATA=
|
||||
|
||||
# Other Makefile variables require by the code
|
||||
#
|
||||
INPUT= top.txt
|
||||
|
||||
|
||||
#################
|
||||
# build the entry
|
||||
#################
|
||||
|
||||
all: data ${TARGET}
|
||||
@${TRUE}
|
||||
|
||||
.PHONY: all alt data everything clean clobber
|
||||
|
||||
# how to compile
|
||||
#
|
||||
${PROG}: ${PROG}.c
|
||||
${CC} ${CFLAGS} ${PROG}.c -o $@ ${LDFLAGS}
|
||||
|
||||
tipple: ${PROG}.c
|
||||
${CC} ${CFLAGS2} ${PROG}.c -o $@
|
||||
|
||||
# alternative executable
|
||||
#
|
||||
alt: data ${ALT_TARGET}
|
||||
@${TRUE}
|
||||
|
||||
${PROG}.alt: ${PROG}.alt.c
|
||||
${CC} ${CFLAGS} ${PROG}.alt.c -o $@ ${LDFLAGS}
|
||||
|
||||
# data files
|
||||
#
|
||||
data: ${DATA}
|
||||
@${TRUE}
|
||||
|
||||
# both all and alt
|
||||
#
|
||||
everything: all alt
|
||||
@${TRUE}
|
||||
|
||||
|
||||
###############
|
||||
# utility rules
|
||||
###############
|
||||
#
|
||||
clean:
|
||||
${RM} -f ${OBJ} ${ALT_OBJ}
|
||||
|
||||
clobber: clean
|
||||
${RM} -f ${TARGET} ${ALT_TARGET}
|
||||
${RM} -rf *.dSYM
|
||||
|
||||
|
||||
######################################
|
||||
# optional include of 1337 hacker rulz
|
||||
######################################
|
||||
|
||||
-include 1337.mk ../1337.mk ../../1337.mk
|
||||
@@ -0,0 +1,275 @@
|
||||
## To build:
|
||||
|
||||
``` <!---sh-->
|
||||
make all
|
||||
```
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
``` <!---sh-->
|
||||
./prog < body.txt
|
||||
```
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
``` <!---sh-->
|
||||
./try.sh
|
||||
```
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
Playing with this entry, we were able to experience joy akin to
|
||||
[what Niels Bohr and Wolfgang Pauli could have experienced when they played with the Tippe-Top](https://repository.aip.org/wolfgang-pauli-and-niels-bohr-demonstrating-tippe-top-toy).
|
||||
|
||||
We invite you to experiment beyond the [try.sh](%%REPO_URL%%/2024/endoh2/try.sh), and test with these "_body.txt_" files:
|
||||
|
||||
* bottle.txt
|
||||
* cylinder.txt
|
||||
* egg.txt
|
||||
* halo.txt
|
||||
* stick.txt
|
||||
* tippe-top.txt
|
||||
* tippe-top2.txt
|
||||
* tippe-top3.txt
|
||||
* top.txt
|
||||
* top2.txt
|
||||
* top3.txt
|
||||
* top4.txt
|
||||
* umbrella.txt
|
||||
* vase.txt
|
||||
|
||||
For example:
|
||||
|
||||
``` <!---sh-->
|
||||
./prog < vase.txt
|
||||
```
|
||||
|
||||
Moreover, you should experiment with various simulation parameters. On the make line you may set:
|
||||
|
||||
```
|
||||
| Perameter | Default | Meaning
|
||||
|-------------|-----------------------------------------------------|
|
||||
| WIDTH | 120 | Screen width |
|
||||
| | | |
|
||||
| HEIGHT | 24 | Screen height |
|
||||
| | | |
|
||||
| TIMESTEP | 0.01 | Simulation time step |
|
||||
| | | a smaller dt |
|
||||
| | | increases precision |
|
||||
| | | down the simulation |
|
||||
| | | |
|
||||
| RESTITUTION | 0.5 | Coefficient of restitution |
|
||||
| | | |
|
||||
| FRICTION | 0.5 | Coefficient of friction |
|
||||
| | | |
|
||||
| RPM | 750 | Initial rotation speed in RPM |
|
||||
| | | |
|
||||
| FASTRPM | 4000 | Tipple top initial rotation speed in RPM |
|
||||
| | | used by ./tipple, not ./prog |
|
||||
| | | |
|
||||
| TILT | 5 | Initial tilt angle |
|
||||
| | | in degrees |
|
||||
| | | 0 is upright |
|
||||
| | | positive values tilt to the right |
|
||||
```
|
||||
|
||||
For example, to increase the "_Coefficient of friction_" to **0.75**,
|
||||
the "_Initial rotation speed in RPM_" to **600**, and the "_Initial
|
||||
tilt angle_" to **15**:
|
||||
|
||||
``` <!---sh-->
|
||||
make clobber all FRICTION=0.75 RPM=600 TILT=15
|
||||
|
||||
./prog < top.txt
|
||||
```
|
||||
|
||||
Now we would like to see if this entry can be hacked to demonstrate the
|
||||
[Dzhanibekov effect](https://en.wikipedia.org/wiki/Tennis_racket_theorem).
|
||||
|
||||
|
||||
## Author's remarks:
|
||||
|
||||
|
||||
### A Spinning Top Simulator
|
||||
|
||||
```
|
||||
@@
|
||||
@@
|
||||
@@@@@@@@@@@@
|
||||
@@ @@@@@@@@@@@@@@@@
|
||||
@@@@ @@@@@@@@@@@@@@@@
|
||||
@@@@@@@ @@@@@@@@@@@ @
|
||||
@@@@@@@@@@@ @@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@
|
||||
@@@@@@@@@
|
||||
@@@@
|
||||
@@
|
||||
@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
```
|
||||
|
||||
This is a physics engine that simulates the motion of a rotating rigid body, such as a [top](https://en.wikipedia.org/wiki/Top).
|
||||
|
||||
|
||||
#### How to run
|
||||
|
||||
Compilation requires specifying several `-D` options:
|
||||
|
||||
```
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=5 -o prog prog.c
|
||||
```
|
||||
|
||||
These options define the following parameters:
|
||||
|
||||
* `-DW=120`: Screen width.
|
||||
* `-DH=24`: Screen height.
|
||||
* `-Ddt=0.01`: Simulation time step (a smaller `dt` increases precision but slows down the simulation).
|
||||
* `-De=0.5`: Coefficient of restitution.
|
||||
* `-Du=0.5`: Coefficient of friction.
|
||||
* `-Drpm=1000`: Initial rotation speed (in RPM).
|
||||
* `-Dtilt=5`: Initial tilt angle (in degrees; 0 is upright; positive values tilt to the right).
|
||||
|
||||
Then, run the program like this:
|
||||
|
||||
```
|
||||
$ ./prog < top.txt
|
||||
```
|
||||
|
||||
|
||||
#### Input file format
|
||||
|
||||
The input file defines the shape of a rigid body. Here's an example:
|
||||
|
||||
```
|
||||
// A typical spinning top
|
||||
|
||||
// Use `-Drpm=1000 -Dtilt=5`
|
||||
|
||||
.
|
||||
.
|
||||
. // Twirl here
|
||||
.
|
||||
.
|
||||
.
|
||||
...
|
||||
#####
|
||||
##
|
||||
# // Spin!
|
||||
##
|
||||
#####
|
||||
..
|
||||
.
|
||||
.
|
||||
. // Looks painful
|
||||
```
|
||||
|
||||
This figure is rotated around its left edge to create a 3D object (a solid of revolution).
|
||||
Only solids of revolution are supported by this simulator.
|
||||
|
||||
Internally, the rigid body is modeled as a collection of particles (point masses). Each character in the input file has the following meaning:
|
||||
|
||||
* A full-stop (or any printable character whose LSB is 0): Represents light particle.
|
||||
* A hash (or any character whose LSB is 1): Represents heavy particle.
|
||||
* A space: Represents no particle (empty space).
|
||||
* A slash: Indicates the start of a comment; everything after it on the line is ignored.
|
||||
|
||||
|
||||
#### Algorithm overview
|
||||
|
||||
The core algorithm works as follows:
|
||||
|
||||
1. Compute the inertia tensor
|
||||
2. Compute an inverse of the tensor
|
||||
3. For each particle in contact with the floor:
|
||||
3-1. Compute the normal force
|
||||
3-2. Compute friction
|
||||
3-3. Convert these into the resultant force and torque acting on the body's center of mass
|
||||
4. Update the position, velocity, angular velocity, and orientation of the body
|
||||
|
||||
For the detailed theory, refer to a physics textbook.
|
||||
|
||||
To keep code size minimal, this simulator uses [quaternions](https://en.wikipedia.org/wiki/Quaternion) to represent 3D vectors and matrices.
|
||||
Quaternion multiplication is powerful, allowing the inertia tensor and its inverse to be calculated concisely, each requiring only about 100 characters of code.
|
||||
Because `math.h` doesn't natively support quaternions for these operations, it's not used at all. This also means linking with `-lm` is unnecessary.
|
||||
|
||||
Motion blur is used in the rendering. You can observe it more clearly by pausing the animation (e.g., with Ctrl+S in some terminals).
|
||||
|
||||
Distant points appear as colons (`:`), while closer ones appear as at-signs (`@`).
|
||||
|
||||
|
||||
#### Included data
|
||||
|
||||
A few shape files are provided. The top*.txt files are standard spinning top shapes.
|
||||
|
||||
```
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=5 -o prog prog.c && ./prog < top.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=500 -Dtilt=5 -o prog prog.c && ./prog < top2.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=500 -Dtilt=5 -o prog prog.c && ./prog < top3.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=500 -Dtilt=5 -o prog prog.c && ./prog < top4.txt
|
||||
```
|
||||
|
||||
The [tippe top](https://en.wikipedia.org/wiki/Tippe_top) is a top that flips itself over when spun quickly.
|
||||
|
||||
```
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=2200 -Dtilt=5 -o prog prog.c && ./prog < tippe-top.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=4000 -Dtilt=5 -o prog prog.c && ./prog < tippe-top2.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=4000 -Dtilt=5 -o prog prog.c && ./prog < tippe-top3.txt
|
||||
```
|
||||
|
||||
Spinning a boiled egg? Try this with `-Dtilt=90` to start it from a lying position.
|
||||
|
||||
```
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1300 -Dtilt=90 -o prog prog.c && ./prog < egg.txt
|
||||
```
|
||||
|
||||
Spin everyday items -- no risk of breaking them:
|
||||
|
||||
```
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=175 -o prog prog.c && ./prog < bottle.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=5 -o prog prog.c && ./prog < bottle.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=5 -o prog prog.c && ./prog < umbrella.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=2000 -Dtilt=5 -o prog prog.c && ./prog < vase.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=2000 -Dtilt=20 -o prog prog.c && ./prog < vase.txt
|
||||
```
|
||||
|
||||
More shapes: `stick.txt`, `cylinder.txt`, `halo.txt`, and even `prog.c`.
|
||||
|
||||
Yes, `prog.c` itself can be used as input. Try it:
|
||||
|
||||
```
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=5 -o prog prog.c && ./prog < prog.c
|
||||
```
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
Copyright © 1984-2025 by Landon Curt Noll and Leonid A. Broukhis. All Rights Reserved.
|
||||
|
||||
You are free to share and adapt this file under the terms of this license:
|
||||
|
||||
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
|
||||
|
||||
For more information, see:
|
||||
|
||||
https://creativecommons.org/licenses/by-sa/4.0/
|
||||
|
||||
-->
|
||||
@@ -0,0 +1,20 @@
|
||||
// A bottle
|
||||
|
||||
// Use `-Drpm=1000 -Dtilt=5` or `-Drpm=1000 -Dtilt=175`
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
##
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#####
|
||||
@@ -0,0 +1,18 @@
|
||||
// A cylinder
|
||||
|
||||
// Use `-Drpm=500 -Dtilt=5`
|
||||
|
||||
...............
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
...............
|
||||
@@ -0,0 +1,20 @@
|
||||
// Is this an egg boiled?
|
||||
|
||||
// ref: https://iopscience.iop.org/article/10.1088/1361-6404/aa997b
|
||||
|
||||
// Use `-Drpm=1300 -Dtilt=90`
|
||||
|
||||
###
|
||||
##
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
##
|
||||
#####
|
||||
@@ -0,0 +1,20 @@
|
||||
// Angel halo
|
||||
|
||||
// Use `-Drpm=300 -Dtilt=5`
|
||||
|
||||
####
|
||||
# #
|
||||
# #
|
||||
####
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
@@ -0,0 +1,783 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<!-- START: two lines up starts content from: inc/top.default.html -->
|
||||
|
||||
<!-- END: this line ends content from: inc/top.default.html -->
|
||||
<!-- START: this line starts content from: inc/head.default.html -->
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" href="../../ioccc.css">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@100..900&display=swap" rel="stylesheet">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||||
<title>2024/endoh2 - Prize in solid body physics</title>
|
||||
<link rel="icon" type="image/x-icon" href="../../favicon.ico">
|
||||
<meta name="description" content="2024 IOCCC entry endoh2 - Prize in solid body physics">
|
||||
<meta name="keywords" content="IOCCC, 2024, IOCCC 2024, IOCCC entry, endoh2, Prize in solid body physics">
|
||||
</head>
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
|
||||
<!-- END: this line ends content from: inc/head.default.html -->
|
||||
|
||||
<!-- -->
|
||||
<!-- This web page was formed via the tool: bin/readme2index.sh -->
|
||||
<!-- The content of main section of this web page came from: 2024/endoh2/README.md -->
|
||||
<!-- -->
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<!-- !!! Do not modify this web page, instead modify the file: 2024/endoh2/README.md !!! -->
|
||||
<!-- !!! Do not modify this web page, instead modify the file: 2024/endoh2/README.md !!! -->
|
||||
<!-- !!! Do not modify this web page, instead modify the file: 2024/endoh2/README.md !!! -->
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
|
||||
<!-- Markdown content was converted into HTML via the tool: bin/md2html.sh -->
|
||||
|
||||
<!-- START: this line starts content from: inc/body.default.html -->
|
||||
|
||||
<body>
|
||||
|
||||
<!-- END: this line ends content from: inc/body.default.html -->
|
||||
<!-- START: this line starts content from: inc/topbar.default.html -->
|
||||
|
||||
<div class="theader">
|
||||
<nav class="topbar">
|
||||
<div class="container">
|
||||
<div class="logo">
|
||||
<a href="../../index.html" class="logo-link">
|
||||
IOCCC
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="topbar-items">
|
||||
<div class="item">
|
||||
<span class="item-header">
|
||||
Entries
|
||||
</span>
|
||||
|
||||
<div class="sub-item">
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../years.html" class="sub-item-link">
|
||||
Winning entries
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../authors.html" class="sub-item-link">
|
||||
Winning authors
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../location.html" class="sub-item-link">
|
||||
Location of authors
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../bugs.html" class="sub-item-link">
|
||||
Bugs and (mis)features
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../faq.html#fix_an_entry" class="sub-item-link">
|
||||
Fixing entries
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../faq.html#fix_author" class="sub-item-link">
|
||||
Updating author info
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="item">
|
||||
<span class="item-header">
|
||||
Status
|
||||
</span>
|
||||
|
||||
<div class="sub-item">
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../news.html" class="sub-item-link">
|
||||
News
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../status.html" class="sub-item-link">
|
||||
Contest status
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../next/rules.html" class="sub-item-link">
|
||||
IOCCC rules
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../next/guidelines.html" class="sub-item-link">
|
||||
IOCCC guidelines
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../markdown.html" class="sub-item-link">
|
||||
Markdown guidelines
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../SECURITY.html" class="sub-item-link">
|
||||
Security policy
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="item">
|
||||
<span class="item-header">
|
||||
FAQ
|
||||
</span>
|
||||
|
||||
<div class="sub-item">
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../faq.html" class="sub-item-link">
|
||||
Frequently asked questions
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../quick-start.html#enter" class="sub-item-link">
|
||||
Enter the IOCCC
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../faq.html#compiling" class="sub-item-link">
|
||||
Compiling entries
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../faq.html#running_entries" class="sub-item-link">
|
||||
Running entries
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../faq.html#help" class="sub-item-link">
|
||||
How to help
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="item">
|
||||
<span class="item-header">
|
||||
About
|
||||
</span>
|
||||
|
||||
<div class="sub-item">
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../index.html" class="sub-item-link">
|
||||
Home page
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../social.html" class="sub-item-link">
|
||||
IOCCC social media
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../about.html" class="sub-item-link">
|
||||
About the IOCCC
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../judges.html" class="sub-item-link">
|
||||
The judges
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../thanks-for-help.html" class="sub-item-link">
|
||||
Thanks for the help
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="outfit-font">
|
||||
<a href="../../contact.html" class="sub-item-link">
|
||||
Contact us
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="header-mobile-menu">
|
||||
<noscript>
|
||||
<a href="../../nojs-menu.html" class="topbar-js-label">
|
||||
Please Enable JavaScript
|
||||
</a>
|
||||
</noscript>
|
||||
|
||||
<button id="header-open-menu-button" class="topbar-mobile-menu">
|
||||
<img
|
||||
src="../../png/hamburger-icon-open.png"
|
||||
alt="hamburger style menu icon - open state"
|
||||
width=48
|
||||
height=48>
|
||||
</button>
|
||||
|
||||
<button id="header-close-menu-button" class="hide-content">
|
||||
<img
|
||||
src="../../png/hamburger-icon-closed.png"
|
||||
alt="hamburger style menu icon - closed state"
|
||||
width=48
|
||||
height=48>
|
||||
</button>
|
||||
|
||||
<div id="mobile-menu-panel" class="hide-content">
|
||||
<div class="mobile-menu-container">
|
||||
|
||||
<div class="mobile-menu-wrapper">
|
||||
<div class="mobile-menu-item">
|
||||
Entries
|
||||
</div>
|
||||
<div class="mobile-submenu-wrapper">
|
||||
|
||||
<a class="mobile-submenu-item" href="../../years.html">
|
||||
Winning entries
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../authors.html">
|
||||
Winning authors
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../location.html">
|
||||
Location of authors
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../bugs.html">
|
||||
Bugs and (mis)features
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../faq.html#fix_an_entry">
|
||||
Fixing entries
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../faq.html#fix_author">
|
||||
Updating author info
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../thanks-for-help.html">
|
||||
Thanks for the help
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mobile-menu-wrapper">
|
||||
|
||||
<div class="mobile-menu-item">
|
||||
Status
|
||||
</div>
|
||||
<div class="mobile-submenu-wrapper">
|
||||
|
||||
<a class="mobile-submenu-item" href="../../news.html">
|
||||
News
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../status.html">
|
||||
Contest status
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../next/rules.html">
|
||||
IOCCC rules
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../next/guidelines.html">
|
||||
IOCCC guidelines
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../markdown.html">
|
||||
Markdown guidelines
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../SECURITY.html">
|
||||
Security policy
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mobile-menu-wrapper">
|
||||
<div class="mobile-menu-item">
|
||||
FAQ
|
||||
</div>
|
||||
<div class="mobile-submenu-wrapper">
|
||||
|
||||
<a class="mobile-submenu-item" href="../../faq.html">
|
||||
Frequently asked questions
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../quick-start.html#enter">
|
||||
Enter the IOCCC
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../faq.html#compiling">
|
||||
Compiling entries
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../faq.html#running_entries">
|
||||
Running entries
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../faq.html#help">
|
||||
How to help
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mobile-menu-wrapper">
|
||||
<div class="mobile-menu-item">
|
||||
About
|
||||
</div>
|
||||
<div class="mobile-submenu-wrapper">
|
||||
|
||||
<a class="mobile-submenu-item" href="../../index.html">
|
||||
Home page
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../social.html">
|
||||
IOCCC social media
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../about.html">
|
||||
About the IOCCC
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../judges.html">
|
||||
The judges
|
||||
</a>
|
||||
|
||||
<a class="mobile-submenu-item" href="../../contact.html">
|
||||
Contact us
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var headerOpenMenuButton = document.getElementById("header-open-menu-button");
|
||||
var headerCloseMenuButton = document.getElementById("header-close-menu-button");
|
||||
var mobileMenuPanel = document.getElementById("mobile-menu-panel");
|
||||
|
||||
headerOpenMenuButton.addEventListener("click", () => {
|
||||
headerOpenMenuButton.classList.remove("topbar-mobile-menu");
|
||||
headerOpenMenuButton.classList.add("hide-content");
|
||||
|
||||
headerCloseMenuButton.classList.remove("hide-content");
|
||||
headerCloseMenuButton.classList.add("topbar-mobile-menu");
|
||||
|
||||
mobileMenuPanel.classList.remove("hide-content");
|
||||
mobileMenuPanel.classList.add("topbar-mobile-panel");
|
||||
});
|
||||
|
||||
headerCloseMenuButton.addEventListener("click", () => {
|
||||
headerCloseMenuButton.classList.remove("topbar-mobile-menu");
|
||||
headerCloseMenuButton.classList.add("hide-content");
|
||||
|
||||
mobileMenuPanel.classList.add("hide-content");
|
||||
mobileMenuPanel.classList.remove("topbar-mobile-panel");
|
||||
|
||||
headerOpenMenuButton.classList.add("topbar-mobile-menu");
|
||||
headerOpenMenuButton.classList.remove("hide-content");
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- END: this line ends content from: inc/topbar.default.html -->
|
||||
<!-- START: this line starts content from: inc/header.default.html -->
|
||||
|
||||
<div class="header">
|
||||
<a href="../../2011/zucker/index.html">
|
||||
<img src="../../png/ioccc.png"
|
||||
alt="IOCCC image by Matt Zucker"
|
||||
width=300
|
||||
height=110>
|
||||
</a>
|
||||
<h1>The International Obfuscated C Code Contest</h1>
|
||||
<h2>2024/endoh2 - Prize in solid body physics</h2>
|
||||
<h3>rotating rigid body simulation</h3>
|
||||
</div>
|
||||
|
||||
<!-- END: this line ends content from: inc/header.default.html -->
|
||||
<!-- START: this line starts content from: inc/navbar.mid.html -->
|
||||
|
||||
<div class="navbar">
|
||||
<a class="Left" href="../endoh1/index.html">← 2024/endoh1</a>
|
||||
<a class="Left" href="../index.html">↑ 2024 ↑</a>
|
||||
<a class="Left" href="../ferguson1/index.html">2024/ferguson1 →</a>
|
||||
<a class="Right" href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/prog.c">C code</a>
|
||||
<a class="Right" href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/Makefile">Makefile</a>
|
||||
<a class="Right" href="#inventory">Inventory</a>
|
||||
<a class="Right" href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fwww.ioccc.org%2F2024%2Fendoh2%2Findex.html">✓</a>
|
||||
</div>
|
||||
|
||||
<!-- END: this line ends content from: inc/navbar.mid.html -->
|
||||
<!-- START: this line starts content from: inc/before-content.default.html -->
|
||||
|
||||
<div class="content" id="content">
|
||||
|
||||
<!-- END: this line ends content from: inc/before-content.default.html -->
|
||||
<!-- START: this line starts content for HTML phase 20 by: bin/output-index-author.sh via bin/md2html.sh -->
|
||||
|
||||
<!-- START: this line starts content generated by: bin/output-index-author.sh -->
|
||||
|
||||
<h2 id="author">Author:</h2>
|
||||
<ul>
|
||||
<li>Name: <a href="../../authors.html#Yusuke_Endoh">Yusuke Endoh</a><br>
|
||||
Location: <a href="../../location.html#JP">JP</a> - <em>Japan</em></li>
|
||||
</ul>
|
||||
|
||||
<!-- END: next line ends content generated by: bin/output-index-author.sh -->
|
||||
|
||||
<!-- END: this line ends content for HTML phase 20 by: bin/output-index-author.sh via bin/md2html.sh -->
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<!-- BEFORE: 1st line of markdown file: 2024/endoh2/README.md -->
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<pre><code> make all</code></pre>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<pre><code> ./prog < body.txt</code></pre>
|
||||
<h2 id="try">Try:</h2>
|
||||
<pre><code> ./try.sh</code></pre>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>Playing with this entry, we were able to experience joy akin to
|
||||
<a href="https://repository.aip.org/wolfgang-pauli-and-niels-bohr-demonstrating-tippe-top-toy">what Niels Bohr and Wolfgang Pauli could have experienced when they played with the Tippe-Top</a>.</p>
|
||||
<p>We invite you to experiment beyond the <a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/try.sh">try.sh</a>, and test with these “<em>body.txt</em>” files:</p>
|
||||
<ul>
|
||||
<li>bottle.txt</li>
|
||||
<li>cylinder.txt</li>
|
||||
<li>egg.txt</li>
|
||||
<li>halo.txt</li>
|
||||
<li>stick.txt</li>
|
||||
<li>tippe-top.txt</li>
|
||||
<li>tippe-top2.txt</li>
|
||||
<li>tippe-top3.txt</li>
|
||||
<li>top.txt</li>
|
||||
<li>top2.txt</li>
|
||||
<li>top3.txt</li>
|
||||
<li>top4.txt</li>
|
||||
<li>umbrella.txt</li>
|
||||
<li>vase.txt</li>
|
||||
</ul>
|
||||
<p>For example:</p>
|
||||
<pre><code> ./prog < vase.txt</code></pre>
|
||||
<p>Moreover, you should experiment with various simulation parameters. On the make line you may set:</p>
|
||||
<pre><code> | Perameter | Default | Meaning
|
||||
|-------------|-----------------------------------------------------|
|
||||
| WIDTH | 120 | Screen width |
|
||||
| | | |
|
||||
| HEIGHT | 24 | Screen height |
|
||||
| | | |
|
||||
| TIMESTEP | 0.01 | Simulation time step |
|
||||
| | | a smaller dt |
|
||||
| | | increases precision |
|
||||
| | | down the simulation |
|
||||
| | | |
|
||||
| RESTITUTION | 0.5 | Coefficient of restitution |
|
||||
| | | |
|
||||
| FRICTION | 0.5 | Coefficient of friction |
|
||||
| | | |
|
||||
| RPM | 750 | Initial rotation speed in RPM |
|
||||
| | | |
|
||||
| FASTRPM | 4000 | Tipple top initial rotation speed in RPM |
|
||||
| | | used by ./tipple, not ./prog |
|
||||
| | | |
|
||||
| TILT | 5 | Initial tilt angle |
|
||||
| | | in degrees |
|
||||
| | | 0 is upright |
|
||||
| | | positive values tilt to the right |</code></pre>
|
||||
<p>For example, to increase the “<em>Coefficient of friction</em>” to <strong>0.75</strong>,
|
||||
the “<em>Initial rotation speed in RPM</em>” to <strong>600</strong>, and the “<em>Initial
|
||||
tilt angle</em>” to <strong>15</strong>:</p>
|
||||
<pre><code> make clobber all FRICTION=0.75 RPM=600 TILT=15
|
||||
|
||||
./prog < top.txt</code></pre>
|
||||
<p>Now we would like to see if this entry can be hacked to demonstrate the
|
||||
<a href="https://en.wikipedia.org/wiki/Tennis_racket_theorem">Dzhanibekov effect</a>.</p>
|
||||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||||
<h3 id="a-spinning-top-simulator">A Spinning Top Simulator</h3>
|
||||
<pre><code> @@
|
||||
@@
|
||||
@@@@@@@@@@@@
|
||||
@@ @@@@@@@@@@@@@@@@
|
||||
@@@@ @@@@@@@@@@@@@@@@
|
||||
@@@@@@@ @@@@@@@@@@@ @
|
||||
@@@@@@@@@@@ @@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@
|
||||
@@@@@@@@@
|
||||
@@@@
|
||||
@@
|
||||
@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</code></pre>
|
||||
<p>This is a physics engine that simulates the motion of a rotating rigid body, such as a <a href="https://en.wikipedia.org/wiki/Top">top</a>.</p>
|
||||
<h4 id="how-to-run">How to run</h4>
|
||||
<p>Compilation requires specifying several <code>-D</code> options:</p>
|
||||
<pre><code>$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=5 -o prog prog.c</code></pre>
|
||||
<p>These options define the following parameters:</p>
|
||||
<ul>
|
||||
<li><code>-DW=120</code>: Screen width.</li>
|
||||
<li><code>-DH=24</code>: Screen height.</li>
|
||||
<li><code>-Ddt=0.01</code>: Simulation time step (a smaller <code>dt</code> increases precision but slows down the simulation).</li>
|
||||
<li><code>-De=0.5</code>: Coefficient of restitution.</li>
|
||||
<li><code>-Du=0.5</code>: Coefficient of friction.</li>
|
||||
<li><code>-Drpm=1000</code>: Initial rotation speed (in RPM).</li>
|
||||
<li><code>-Dtilt=5</code>: Initial tilt angle (in degrees; 0 is upright; positive values tilt to the right).</li>
|
||||
</ul>
|
||||
<p>Then, run the program like this:</p>
|
||||
<pre><code>$ ./prog < top.txt</code></pre>
|
||||
<h4 id="input-file-format">Input file format</h4>
|
||||
<p>The input file defines the shape of a rigid body. Here’s an example:</p>
|
||||
<pre><code>// A typical spinning top
|
||||
|
||||
// Use `-Drpm=1000 -Dtilt=5`
|
||||
|
||||
.
|
||||
.
|
||||
. // Twirl here
|
||||
.
|
||||
.
|
||||
.
|
||||
...
|
||||
#####
|
||||
##
|
||||
# // Spin!
|
||||
##
|
||||
#####
|
||||
..
|
||||
.
|
||||
.
|
||||
. // Looks painful</code></pre>
|
||||
<p>This figure is rotated around its left edge to create a 3D object (a solid of revolution).
|
||||
Only solids of revolution are supported by this simulator.</p>
|
||||
<p>Internally, the rigid body is modeled as a collection of particles (point masses). Each character in the input file has the following meaning:</p>
|
||||
<ul>
|
||||
<li>A full-stop (or any printable character whose LSB is 0): Represents light particle.</li>
|
||||
<li>A hash (or any character whose LSB is 1): Represents heavy particle.</li>
|
||||
<li>A space: Represents no particle (empty space).</li>
|
||||
<li>A slash: Indicates the start of a comment; everything after it on the line is ignored.</li>
|
||||
</ul>
|
||||
<h4 id="algorithm-overview">Algorithm overview</h4>
|
||||
<p>The core algorithm works as follows:</p>
|
||||
<ol type="1">
|
||||
<li>Compute the inertia tensor</li>
|
||||
<li>Compute an inverse of the tensor</li>
|
||||
<li>For each particle in contact with the floor:
|
||||
3-1. Compute the normal force
|
||||
3-2. Compute friction
|
||||
3-3. Convert these into the resultant force and torque acting on the body’s center of mass</li>
|
||||
<li>Update the position, velocity, angular velocity, and orientation of the body</li>
|
||||
</ol>
|
||||
<p>For the detailed theory, refer to a physics textbook.</p>
|
||||
<p>To keep code size minimal, this simulator uses <a href="https://en.wikipedia.org/wiki/Quaternion">quaternions</a> to represent 3D vectors and matrices.
|
||||
Quaternion multiplication is powerful, allowing the inertia tensor and its inverse to be calculated concisely, each requiring only about 100 characters of code.
|
||||
Because <code>math.h</code> doesn’t natively support quaternions for these operations, it’s not used at all. This also means linking with <code>-lm</code> is unnecessary.</p>
|
||||
<p>Motion blur is used in the rendering. You can observe it more clearly by pausing the animation (e.g., with Ctrl+S in some terminals).</p>
|
||||
<p>Distant points appear as colons (<code>:</code>), while closer ones appear as at-signs (<code>@</code>).</p>
|
||||
<h4 id="included-data">Included data</h4>
|
||||
<p>A few shape files are provided. The top*.txt files are standard spinning top shapes.</p>
|
||||
<pre><code>$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=5 -o prog prog.c && ./prog < top.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=500 -Dtilt=5 -o prog prog.c && ./prog < top2.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=500 -Dtilt=5 -o prog prog.c && ./prog < top3.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=500 -Dtilt=5 -o prog prog.c && ./prog < top4.txt</code></pre>
|
||||
<p>The <a href="https://en.wikipedia.org/wiki/Tippe_top">tippe top</a> is a top that flips itself over when spun quickly.</p>
|
||||
<pre><code>$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=2200 -Dtilt=5 -o prog prog.c && ./prog < tippe-top.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=4000 -Dtilt=5 -o prog prog.c && ./prog < tippe-top2.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=4000 -Dtilt=5 -o prog prog.c && ./prog < tippe-top3.txt</code></pre>
|
||||
<p>Spinning a boiled egg? Try this with <code>-Dtilt=90</code> to start it from a lying position.</p>
|
||||
<pre><code>$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1300 -Dtilt=90 -o prog prog.c && ./prog < egg.txt</code></pre>
|
||||
<p>Spin everyday items – no risk of breaking them:</p>
|
||||
<pre><code>$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=175 -o prog prog.c && ./prog < bottle.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=5 -o prog prog.c && ./prog < bottle.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=5 -o prog prog.c && ./prog < umbrella.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=2000 -Dtilt=5 -o prog prog.c && ./prog < vase.txt
|
||||
|
||||
$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=2000 -Dtilt=20 -o prog prog.c && ./prog < vase.txt</code></pre>
|
||||
<p>More shapes: <code>stick.txt</code>, <code>cylinder.txt</code>, <code>halo.txt</code>, and even <code>prog.c</code>.</p>
|
||||
<p>Yes, <code>prog.c</code> itself can be used as input. Try it:</p>
|
||||
<pre><code>$ gcc -O3 -DW=120 -DH=24 -Ddt=0.01 -De=0.5 -Du=0.5 -Drpm=1000 -Dtilt=5 -o prog prog.c && ./prog < prog.c</code></pre>
|
||||
<!--
|
||||
|
||||
Copyright © 1984-2025 by Landon Curt Noll and Leonid A. Broukhis. All Rights Reserved.
|
||||
|
||||
You are free to share and adapt this file under the terms of this license:
|
||||
|
||||
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
|
||||
|
||||
For more information, see:
|
||||
|
||||
https://creativecommons.org/licenses/by-sa/4.0/
|
||||
|
||||
-->
|
||||
<!-- AFTER: last line of markdown file: 2024/endoh2/README.md -->
|
||||
|
||||
<!-- END: this line ends content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
<!-- START: this line starts content for HTML phase 22 by: bin/output-index-inventory.sh via bin/md2html.sh -->
|
||||
|
||||
<!-- START: this line starts content generated by: bin/output-index-inventory.sh -->
|
||||
|
||||
<div id="inventory">
|
||||
<h1 id="inventory-for-2024endoh2">Inventory for 2024/endoh2</h1>
|
||||
</div>
|
||||
<h2 id="primary-files">Primary files</h2>
|
||||
<ul>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/prog.c">prog.c</a> - entry source code</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/Makefile">Makefile</a> - entry Makefile</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/prog.orig.c">prog.orig.c</a> - original source code</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/bottle.txt">bottle.txt</a> - 1/2 of a wine bottle</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/cylinder.txt">cylinder.txt</a> - 1/2 of a cylinder</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/egg.txt">egg.txt</a> - 1/2 of an egg</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/halo.txt">halo.txt</a> - 1/2 of a halo</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/stick.txt">stick.txt</a> - 1/2 of a stick</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/tippe-top2.txt">tippe-top2.txt</a> - 1/2 of a tippe top style 2</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/tippe-top3.txt">tippe-top3.txt</a> - 1/2 of a tippe top style 3</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/tippe-top.txt">tippe-top.txt</a> - 1/2 of a tippe top style 1</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/top2.txt">top2.txt</a> - 1/2 of a classic top style 2</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/top3.txt">top3.txt</a> - 1/2 of a classic top style 3</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/top4.txt">top4.txt</a> - 1/2 of a classic top style 4</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/top.txt">top.txt</a> - 1/2 of a classic top style 1</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/try.sh">try.sh</a> - script to try entry</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/umbrella.txt">umbrella.txt</a> - 1/2 of an umbrella</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/vase.txt">vase.txt</a> - 1/2 of a flower vase</li>
|
||||
</ul>
|
||||
<h2 id="secondary-files">Secondary files</h2>
|
||||
<ul>
|
||||
<li><a href="2024_endoh2.tar.bz2">2024_endoh2.tar.bz2</a> - download entry tarball</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/README.md">README.md</a> - markdown source for this web page</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/.entry.json">.entry.json</a> - entry summary and manifest in JSON</li>
|
||||
<li><a href="https://github.com/ioccc-src/winner/blob/master/2024/endoh2/.gitignore">.gitignore</a> - list of files that should not be committed under git</li>
|
||||
<li><a href=".path">.path</a> - directory path from top level directory</li>
|
||||
<li><a href="index.html">index.html</a> - this web page</li>
|
||||
</ul>
|
||||
<hr style="width:10%;text-align:left;margin-left:0">
|
||||
<h4>
|
||||
Jump to: <a href="#">top</a>
|
||||
</h4>
|
||||
|
||||
<!-- END: next line ends content generated by: bin/output-index-inventory.sh -->
|
||||
|
||||
<!-- END: this line ends content for HTML phase 22 by: bin/output-index-inventory.sh via bin/md2html.sh -->
|
||||
<!-- START: this line starts content from: inc/after-content.default.html -->
|
||||
|
||||
</div>
|
||||
|
||||
<!-- END: this line ends content from: inc/after-content.default.html -->
|
||||
<!-- START: this line starts content from: inc/footer.inventory.html -->
|
||||
|
||||
<!--
|
||||
|
||||
Copyright © 1984-2025 by Landon Curt Noll. All Rights Reserved.
|
||||
|
||||
You are free to share and adapt this file under the terms of this license:
|
||||
|
||||
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
|
||||
|
||||
For more information, see:
|
||||
|
||||
https://creativecommons.org/licenses/by-sa/4.0/
|
||||
|
||||
-->
|
||||
|
||||
<div class="footer">
|
||||
|
||||
<div id="copyright"><h3>Copyright © 1984-2025 by Landon Curt Noll:
|
||||
<a href="https://creativecommons.org/faq/#what-does-some-rights-reserved-mean"
|
||||
target="_blank"
|
||||
rel="license noopener noreferrer">Some Rights Reserved</a></h3>
|
||||
<p>
|
||||
This work is <b>licensed by Landon Curt Noll</b> under
|
||||
<b><a href="https://creativecommons.org/licenses/by-sa/4.0/?ref=chooser-v1"
|
||||
target="_blank"
|
||||
rel="license noopener noreferrer"
|
||||
style="display:inline-block;">CC BY-SA 4.0</a></b>.
|
||||
<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
|
||||
src="../../png/cc.png"
|
||||
alt="cc inside circle symbol">
|
||||
<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
|
||||
src="../../png/by.png"
|
||||
alt="person inside circle symbol">
|
||||
<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
|
||||
src="../../png/sa.png"
|
||||
alt="arrow looping back on itself inside circle symbol"><br>
|
||||
You should <b>carefully review</b> the
|
||||
<b><a href="https://creativecommons.org/licenses/by-sa/4.0/legalcode.en"
|
||||
target="_blank"
|
||||
rel="license noopener noreferrer">CC BY-SA 4.0 LEGAL CODE</a></b>
|
||||
before using the licensed material.<br>
|
||||
You may wish to review the
|
||||
<b><a href="../../license.html"
|
||||
target="_blank"
|
||||
rel="license noopener noreferrer">highlights of some of the key features and terms</a></b>
|
||||
of <b>CC BY-SA 4.0</b>.<br>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div id="coda"><h3>Coda</h3>
|
||||
<p>
|
||||
<a href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fwww.ioccc.org%2F2024%2Fendoh2%2Findex.html" rel="nofollow">Nu HTML check this web page</a><br>
|
||||
<a href="#top">Jump to top</a> <a href="#content">Jump to Content</a> <a href="#inventory">Jump to Inventory</a><br>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- END: this line ends content from: inc/footer.inventory.html -->
|
||||
<!-- START: this line starts content from: inc/bottom.default.html -->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<!-- END: this line ends content from: inc/bottom.default.html -->
|
||||
@@ -0,0 +1,27 @@
|
||||
/* cc -O3 -DW=80 -DH=24 -Ddt=.01 -De=.5 -Du=.5 -Drpm=1000 -Dtilt=5 prog.c */#include<stdio.h>
|
||||
/* ./a.out < prog.c # or your favorite pattern file for a spinning top */#include<unistd.h>
|
||||
/**/char*C,B[H*W+9]="\x1b[H\x1b[J";typedef float S;typedef struct Q{S a[4];}Q;S*E,M,O,z,Z=71.
|
||||
/8136*tilt,g,h=1;int i=1,j,k,a,b;struct P{Q x,v;S m;}L[1<<20],*p;void o(S*p){for(k=1;k<99;h*=
|
||||
Z/k++)p[k%2]+=h=k%2?-h:h;}Q Y,w={{71*rpm/13560.}}, I[4],N={{1}},V,q,X={{30}},J,G;Q A(Q a,Q b
|
||||
)/**/{for(k=4;k--;)a.a[k]+=b.a[k];return a;}Q m(Q a,Q b){Q q=G;for(k=16;k--;){q.a[k%4]+=b.a[
|
||||
k/4]*(1-(5432>>k&2))*a.a[19995>>(k>7?15- k:k)*2&3];}return q;}void K(S x){for(h=k=
|
||||
99;k;h=(x/h+h)/2)k--;}Q s(Q a,S b){J . a[3]=b;return m(a,J);}S D(Q a,Q b){for
|
||||
(h=k=0;k<4/+1;k++){h+=a.a[k]*b.a[k] ;} return h;}Q U(Q a){K(D(a,a));h=1/+h;
|
||||
return s(a,/**/h);}int main(){C=B+ 6;o( q. a+2);for(p=L;fgets(C,W*H-1,stdin);
|
||||
b--){for(a=0/1;j=C[a++],j&&j!=47;) {for(Z=0;j> 32&&Z*113<710;h=(a-.5+i*61e-7)/2,E
|
||||
=(S*)p,M-=z/=j%2?2:2e3,*E=b,o(E+1), Y=A(Y,s(p->x,p->m=z)),p++,i=48271*
|
||||
i%65535){Z/**/+=z=2./a;}}}for(;p--> L;)p->x=A(p->x,s(Y,1/M));for(;;us\
|
||||
leep(1e4/1)){for(i=H*W;i--;C[i]=i>H* W-W?(a&16)+45 :i%W?32:10)a=i+O;for(j
|
||||
=20;j--/1;){Q F={{M}},T=G,v=G,t[3]={ G};for(p=L;p->m;p++){for(i=3,Y=p->x;i
|
||||
--;t[/**/i].a[i]+=m(Y,Y).a[3]*p->m){t [i]=A(t[i],s(Y,Y.a[i]*p->m));}}for(Z=i=0
|
||||
;i<3/1;i++){Z-=D(t[i],I[i]=m(t[(i+1)% 3],t[(i+2)%3]));}for(;i--;I[i].a[3]=0){I[i]
|
||||
=s/**/(I[i],3/Z);}for(p=L;p->m;p++){if (E=p->v.a,(i=+W*(b=H-1.5-*E)+(a=.5+(E[1]-O)*2+
|
||||
W/2))>0&&i<W*H&&0<a&&a<W){C[i]=E[2]<X.a[ 2]&&C[i]-64?58:64;}}Z=0;E=v.a;for(p=L;p->m;p++){Q
|
||||
r/**/=s(q,-1);r.a[3]*=-1;z=*(p->v=A(r=m( m(q,p->x),r),X)).a;if(z<0){for(i=4;i--;){E[i]=D(I[i
|
||||
/1],m(r,N));}g=(1+e)**A(V,m(w,r)).a/(*m (v,r).a-1/M);v=A(V,m(w,r));*E=E[3]=0;F=A(F,v=A(s(N,g
|
||||
/1*z-g),s(U (v),g*u)));
|
||||
/**/T=A(T,m (r,v));Z=Z>
|
||||
/**/z?z:Z;} }*X.a-=Z;X=
|
||||
/*IOCCC*/A(X,s(V=A(V,s(F,dt/-M)),dt));for(i=3;i--;)E[i]=D(I[i],T)*dt;q=U(A(q,s(m(w=A(w,v),q),
|
||||
/*2025*/.5*dt)));}O+=(X.a[1]-O)/50;K(D(w,w)*36476);printf("%s\n%*.0f rpm",B,W-5,h);B[5]=72;}}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/* cc -O3 -DW=80 -DH=24 -Ddt=.01 -De=.5 -Du=.5 -Drpm=1000 -Dtilt=5 prog.c */#include<stdio.h>
|
||||
/* ./a.out < prog.c # or your favorite pattern file for a spinning top */#include<unistd.h>
|
||||
/**/char*C,B[H*W+9]="\x1b[H\x1b[J";typedef float S;typedef struct Q{S a[4];}Q;S*E,M,O,z,Z=71.
|
||||
/8136*tilt,g,h=1;int i=1,j,k,a,b;struct P{Q x,v;S m;}L[1<<20],*p;void o(S*p){for(k=1;k<99;h*=
|
||||
Z/k++)p[k%2]+=h=k%2?-h:h;}Q Y,w={{71*rpm/13560.}}, I[4],N={{1}},V,q,X={{30}},J,G;Q A(Q a,Q b
|
||||
)/**/{for(k=4;k--;)a.a[k]+=b.a[k];return a;}Q m(Q a,Q b){Q q=G;for(k=16;k--;){q.a[k%4]+=b.a[
|
||||
k/4]*(1-(5432>>k&2))*a.a[19995>>(k>7?15- k:k)*2&3];}return q;}void K(S x){for(h=k=
|
||||
99;k;h=(x/h+h)/2)k--;}Q s(Q a,S b){J . a[3]=b;return m(a,J);}S D(Q a,Q b){for
|
||||
(h=k=0;k<4/+1;k++){h+=a.a[k]*b.a[k] ;} return h;}Q U(Q a){K(D(a,a));h=1/+h;
|
||||
return s(a,/**/h);}int main(){C=B+ 6;o( q. a+2);for(p=L;fgets(C,W*H-1,stdin);
|
||||
b--){for(a=0/1;j=C[a++],j&&j!=47;) {for(Z=0;j> 32&&Z*113<710;h=(a-.5+i*61e-7)/2,E
|
||||
=(S*)p,M-=z/=j%2?2:2e3,*E=b,o(E+1), Y=A(Y,s(p->x,p->m=z)),p++,i=48271*
|
||||
i%65535){Z/**/+=z=2./a;}}}for(;p--> L;)p->x=A(p->x,s(Y,1/M));for(;;us\
|
||||
leep(1e4/1)){for(i=H*W;i--;C[i]=i>H* W-W?(a&16)+45 :i%W?32:10)a=i+O;for(j
|
||||
=20;j--/1;){Q F={{M}},T=G,v=G,t[3]={ G};for(p=L;p->m;p++){for(i=3,Y=p->x;i
|
||||
--;t[/**/i].a[i]+=m(Y,Y).a[3]*p->m){t [i]=A(t[i],s(Y,Y.a[i]*p->m));}}for(Z=i=0
|
||||
;i<3/1;i++){Z-=D(t[i],I[i]=m(t[(i+1)% 3],t[(i+2)%3]));}for(;i--;I[i].a[3]=0){I[i]
|
||||
=s/**/(I[i],3/Z);}for(p=L;p->m;p++){if (E=p->v.a,(i=+W*(b=H-1.5-*E)+(a=.5+(E[1]-O)*2+
|
||||
W/2))>0&&i<W*H&&0<a&&a<W){C[i]=E[2]<X.a[ 2]&&C[i]-64?58:64;}}Z=0;E=v.a;for(p=L;p->m;p++){Q
|
||||
r/**/=s(q,-1);r.a[3]*=-1;z=*(p->v=A(r=m( m(q,p->x),r),X)).a;if(z<0){for(i=4;i--;){E[i]=D(I[i
|
||||
/1],m(r,N));}g=(1+e)**A(V,m(w,r)).a/(*m (v,r).a-1/M);v=A(V,m(w,r));*E=E[3]=0;F=A(F,v=A(s(N,g
|
||||
/1*z-g),s(U (v),g*u)));
|
||||
/**/T=A(T,m (r,v));Z=Z>
|
||||
/**/z?z:Z;} }*X.a-=Z;X=
|
||||
/*IOCCC*/A(X,s(V=A(V,s(F,dt/-M)),dt));for(i=3;i--;)E[i]=D(I[i],T)*dt;q=U(A(q,s(m(w=A(w,v),q),
|
||||
/*2025*/.5*dt)));}O+=(X.a[1]-O)/50;K(D(w,w)*36476);printf("%s\n%*.0f rpm",B,W-5,h);B[5]=72;}}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// A stick
|
||||
|
||||
// Use `-Drpm=10 -Dtilt=30`
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
@@ -0,0 +1,20 @@
|
||||
// A tippe top
|
||||
|
||||
// Use `-Drpm=2500 -Dtilt=5`
|
||||
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
. ..
|
||||
. .
|
||||
. .
|
||||
. .
|
||||
. .
|
||||
. .
|
||||
.#.#.#.#.#.#.#
|
||||
#.#.#.#.#.#.#
|
||||
.#.#.#.#.#.
|
||||
#.#.#.#.
|
||||
@@ -0,0 +1,25 @@
|
||||
// A long-stem tippe top
|
||||
|
||||
// Use `-Drpm=4000 -Dtilt=5`
|
||||
|
||||
..
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
. .
|
||||
. .
|
||||
. .
|
||||
. .
|
||||
.#.#.#.#.#.#.#
|
||||
#.#.#.#.#.#.#
|
||||
.#.#.#.#.#.
|
||||
#.#.#.#.
|
||||
@@ -0,0 +1,23 @@
|
||||
// A thick-stem tippe top
|
||||
|
||||
// Use `-Drpm=2500 -Dtilt=5`
|
||||
|
||||
#
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
. #.
|
||||
. .#
|
||||
. #.
|
||||
. .#
|
||||
. #.
|
||||
. .#
|
||||
. #.#
|
||||
#.#.#.#.#.#.#
|
||||
.#.#.#.#.#.
|
||||
#.#.#.#
|
||||
@@ -0,0 +1,20 @@
|
||||
// A typical spinning top
|
||||
|
||||
// Use `-Drpm=1000 -Dtilt=5`
|
||||
|
||||
.
|
||||
.
|
||||
. // Twirl here
|
||||
.
|
||||
.
|
||||
.
|
||||
...
|
||||
#####
|
||||
##
|
||||
# // Spin!
|
||||
##
|
||||
#####
|
||||
##
|
||||
#
|
||||
#
|
||||
# // Looks painful
|
||||
@@ -0,0 +1,18 @@
|
||||
// Yet another typical top
|
||||
|
||||
// Use `-Drpm=500 -Dtilt=5`
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
###############
|
||||
#
|
||||
#
|
||||
#####
|
||||
#####
|
||||
####
|
||||
#
|
||||
#
|
||||
@@ -0,0 +1,20 @@
|
||||
// An eggplant-like top
|
||||
|
||||
// Use `-Drpm=500 -Dtilt=5`
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#####
|
||||
##
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
##
|
||||
##
|
||||
#
|
||||
@@ -0,0 +1,18 @@
|
||||
// A corn-style top
|
||||
|
||||
// Use `-Drpm=500 -Dtilt=5`
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
###############
|
||||
##
|
||||
##
|
||||
##
|
||||
##
|
||||
##
|
||||
##
|
||||
#
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate 2024/endoh2
|
||||
|
||||
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
|
||||
# this way allows us to have the user specify a different compiler in an easy way.
|
||||
#
|
||||
[[ -z "$CC" ]] && CC="cc"
|
||||
|
||||
# make sure the program has been built
|
||||
#
|
||||
make CC="$CC" all tipple >/dev/null || exit 1
|
||||
|
||||
# clear the screen
|
||||
#
|
||||
clear
|
||||
|
||||
# try the program
|
||||
#
|
||||
echo 'NOTE: To exit, press CTRL+C' 1>&2
|
||||
echo 1>&2
|
||||
read -r -n 1 -p "Press any key to run: ./tipple < tippe-top2.txt: "
|
||||
echo 1>&2
|
||||
echo 1>&2
|
||||
./tipple < tippe-top2.txt
|
||||
echo 1>&2
|
||||
@@ -0,0 +1,19 @@
|
||||
// An umbrella
|
||||
|
||||
// Use `-Drpm=1000 -Dtilt=30` or `-Drpm=1000 -Dtilt=180`
|
||||
|
||||
########
|
||||
# ###
|
||||
# ##
|
||||
# ##
|
||||
# #
|
||||
# #
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
@@ -0,0 +1,18 @@
|
||||
// A vase
|
||||
|
||||
// Use `-Drpm=2000 -Dtilt=5` or `-Drpm=2000 -Dtilt=20`
|
||||
|
||||
...
|
||||
.
|
||||
.
|
||||
.
|
||||
..
|
||||
..
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
##
|
||||
######
|
||||
Reference in new issue
Block a user