diff options
34 files changed, 2808 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e8e99f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +C=g++ +FLAGS=-std=c++11 -Wno-write-strings `pkg-config --libs --cflags sdl2` + +default: all + +all: src/*.cpp src/*.h + $(C) -o qualums src/*.cpp $(FLAGS) + +clean: + rm qualums diff --git a/README.md b/README.md new file mode 100644 index 0000000..d84ff13 --- /dev/null +++ b/README.md @@ -0,0 +1,87 @@ +# Qualums +### About Qualums +Qualums exist on a grid. Every qualum has a certain position, x speed, y speed, and color. At each iteration, every qualum moves to the right by its x speed, and downwards by its y speed. Qualums interact when they collide, i.e. when they both occupy the same grid square at once. It is possible for more than two qualums to collide at once, however the use of these collisions is discouraged, as the outcome will depend on the order in which the qualums were created. Here are the rules for qualum collision: +1. If both qualums are red, they are both destroyed. +2. If one qualum is red, it destroys the other one. +3. If one qualum is cyan, the qualum is delayed (it cannot move or collide) for 1 iteration. This means that (assuming the cyan qualum is stationary) it will take a moving qualum 2 iterations to pass through a cyan qualum. +4. If one qualum is orange, the qualum is delayed for 16 iterations. This qualum is like a more extreme version of the cyan qualum, and it can be used to avoid very long chains of cyan qualums. +5. If one qualum is gray, the other qualum turns left. +6. If one qualum is either green or blue, and the other is also either green or blue, the two qualums will merge, forming one qualum whose speed is the sum of the two qualums' speed. The resulting qualum will be green unless both qualums were green. This is a chart of the color of the resulting qualum (this is NAND where green = true and blue = false): +``` +Qualum 1 | Qualum 2 | Output qualum +Blue Blue Green +Blue Green Green +Green Blue Green +Green Green Blue +``` +7. If both qualums are purple, they will both be destroyed. +8. If one qualum is purple, it will destroy the other qualum, and create two copies of it. The copies will be sent out in two different directions, both of which are perpendicular to the original qualum's direction. +9. If one qualum is yellow, it will stop the other qualum. For example, if a qualum moving right collides with a yellow qualum, it will remain stationary on the square to the left of the yellow qualum. + +So, you can think of giving these names to the colors of qualum: +Red - A destroyer +Cyan/Orange - A delayer +Gray - A turner +Blue/green - Bits of data (0 and 1 respectively) +Purple - A splitter +Yellow - A stopper +### Building +If you wish to build Qualums, you will need to install: +- g++ +- make +- SDL2 + +You can build it using `make clean && make all`. + +You might want to modify the size of the output qualum grid and the size of the window. You can do this by changing `GRID_WIDTH` and `GRID_HEIGHT` in `src/Rendering.h` and you can change `RENDER_SCALE` in `src/Rendering.cpp` to change the size of qualums in pixels. Hopefully, the ability to change these variables without rebuilding (in .qua files or in command line options) will be available soon. +### Running +To run a .qua file, simply use the command `./qualums [your file].qua`. +The qualum repository includes several example .qua files (including an 8-bit adder!) which can be run with, for example, +``` +./qualums add8test.qua +``` +You can change the numbers added in `add8test.qua` by editing the file. +### .qua files +.qua files begin with a one-line header. **The first line of a .qua file is always ignored.** It can be helpful to add +``` +x y speedX speedY color +``` +To the top of the file so that the text is aligned. +To add a qualum, just add a new line to the file, and separate the x position, y position, x speed, y speed, and color with any number of spaces/tabs. +Each color is represented using a 2-letter code: +``` +GA - Gray +RE - Red +BL - Blue +GE - Green +PU - Purple +YE - Yellow +CY - Cyan +OR - Orange +``` +So, to create a green qualum at (10,50) that will move towards, then collide with (and be split by) a purple qualum at (50,50): +``` +x y speedX speedY color +10 50 1 0 GE +50 50 0 0 PU # Comments begin with #; they can be put at the end of a line +# Or on a new line +``` +#### Including other .qua files +To include a .qua file in another .qua file, put `![name of file]` in the including file. The x positions & speeds, and the y positions & speeds of the qualums in the file will be shifted by the numbers in the x, y, speedX, and speedY columns. For example, + +`wall.qua`: +``` +x y speedX speedY color +0 0 0 0 YE +1 0 0 0 YE +2 0 0 0 YE +# A horizontal wall to stop qualums +``` +`anotherfile.qua`: +``` +x y speedX speedY color +30 30 1 0 !wall.qua # The yellow qualums will be at (30, 30), (31, 30), and (32, 30) +# Since speedX = 1, the wall will be moving to the right. +41 20 0 1 GE # This qualum will move downwards and collide with the wall +``` +At the moment, all relative includes are relative to the folder the executable is in, not the folder the .qua file is in. This problem should be fixed reasonably soon, but for the moment, you can only use paths relative to the executable or absolute paths.
\ No newline at end of file diff --git a/examples/20row.qua b/examples/20row.qua new file mode 100644 index 0000000..30d681c --- /dev/null +++ b/examples/20row.qua @@ -0,0 +1,22 @@ +x y speedX speedY color +0 0 0 0 OR +1 0 0 0 OR +2 0 0 0 OR +3 0 0 0 OR +4 0 0 0 OR +5 0 0 0 OR +6 0 0 0 OR +7 0 0 0 OR +8 0 0 0 OR +9 0 0 0 OR +10 0 0 0 OR +11 0 0 0 OR +12 0 0 0 OR +13 0 0 0 OR +14 0 0 0 OR +15 0 0 0 OR +16 0 0 0 OR +17 0 0 0 OR +18 0 0 0 OR +19 0 0 0 OR + diff --git a/examples/add8.qua b/examples/add8.qua new file mode 100644 index 0000000..f52008b --- /dev/null +++ b/examples/add8.qua @@ -0,0 +1,605 @@ +x y speedX speedY color +## Re-route inputs +# Bring down +-16 -17 0 0 PU +-15 -16 0 0 PU +-14 -15 0 0 PU +-13 -14 0 0 PU +-12 -13 0 0 PU +-11 -12 0 0 PU +-10 -11 0 0 PU +-9 -10 0 0 PU +-7 -8 0 0 PU +-6 -7 0 0 PU +-5 -6 0 0 PU +-4 -5 0 0 PU +-3 -4 0 0 PU +-2 -3 0 0 PU +-1 -2 0 0 PU +0 -1 0 0 PU + +-16 -18 0 0 RE +-15 -17 0 0 RE +-14 -16 0 0 RE +-13 -15 0 0 RE +-12 -14 0 0 RE +-11 -13 0 0 RE +-10 -12 0 0 RE +-9 -11 0 0 RE +-7 -9 0 0 RE +-6 -8 0 0 RE +-5 -7 0 0 RE +-4 -6 0 0 RE +-3 -5 0 0 RE +-2 -4 0 0 RE +-1 -3 0 0 RE +0 -2 0 0 RE +# Digit x (starting at 0) of A is on column -x +# Digit x of B is on column -x-9 +## First pair +0 20 0 0 GA +1 20 0 0 CY +2 20 0 0 CY +3 20 0 0 CY +4 20 0 0 CY +5 20 0 0 CY +6 20 0 0 CY +7 20 0 0 CY +8 20 0 0 CY +9 20 0 0 CY +-9 21 0 0 GA + +20 20 0 0 GA +21 21 0 0 GA + +20 3 0 0 GA +21 4 0 0 GA + +19 3 0 0 GA +18 4 0 0 GA + +19 5 0 0 GA +18 6 0 0 GA + +38 5 0 0 GA +37 6 0 0 GA + +38 3 0 0 GA +37 4 0 0 GA + +35 3 0 0 GA +36 4 0 0 GA +35 4 0 0 CY + + +35 17 0 0 !examples/half.qua # Outputs to 33/34, 43 +# Redirect last digit of answer +34 44 0 0 GA +40 44 0 0 GA +40 -3 0 0 PU +39 -3 0 0 RE +## Delay rest of bits while first pair is adding +0 0 0 0 !examples/add8rect1.qua +## Second pair +# Redirect carry in +33 45 0 0 GA +46 45 0 0 GA +46 5 0 0 GA +45 5 0 0 GA +45 6 0 0 GA +46 6 0 0 CY +47 6 0 0 CY +48 6 0 0 CY +49 6 0 0 CY +50 6 0 0 CY +51 6 0 0 CY +52 6 0 0 CY +53 6 0 0 CY +54 6 0 0 CY +55 6 0 0 CY +56 6 0 0 CY +57 6 0 0 CY +58 6 0 0 CY +59 6 0 0 CY +60 6 0 0 PU +60 5 0 0 RE +60 7 0 0 OR +# Redirect 2 digits +-1 50 0 0 GA +-10 51 0 0 GA +42 50 0 0 GA +44 51 0 0 GA +44 3 0 0 PU +43 3 0 0 RE +42 1 0 0 PU +41 1 0 0 RE +43 1 0 0 CY +44 1 0 0 CY +45 1 0 0 CY +46 1 0 0 CY +47 1 0 0 CY +48 1 0 0 CY +61 3 0 0 PU +61 2 0 0 RE +62 1 0 0 PU +62 0 0 0 RE +# Add +60 10 0 0 !examples/full.qua # Outputs to 63/64, 87 +# Redirect sum +64 90 0 0 GA +77 90 0 0 GA +77 -4 0 0 PU +76 -4 0 0 RE +## Delay other bits while second pair is adding +0 8 0 0 !examples/add8rect2.qua +## Third pair +# Redirect carry in +63 91 0 0 GA +79 91 0 0 GA +79 1 0 0 PU +78 1 0 0 RE +97 1 0 0 PU +97 0 0 0 RE +# Redirect 2 bits +-2 92 0 0 GA +-11 93 0 0 GA +80 92 0 0 GA +81 93 0 0 GA +80 0 0 0 PU +79 0 0 0 RE +81 -1 0 0 PU +80 -1 0 0 RE +95 -1 0 0 PU +95 -2 0 0 RE +96 0 0 0 PU +96 -1 0 0 RE +# Delay bits +81 92 0 0 CY +81 91 0 0 CY +81 90 0 0 CY +81 89 0 0 CY +81 88 0 0 CY +81 87 0 0 CY +81 86 0 0 CY +81 85 0 0 CY +81 84 0 0 CY + +80 91 0 0 OR +96 8 0 0 CY +96 7 0 0 CY +96 6 0 0 CY +96 5 0 0 CY +96 4 0 0 CY +96 3 0 0 CY +95 8 0 0 CY +# Add +95 10 0 0 !examples/full.qua # Outputs to 98/99, 87 +# Redirect sum +99 90 0 0 GA +112 90 0 0 GA +112 -5 0 0 PU +111 -5 0 0 RE +## Fourth pair +# Redirect carry in +98 91 0 0 GA +114 91 0 0 GA +114 1 0 0 PU +113 1 0 0 RE +132 1 0 0 PU +132 0 0 0 RE +# Delay while last bits are adding +0 24 0 0 !examples/add8rect3.qua +# Redirect bits +-3 94 0 0 GA +-12 95 0 0 GA +115 94 0 0 GA +116 95 0 0 GA +115 0 0 0 PU +114 0 0 0 RE +116 -1 0 0 PU +115 -1 0 0 RE +130 -1 0 0 PU +130 -2 0 0 RE +131 0 0 0 PU +131 -1 0 0 RE +# Delay bits +115 93 0 0 OR +115 92 0 0 CY +115 91 0 0 CY +115 90 0 0 CY +115 89 0 0 CY +115 88 0 0 CY +115 87 0 0 CY +115 86 0 0 CY + +116 92 0 0 CY +116 91 0 0 CY +116 90 0 0 CY +116 89 0 0 CY +116 88 0 0 CY +116 87 0 0 CY +116 86 0 0 CY +116 85 0 0 CY +116 84 0 0 CY +116 83 0 0 CY +116 82 0 0 CY +# Add +130 10 0 0 !examples/full.qua # Outputs to 133/134, 87 +# Redirect sum +134 90 0 0 GA +147 90 0 0 GA +147 -6 0 0 PU +146 -6 0 0 RE +## Fifth pair +# Redirect carry in +133 91 0 0 GA +149 91 0 0 GA +149 1 0 0 PU +148 1 0 0 RE +167 1 0 0 PU +167 0 0 0 RE +# Delay while last bits are adding +0 44 0 0 !examples/add8rect4.qua +# Redirect bits +-4 96 0 0 GA +-13 97 0 0 GA +150 96 0 0 GA +151 97 0 0 GA +150 0 0 0 PU +149 0 0 0 RE +151 -1 0 0 PU +150 -1 0 0 RE +165 -1 0 0 PU +165 -2 0 0 RE +166 0 0 0 PU +166 -1 0 0 RE +# Delay bits +150 93 0 0 OR +150 92 0 0 CY +150 91 0 0 CY +150 90 0 0 CY +150 89 0 0 CY +150 88 0 0 CY +150 87 0 0 CY +150 86 0 0 CY +150 85 0 0 CY + +151 92 0 0 CY +151 91 0 0 CY +151 90 0 0 CY +151 89 0 0 CY +151 88 0 0 CY +151 87 0 0 CY +151 86 0 0 CY +151 85 0 0 CY +151 84 0 0 CY +151 83 0 0 CY +151 82 0 0 CY +151 81 0 0 CY +# Add +165 10 0 0 !examples/full.qua # Outputs to 168/169, 87 +# Redirect sum +169 90 0 0 GA +182 90 0 0 GA +182 -7 0 0 PU +181 -7 0 0 RE + + +## Sixth pair +# Redirect carry in +168 91 0 0 GA +184 91 0 0 GA +184 1 0 0 PU +183 1 0 0 RE +202 1 0 0 PU +202 0 0 0 RE +# Delay while last bits are adding +0 66 0 0 !examples/add8rect5.qua +# Redirect bits +-5 98 0 0 GA +-14 99 0 0 GA +185 98 0 0 GA +186 99 0 0 GA +185 0 0 0 PU +184 0 0 0 RE +186 -1 0 0 PU +185 -1 0 0 RE +200 -1 0 0 PU +200 -2 0 0 RE +201 0 0 0 PU +201 -1 0 0 RE +# Delay bits +185 93 0 0 OR +185 92 0 0 CY +185 91 0 0 CY +185 90 0 0 CY +185 89 0 0 CY +185 88 0 0 CY +185 87 0 0 CY +185 86 0 0 CY +185 85 0 0 CY +185 84 0 0 CY + +186 92 0 0 CY +186 91 0 0 CY +186 90 0 0 CY +186 89 0 0 CY +186 88 0 0 CY +186 87 0 0 CY +186 86 0 0 CY +186 85 0 0 CY +186 84 0 0 CY +186 83 0 0 CY +186 82 0 0 CY +186 81 0 0 CY +186 80 0 0 CY +# Add +200 10 0 0 !examples/full.qua # Outputs to 203/204, 87 +# Redirect sum +204 90 0 0 GA +217 90 0 0 GA +217 -8 0 0 PU +216 -8 0 0 RE + + +## Seventh pair +# Redirect carry in +203 91 0 0 GA +219 91 0 0 GA +219 1 0 0 PU +218 1 0 0 RE +237 1 0 0 PU +237 0 0 0 RE +# Delay while last bits are adding +-5 100 0 0 !examples/add8rect6.qua +# Redirect bits +-6 100 0 0 GA +-15 101 0 0 GA +220 100 0 0 GA +221 101 0 0 GA +220 0 0 0 PU +219 0 0 0 RE +221 -1 0 0 PU +220 -1 0 0 RE +235 -1 0 0 PU +235 -2 0 0 RE +236 0 0 0 PU +236 -1 0 0 RE +# Delay bits +220 93 0 0 OR +220 92 0 0 CY +220 91 0 0 CY +220 90 0 0 CY +220 89 0 0 CY +220 88 0 0 CY +220 87 0 0 CY +220 86 0 0 CY +220 85 0 0 CY +220 84 0 0 CY +220 83 0 0 CY + +221 92 0 0 CY +221 91 0 0 CY +221 90 0 0 CY +221 89 0 0 CY +221 88 0 0 CY +221 87 0 0 CY +221 86 0 0 CY +221 85 0 0 CY +221 84 0 0 CY +221 83 0 0 CY +221 82 0 0 CY +221 81 0 0 CY +221 80 0 0 CY +221 79 0 0 CY +# Add +235 10 0 0 !examples/full.qua # Outputs to 238/239, 87 +# Redirect sum +239 90 0 0 GA +252 90 0 0 GA +252 -9 0 0 PU +251 -9 0 0 RE + +## Eighth pair +# Redirect carry in +238 91 0 0 GA +254 91 0 0 GA +254 1 0 0 PU +253 1 0 0 RE +272 1 0 0 PU +272 0 0 0 RE +# Delay while last bits are adding +15 100 0 0 !examples/add8rect7.qua +# Redirect bits +-7 102 0 0 GA +-16 103 0 0 GA +255 102 0 0 GA +256 103 0 0 GA +255 0 0 0 PU +254 0 0 0 RE +256 -1 0 0 PU +255 -1 0 0 RE +270 -1 0 0 PU +270 -2 0 0 RE +271 0 0 0 PU +271 -1 0 0 RE +# Delay bits +255 93 0 0 OR +255 92 0 0 CY +255 91 0 0 CY +255 90 0 0 CY +255 89 0 0 CY +255 88 0 0 CY +255 87 0 0 CY +255 86 0 0 CY +255 85 0 0 CY +255 84 0 0 CY +255 83 0 0 CY +255 82 0 0 CY + +256 92 0 0 CY +256 91 0 0 CY +256 90 0 0 CY +256 89 0 0 CY +256 88 0 0 CY +256 87 0 0 CY +256 86 0 0 CY +256 85 0 0 CY +256 84 0 0 CY +256 83 0 0 CY +256 82 0 0 CY +256 81 0 0 CY +256 80 0 0 CY +256 79 0 0 CY +256 78 0 0 CY +# Add +270 10 0 0 !examples/full.qua # Outputs to 273/274, 87 + +# Redirect sum & carry +274 90 0 0 GA +287 90 0 0 GA +273 91 0 0 GA +288 91 0 0 GA +288 90 0 0 CY +288 89 0 0 CY +288 88 0 0 CY +288 87 0 0 CY + + +287 -10 0 0 PU +286 -10 0 0 RE +288 -11 0 0 PU +287 -11 0 0 RE + +## Delay outputs +253 -9 0 0 !examples/20row.qua +253 -8 0 0 !examples/20row.qua +253 -7 0 0 !examples/20row.qua +253 -6 0 0 !examples/20row.qua +253 -5 0 0 !examples/20row.qua +253 -4 0 0 !examples/20row.qua +253 -3 0 0 !examples/20row.qua +273 -3 0 0 OR +274 -3 0 0 OR +273 -4 0 0 OR + +289 -8 0 0 OR +289 -7 0 0 OR +289 -6 0 0 OR +289 -5 0 0 OR +289 -4 0 0 OR +289 -3 0 0 OR +289 -9 0 0 CY +290 -9 0 0 CY +291 -9 0 0 CY +292 -9 0 0 CY +293 -9 0 0 CY +294 -9 0 0 CY +295 -9 0 0 CY +296 -9 0 0 CY +297 -9 0 0 CY +298 -9 0 0 CY +299 -9 0 0 CY +300 -9 0 0 CY +301 -9 0 0 CY +302 -9 0 0 CY +303 -9 0 0 CY + +295 -10 0 0 CY +296 -10 0 0 CY +297 -10 0 0 CY +298 -10 0 0 CY +299 -10 0 0 CY +300 -10 0 0 CY +301 -10 0 0 CY +302 -10 0 0 CY + +295 -4 0 0 CY +296 -4 0 0 CY + +295 -6 0 0 CY +296 -6 0 0 CY +297 -6 0 0 CY +298 -6 0 0 CY + +292 -5 0 0 CY +293 -5 0 0 CY +294 -5 0 0 CY +295 -5 0 0 CY +296 -5 0 0 CY +297 -5 0 0 CY +298 -5 0 0 CY +299 -5 0 0 CY +300 -5 0 0 CY +301 -5 0 0 CY +302 -5 0 0 CY + +291 -7 0 0 CY +292 -7 0 0 CY +293 -7 0 0 CY +294 -7 0 0 CY +295 -7 0 0 CY +296 -7 0 0 CY +297 -7 0 0 CY +298 -7 0 0 CY +299 -7 0 0 CY +300 -7 0 0 CY +301 -7 0 0 CY +302 -7 0 0 CY +303 -7 0 0 CY + +295 -8 0 0 CY +296 -8 0 0 CY +297 -8 0 0 CY +298 -8 0 0 CY +299 -8 0 0 CY +300 -8 0 0 CY + + +290 -6 0 0 OR +290 -5 0 0 OR +290 -4 0 0 OR +290 -3 0 0 OR +291 -3 0 0 OR + +218 -8 0 0 !examples/20row.qua +218 -7 0 0 !examples/20row.qua +218 -6 0 0 !examples/20row.qua +218 -5 0 0 !examples/20row.qua +218 -4 0 0 !examples/20row.qua +218 -3 0 0 !examples/20row.qua + +183 -7 0 0 !examples/20row.qua +183 -6 0 0 !examples/20row.qua +183 -5 0 0 !examples/20row.qua +183 -4 0 0 !examples/20row.qua +183 -3 0 0 !examples/20row.qua + +148 -6 0 0 !examples/20row.qua +148 -5 0 0 !examples/20row.qua +148 -4 0 0 !examples/20row.qua +148 -3 0 0 !examples/20row.qua + +113 -5 0 0 !examples/20row.qua +113 -4 0 0 !examples/20row.qua +113 -3 0 0 !examples/20row.qua + +78 -4 0 0 !examples/20row.qua +78 -3 0 0 !examples/20row.qua + +43 -3 0 0 !examples/20row.qua + +# ADD-8 +# Inputs: -17, -16 +# -17, -15 +# ... +# -17, -10 +# -17, -8 +# -17, -7 +# ... +# -17, -1 +# Outputs: 303, -10 +# 303, -9 +# ... +# 303, -3 +# Time: 2852
\ No newline at end of file diff --git a/examples/add8rect1.qua b/examples/add8rect1.qua new file mode 100644 index 0000000..8bac238 --- /dev/null +++ b/examples/add8rect1.qua @@ -0,0 +1,151 @@ +x y speedX speedY color +#-1 {:2} 0 0 OR +#-2 {:2} 0 0 OR +#-3 {:2} 0 0 OR +#-4 {:2} 0 0 OR +#-5 {:2} 0 0 OR +#-6 {:2} 0 0 OR +#-7 {:2} 0 0 OR + +#-10 {:2} 0 0 OR +#-11 {:2} 0 0 OR +#-12 {:2} 0 0 OR +#-13 {:2} 0 0 OR +#-14 {:2} 0 0 OR +#-15 {:2} 0 0 OR +#-16 {:2} 0 0 OR +-1 0 0 0 OR +-2 0 0 0 OR +-3 0 0 0 OR +-4 0 0 0 OR +-5 0 0 0 OR +-6 0 0 0 OR +-7 0 0 0 OR + +-10 0 0 0 OR +-11 0 0 0 OR +-12 0 0 0 OR +-13 0 0 0 OR +-14 0 0 0 OR +-15 0 0 0 OR +-16 0 0 0 OR + + +-1 1 0 0 OR +-2 1 0 0 OR +-3 1 0 0 OR +-4 1 0 0 OR +-5 1 0 0 OR +-6 1 0 0 OR +-7 1 0 0 OR + +-10 1 0 0 OR +-11 1 0 0 OR +-12 1 0 0 OR +-13 1 0 0 OR +-14 1 0 0 OR +-15 1 0 0 OR +-16 1 0 0 OR + + +-1 2 0 0 OR +-2 2 0 0 OR +-3 2 0 0 OR +-4 2 0 0 OR +-5 2 0 0 OR +-6 2 0 0 OR +-7 2 0 0 OR + +-10 2 0 0 OR +-11 2 0 0 OR +-12 2 0 0 OR +-13 2 0 0 OR +-14 2 0 0 OR +-15 2 0 0 OR +-16 2 0 0 OR + + +-1 3 0 0 OR +-2 3 0 0 OR +-3 3 0 0 OR +-4 3 0 0 OR +-5 3 0 0 OR +-6 3 0 0 OR +-7 3 0 0 OR + +-10 3 0 0 OR +-11 3 0 0 OR +-12 3 0 0 OR +-13 3 0 0 OR +-14 3 0 0 OR +-15 3 0 0 OR +-16 3 0 0 OR + + +-1 4 0 0 OR +-2 4 0 0 OR +-3 4 0 0 OR +-4 4 0 0 OR +-5 4 0 0 OR +-6 4 0 0 OR +-7 4 0 0 OR + +-10 4 0 0 OR +-11 4 0 0 OR +-12 4 0 0 OR +-13 4 0 0 OR +-14 4 0 0 OR +-15 4 0 0 OR +-16 4 0 0 OR + + +-1 5 0 0 OR +-2 5 0 0 OR +-3 5 0 0 OR +-4 5 0 0 OR +-5 5 0 0 OR +-6 5 0 0 OR +-7 5 0 0 OR + +-10 5 0 0 OR +-11 5 0 0 OR +-12 5 0 0 OR +-13 5 0 0 OR +-14 5 0 0 OR +-15 5 0 0 OR +-16 5 0 0 OR + + +-1 6 0 0 OR +-2 6 0 0 OR +-3 6 0 0 OR +-4 6 0 0 OR +-5 6 0 0 OR +-6 6 0 0 OR +-7 6 0 0 OR + +-10 6 0 0 OR +-11 6 0 0 OR +-12 6 0 0 OR +-13 6 0 0 OR +-14 6 0 0 OR +-15 6 0 0 OR +-16 6 0 0 OR + + +-1 7 0 0 OR +-2 7 0 0 OR +-3 7 0 0 OR +-4 7 0 0 OR +-5 7 0 0 OR +-6 7 0 0 OR +-7 7 0 0 OR + +-10 7 0 0 OR +-11 7 0 0 OR +-12 7 0 0 OR +-13 7 0 0 OR +-14 7 0 0 OR +-15 7 0 0 OR +-16 7 0 0 OR + diff --git a/examples/add8rect2.qua b/examples/add8rect2.qua new file mode 100644 index 0000000..23713f2 --- /dev/null +++ b/examples/add8rect2.qua @@ -0,0 +1,211 @@ +x y speedX speedY color +-2 0 0 0 OR +-3 0 0 0 OR +-4 0 0 0 OR +-5 0 0 0 OR +-6 0 0 0 OR +-7 0 0 0 OR + +-11 0 0 0 OR +-12 0 0 0 OR +-13 0 0 0 OR +-14 0 0 0 OR +-15 0 0 0 OR +-16 0 0 0 OR + + +-2 1 0 0 OR +-3 1 0 0 OR +-4 1 0 0 OR +-5 1 0 0 OR +-6 1 0 0 OR +-7 1 0 0 OR + +-11 1 0 0 OR +-12 1 0 0 OR +-13 1 0 0 OR +-14 1 0 0 OR +-15 1 0 0 OR +-16 1 0 0 OR + + +-2 2 0 0 OR +-3 2 0 0 OR +-4 2 0 0 OR +-5 2 0 0 OR +-6 2 0 0 OR +-7 2 0 0 OR + +-11 2 0 0 OR +-12 2 0 0 OR +-13 2 0 0 OR +-14 2 0 0 OR +-15 2 0 0 OR +-16 2 0 0 OR + + +-2 3 0 0 OR +-3 3 0 0 OR +-4 3 0 0 OR +-5 3 0 0 OR +-6 3 0 0 OR +-7 3 0 0 OR + +-11 3 0 0 OR +-12 3 0 0 OR +-13 3 0 0 OR +-14 3 0 0 OR +-15 3 0 0 OR +-16 3 0 0 OR + + +-2 4 0 0 OR +-3 4 0 0 OR +-4 4 0 0 OR +-5 4 0 0 OR +-6 4 0 0 OR +-7 4 0 0 OR + +-11 4 0 0 OR +-12 4 0 0 OR +-13 4 0 0 OR +-14 4 0 0 OR +-15 4 0 0 OR +-16 4 0 0 OR + + +-2 5 0 0 OR +-3 5 0 0 OR +-4 5 0 0 OR +-5 5 0 0 OR +-6 5 0 0 OR +-7 5 0 0 OR + +-11 5 0 0 OR +-12 5 0 0 OR +-13 5 0 0 OR +-14 5 0 0 OR +-15 5 0 0 OR +-16 5 0 0 OR + + +-2 6 0 0 OR +-3 6 0 0 OR +-4 6 0 0 OR +-5 6 0 0 OR +-6 6 0 0 OR +-7 6 0 0 OR + +-11 6 0 0 OR +-12 6 0 0 OR +-13 6 0 0 OR +-14 6 0 0 OR +-15 6 0 0 OR +-16 6 0 0 OR + + +-2 7 0 0 OR +-3 7 0 0 OR +-4 7 0 0 OR +-5 7 0 0 OR +-6 7 0 0 OR +-7 7 0 0 OR + +-11 7 0 0 OR +-12 7 0 0 OR +-13 7 0 0 OR +-14 7 0 0 OR +-15 7 0 0 OR +-16 7 0 0 OR + + +-2 8 0 0 OR +-3 8 0 0 OR +-4 8 0 0 OR +-5 8 0 0 OR +-6 8 0 0 OR +-7 8 0 0 OR + +-11 8 0 0 OR +-12 8 0 0 OR +-13 8 0 0 OR +-14 8 0 0 OR +-15 8 0 0 OR +-16 8 0 0 OR + + +-2 9 0 0 OR +-3 9 0 0 OR +-4 9 0 0 OR +-5 9 0 0 OR +-6 9 0 0 OR +-7 9 0 0 OR + +-11 9 0 0 OR +-12 9 0 0 OR +-13 9 0 0 OR +-14 9 0 0 OR +-15 9 0 0 OR +-16 9 0 0 OR + + +-2 10 0 0 OR +-3 10 0 0 OR +-4 10 0 0 OR +-5 10 0 0 OR +-6 10 0 0 OR +-7 10 0 0 OR + +-11 10 0 0 OR +-12 10 0 0 OR +-13 10 0 0 OR +-14 10 0 0 OR +-15 10 0 0 OR +-16 10 0 0 OR + + +-2 11 0 0 OR +-3 11 0 0 OR +-4 11 0 0 OR +-5 11 0 0 OR +-6 11 0 0 OR +-7 11 0 0 OR + +-11 11 0 0 OR +-12 11 0 0 OR +-13 11 0 0 OR +-14 11 0 0 OR +-15 11 0 0 OR +-16 11 0 0 OR + + +-2 14 0 0 OR +-3 14 0 0 OR +-4 14 0 0 OR +-5 14 0 0 OR +-6 14 0 0 OR +-7 14 0 0 OR + +-11 14 0 0 OR +-12 14 0 0 OR +-13 14 0 0 OR +-14 14 0 0 OR +-15 14 0 0 OR +-16 14 0 0 OR + + +-2 15 0 0 OR +-3 15 0 0 OR +-4 15 0 0 OR +-5 15 0 0 OR +-6 15 0 0 OR +-7 15 0 0 OR + +-11 15 0 0 OR +-12 15 0 0 OR +-13 15 0 0 OR +-14 15 0 0 OR +-15 15 0 0 OR +-16 15 0 0 OR + + diff --git a/examples/add8rect3.qua b/examples/add8rect3.qua new file mode 100644 index 0000000..1f6f9c0 --- /dev/null +++ b/examples/add8rect3.qua @@ -0,0 +1,261 @@ +x y speedX speedY color +-3 0 0 0 OR +-4 0 0 0 OR +-5 0 0 0 OR +-6 0 0 0 OR +-7 0 0 0 OR + +-12 0 0 0 OR +-13 0 0 0 OR +-14 0 0 0 OR +-15 0 0 0 OR +-16 0 0 0 OR + + +-3 1 0 0 OR +-4 1 0 0 OR +-5 1 0 0 OR +-6 1 0 0 OR +-7 1 0 0 OR + +-12 1 0 0 OR +-13 1 0 0 OR +-14 1 0 0 OR +-15 1 0 0 OR +-16 1 0 0 OR + + +-3 2 0 0 OR +-4 2 0 0 OR +-5 2 0 0 OR +-6 2 0 0 OR +-7 2 0 0 OR + +-12 2 0 0 OR +-13 2 0 0 OR +-14 2 0 0 OR +-15 2 0 0 OR +-16 2 0 0 OR + + +-3 3 0 0 OR +-4 3 0 0 OR +-5 3 0 0 OR +-6 3 0 0 OR +-7 3 0 0 OR + +-12 3 0 0 OR +-13 3 0 0 OR +-14 3 0 0 OR +-15 3 0 0 OR +-16 3 0 0 OR + + +-3 4 0 0 OR +-4 4 0 0 OR +-5 4 0 0 OR +-6 4 0 0 OR +-7 4 0 0 OR + +-12 4 0 0 OR +-13 4 0 0 OR +-14 4 0 0 OR +-15 4 0 0 OR +-16 4 0 0 OR + + +-3 5 0 0 OR +-4 5 0 0 OR +-5 5 0 0 OR +-6 5 0 0 OR +-7 5 0 0 OR + +-12 5 0 0 OR +-13 5 0 0 OR +-14 5 0 0 OR +-15 5 0 0 OR +-16 5 0 0 OR + + +-3 6 0 0 OR +-4 6 0 0 OR +-5 6 0 0 OR +-6 6 0 0 OR +-7 6 0 0 OR + +-12 6 0 0 OR +-13 6 0 0 OR +-14 6 0 0 OR +-15 6 0 0 OR +-16 6 0 0 OR + + +-3 7 0 0 OR +-4 7 0 0 OR +-5 7 0 0 OR +-6 7 0 0 OR +-7 7 0 0 OR + +-12 7 0 0 OR +-13 7 0 0 OR +-14 7 0 0 OR +-15 7 0 0 OR +-16 7 0 0 OR + + +-3 8 0 0 OR +-4 8 0 0 OR +-5 8 0 0 OR +-6 8 0 0 OR +-7 8 0 0 OR + +-12 8 0 0 OR +-13 8 0 0 OR +-14 8 0 0 OR +-15 8 0 0 OR +-16 8 0 0 OR + + +-3 9 0 0 OR +-4 9 0 0 OR +-5 9 0 0 OR +-6 9 0 0 OR +-7 9 0 0 OR + +-12 9 0 0 OR +-13 9 0 0 OR +-14 9 0 0 OR +-15 9 0 0 OR +-16 9 0 0 OR + + +-3 10 0 0 OR +-4 10 0 0 OR +-5 10 0 0 OR +-6 10 0 0 OR +-7 10 0 0 OR + +-12 10 0 0 OR +-13 10 0 0 OR +-14 10 0 0 OR +-15 10 0 0 OR +-16 10 0 0 OR + + +-3 11 0 0 OR +-4 11 0 0 OR +-5 11 0 0 OR +-6 11 0 0 OR +-7 11 0 0 OR + +-12 11 0 0 OR +-13 11 0 0 OR +-14 11 0 0 OR +-15 11 0 0 OR +-16 11 0 0 OR + + +-3 12 0 0 OR +-4 12 0 0 OR +-5 12 0 0 OR +-6 12 0 0 OR +-7 12 0 0 OR + +-12 12 0 0 OR +-13 12 0 0 OR +-14 12 0 0 OR +-15 12 0 0 OR +-16 12 0 0 OR + + +-3 13 0 0 OR +-4 13 0 0 OR +-5 13 0 0 OR +-6 13 0 0 OR +-7 13 0 0 OR + +-12 13 0 0 OR +-13 13 0 0 OR +-14 13 0 0 OR +-15 13 0 0 OR +-16 13 0 0 OR + + +-3 14 0 0 OR +-4 14 0 0 OR +-5 14 0 0 OR +-6 14 0 0 OR +-7 14 0 0 OR + +-12 14 0 0 OR +-13 14 0 0 OR +-14 14 0 0 OR +-15 14 0 0 OR +-16 14 0 0 OR + + +-3 15 0 0 OR +-4 15 0 0 OR +-5 15 0 0 OR +-6 15 0 0 OR +-7 15 0 0 OR + +-12 15 0 0 OR +-13 15 0 0 OR +-14 15 0 0 OR +-15 15 0 0 OR +-16 15 0 0 OR + + +-3 16 0 0 OR +-4 16 0 0 OR +-5 16 0 0 OR +-6 16 0 0 OR +-7 16 0 0 OR + +-12 16 0 0 OR +-13 16 0 0 OR +-14 16 0 0 OR +-15 16 0 0 OR +-16 16 0 0 OR + + +-3 17 0 0 OR +-4 17 0 0 OR +-5 17 0 0 OR +-6 17 0 0 OR +-7 17 0 0 OR + +-12 17 0 0 OR +-13 17 0 0 OR +-14 17 0 0 OR +-15 17 0 0 OR +-16 17 0 0 OR + + +-3 18 0 0 OR +-4 18 0 0 OR +-5 18 0 0 OR +-6 18 0 0 OR +-7 18 0 0 OR + +-12 18 0 0 OR +-13 18 0 0 OR +-14 18 0 0 OR +-15 18 0 0 OR +-16 18 0 0 OR + + +-3 19 0 0 OR +-4 19 0 0 OR +-5 19 0 0 OR +-6 19 0 0 OR +-7 19 0 0 OR + +-12 19 0 0 OR +-13 19 0 0 OR +-14 19 0 0 OR +-15 19 0 0 OR +-16 19 0 0 OR + + diff --git a/examples/add8rect4.qua b/examples/add8rect4.qua new file mode 100644 index 0000000..ca8c5b8 --- /dev/null +++ b/examples/add8rect4.qua @@ -0,0 +1,220 @@ +x y speedX speedY color +-4 0 0 0 OR +-5 0 0 0 OR +-6 0 0 0 OR +-7 0 0 0 OR + +-13 0 0 0 OR +-14 0 0 0 OR +-15 0 0 0 OR +-16 0 0 0 OR + + +-4 1 0 0 OR +-5 1 0 0 OR +-6 1 0 0 OR +-7 1 0 0 OR + +-13 1 0 0 OR +-14 1 0 0 OR +-15 1 0 0 OR +-16 1 0 0 OR + + +-4 2 0 0 OR +-5 2 0 0 OR +-6 2 0 0 OR +-7 2 0 0 OR + +-13 2 0 0 OR +-14 2 0 0 OR +-15 2 0 0 OR +-16 2 0 0 OR + + +-4 3 0 0 OR +-5 3 0 0 OR +-6 3 0 0 OR +-7 3 0 0 OR + +-13 3 0 0 OR +-14 3 0 0 OR +-15 3 0 0 OR +-16 3 0 0 OR + + +-4 4 0 0 OR +-5 4 0 0 OR +-6 4 0 0 OR +-7 4 0 0 OR + +-13 4 0 0 OR +-14 4 0 0 OR +-15 4 0 0 OR +-16 4 0 0 OR + + +-4 5 0 0 OR +-5 5 0 0 OR +-6 5 0 0 OR +-7 5 0 0 OR + +-13 5 0 0 OR +-14 5 0 0 OR +-15 5 0 0 OR +-16 5 0 0 OR + +-4 8 0 0 OR +-5 8 0 0 OR +-6 8 0 0 OR +-7 8 0 0 OR + +-13 8 0 0 OR +-14 8 0 0 OR +-15 8 0 0 OR +-16 8 0 0 OR + + +-4 9 0 0 OR +-5 9 0 0 OR +-6 9 0 0 OR +-7 9 0 0 OR + +-13 9 0 0 OR +-14 9 0 0 OR +-15 9 0 0 OR +-16 9 0 0 OR + + +-4 10 0 0 OR +-5 10 0 0 OR +-6 10 0 0 OR +-7 10 0 0 OR + +-13 10 0 0 OR +-14 10 0 0 OR +-15 10 0 0 OR +-16 10 0 0 OR + + +-4 11 0 0 OR +-5 11 0 0 OR +-6 11 0 0 OR +-7 11 0 0 OR + +-13 11 0 0 OR +-14 11 0 0 OR +-15 11 0 0 OR +-16 11 0 0 OR + + +-4 12 0 0 OR +-5 12 0 0 OR +-6 12 0 0 OR +-7 12 0 0 OR + +-13 12 0 0 OR +-14 12 0 0 OR +-15 12 0 0 OR +-16 12 0 0 OR + + +-4 13 0 0 OR +-5 13 0 0 OR +-6 13 0 0 OR +-7 13 0 0 OR + +-13 13 0 0 OR +-14 13 0 0 OR +-15 13 0 0 OR +-16 13 0 0 OR + + +-4 14 0 0 OR +-5 14 0 0 OR +-6 14 0 0 OR +-7 14 0 0 OR + +-13 14 0 0 OR +-14 14 0 0 OR +-15 14 0 0 OR +-16 14 0 0 OR + + +-4 15 0 0 OR +-5 15 0 0 OR +-6 15 0 0 OR +-7 15 0 0 OR + +-13 15 0 0 OR +-14 15 0 0 OR +-15 15 0 0 OR +-16 15 0 0 OR + + +-4 16 0 0 OR +-5 16 0 0 OR +-6 16 0 0 OR +-7 16 0 0 OR + +-13 16 0 0 OR +-14 16 0 0 OR +-15 16 0 0 OR +-16 16 0 0 OR + + +-4 17 0 0 OR +-5 17 0 0 OR +-6 17 0 0 OR +-7 17 0 0 OR + +-13 17 0 0 OR +-14 17 0 0 OR +-15 17 0 0 OR +-16 17 0 0 OR + + +-4 18 0 0 OR +-5 18 0 0 OR +-6 18 0 0 OR +-7 18 0 0 OR + +-13 18 0 0 OR +-14 18 0 0 OR +-15 18 0 0 OR +-16 18 0 0 OR + + +-4 19 0 0 OR +-5 19 0 0 OR +-6 19 0 0 OR +-7 19 0 0 OR + +-13 19 0 0 OR +-14 19 0 0 OR +-15 19 0 0 OR +-16 19 0 0 OR + + +-4 20 0 0 OR +-5 20 0 0 OR +-6 20 0 0 OR +-7 20 0 0 OR + +-13 20 0 0 OR +-14 20 0 0 OR +-15 20 0 0 OR +-16 20 0 0 OR + + +-4 21 0 0 OR +-5 21 0 0 OR +-6 21 0 0 OR +-7 21 0 0 OR + +-13 21 0 0 OR +-14 21 0 0 OR +-15 21 0 0 OR +-16 21 0 0 OR + + diff --git a/examples/add8rect5.qua b/examples/add8rect5.qua new file mode 100644 index 0000000..92999c4 --- /dev/null +++ b/examples/add8rect5.qua @@ -0,0 +1,180 @@ +x y speedX speedY color +-5 0 0 0 OR +-6 0 0 0 OR +-7 0 0 0 OR + +-14 0 0 0 OR +-15 0 0 0 OR +-16 0 0 0 OR + + +-5 1 0 0 OR +-6 1 0 0 OR +-7 1 0 0 OR + +-14 1 0 0 OR +-15 1 0 0 OR +-16 1 0 0 OR + + +-5 2 0 0 OR +-6 2 0 0 OR +-7 2 0 0 OR + +-14 2 0 0 OR +-15 2 0 0 OR +-16 2 0 0 OR + + +-5 3 0 0 OR +-6 3 0 0 OR +-7 3 0 0 OR + +-14 3 0 0 OR +-15 3 0 0 OR +-16 3 0 0 OR + + +-5 4 0 0 OR +-6 4 0 0 OR +-7 4 0 0 OR + +-14 4 0 0 OR +-15 4 0 0 OR +-16 4 0 0 OR + + +-5 5 0 0 OR +-6 5 0 0 OR +-7 5 0 0 OR + +-14 5 0 0 OR +-15 5 0 0 OR +-16 5 0 0 OR + + +-5 6 0 0 OR +-6 6 0 0 OR +-7 6 0 0 OR + +-14 6 0 0 OR +-15 6 0 0 OR +-16 6 0 0 OR + + +-5 7 0 0 OR +-6 7 0 0 OR +-7 7 0 0 OR + +-14 7 0 0 OR +-15 7 0 0 OR +-16 7 0 0 OR + + +-5 8 0 0 OR +-6 8 0 0 OR +-7 8 0 0 OR + +-14 8 0 0 OR +-15 8 0 0 OR +-16 8 0 0 OR + + +-5 9 0 0 OR +-6 9 0 0 OR +-7 9 0 0 OR + +-14 9 0 0 OR +-15 9 0 0 OR +-16 9 0 0 OR + + +-5 10 0 0 OR +-6 10 0 0 OR +-7 10 0 0 OR + +-14 10 0 0 OR +-15 10 0 0 OR +-16 10 0 0 OR + + +-5 11 0 0 OR +-6 11 0 0 OR +-7 11 0 0 OR + +-14 11 0 0 OR +-15 11 0 0 OR +-16 11 0 0 OR + + +-5 12 0 0 OR +-6 12 0 0 OR +-7 12 0 0 OR + +-14 12 0 0 OR +-15 12 0 0 OR +-16 12 0 0 OR + + +-5 13 0 0 OR +-6 13 0 0 OR +-7 13 0 0 OR + +-14 13 0 0 OR +-15 13 0 0 OR +-16 13 0 0 OR + + +-5 14 0 0 OR +-6 14 0 0 OR +-7 14 0 0 OR + +-14 14 0 0 OR +-15 14 0 0 OR +-16 14 0 0 OR + + +-5 15 0 0 OR +-6 15 0 0 OR +-7 15 0 0 OR + +-14 15 0 0 OR +-15 15 0 0 OR +-16 15 0 0 OR + + +-5 16 0 0 OR +-6 16 0 0 OR +-7 16 0 0 OR + +-14 16 0 0 OR +-15 16 0 0 OR +-16 16 0 0 OR + + +-5 17 0 0 OR +-6 17 0 0 OR +-7 17 0 0 OR + +-14 17 0 0 OR +-15 17 0 0 OR +-16 17 0 0 OR + + +-5 18 0 0 OR +-6 18 0 0 OR +-7 18 0 0 OR + +-14 18 0 0 OR +-15 18 0 0 OR +-16 18 0 0 OR + + +-5 19 0 0 OR +-6 19 0 0 OR +-7 19 0 0 OR + +-14 19 0 0 OR +-15 19 0 0 OR +-16 19 0 0 OR + diff --git a/examples/add8rect6.qua b/examples/add8rect6.qua new file mode 100644 index 0000000..acf27c5 --- /dev/null +++ b/examples/add8rect6.qua @@ -0,0 +1,121 @@ +x y speedX speedY color + 0 0 0 0 OR + 0 1 0 0 OR + 0 2 0 0 OR + 0 3 0 0 OR + + + 1 0 0 0 OR + 1 1 0 0 OR + 1 2 0 0 OR + 1 3 0 0 OR + + + 2 0 0 0 OR + 2 1 0 0 OR + 2 2 0 0 OR + 2 3 0 0 OR + + + 3 0 0 0 OR + 3 1 0 0 OR + 3 2 0 0 OR + 3 3 0 0 OR + + + 4 0 0 0 OR + 4 1 0 0 OR + 4 2 0 0 OR + 4 3 0 0 OR + + + 5 0 0 0 OR + 5 1 0 0 OR + 5 2 0 0 OR + 5 3 0 0 OR + + + 6 0 0 0 OR + 6 1 0 0 OR + 6 2 0 0 OR + 6 3 0 0 OR + + + 7 0 0 0 OR + 7 1 0 0 OR + 7 2 0 0 OR + 7 3 0 0 OR + + + 8 0 0 0 OR + 8 1 0 0 OR + 8 2 0 0 OR + 8 3 0 0 OR + + + 9 0 0 0 OR + 9 1 0 0 OR + 9 2 0 0 OR + 9 3 0 0 OR + + +10 0 0 0 OR +10 1 0 0 OR +10 2 0 0 OR +10 3 0 0 OR + + +11 0 0 0 OR +11 1 0 0 OR +11 2 0 0 OR +11 3 0 0 OR + + +12 0 0 0 OR +12 1 0 0 OR +12 2 0 0 OR +12 3 0 0 OR + + +13 0 0 0 OR +13 1 0 0 OR +13 2 0 0 OR +13 3 0 0 OR + + +14 0 0 0 OR +14 1 0 0 OR +14 2 0 0 OR +14 3 0 0 OR + + +15 0 0 0 OR +15 1 0 0 OR +15 2 0 0 OR +15 3 0 0 OR + + +16 0 0 0 OR +16 1 0 0 OR +16 2 0 0 OR +16 3 0 0 OR + + +17 0 0 0 OR +17 1 0 0 OR +17 2 0 0 OR +17 3 0 0 OR + + +18 0 0 0 OR +18 1 0 0 OR +18 2 0 0 OR +18 3 0 0 OR + + +19 0 0 0 OR +19 1 0 0 OR +19 2 0 0 OR +19 3 0 0 OR + + diff --git a/examples/add8rect7.qua b/examples/add8rect7.qua new file mode 100644 index 0000000..b7c6d21 --- /dev/null +++ b/examples/add8rect7.qua @@ -0,0 +1,81 @@ +x y speedX speedY color + 0 2 0 0 OR + 0 3 0 0 OR + + + 1 2 0 0 OR + 1 3 0 0 OR + + + 2 2 0 0 OR + 2 3 0 0 OR + + + 3 2 0 0 OR + 3 3 0 0 OR + + + 4 2 0 0 OR + 4 3 0 0 OR + + + 5 2 0 0 OR + 5 3 0 0 OR + + + 6 2 0 0 OR + 6 3 0 0 OR + + + 7 2 0 0 OR + 7 3 0 0 OR + + + 8 2 0 0 OR + 8 3 0 0 OR + + + 9 2 0 0 OR + 9 3 0 0 OR + + +10 2 0 0 OR +10 3 0 0 OR + + +11 2 0 0 OR +11 3 0 0 OR + + +12 2 0 0 OR +12 3 0 0 OR + + +13 2 0 0 OR +13 3 0 0 OR + + +14 2 0 0 OR +14 3 0 0 OR + + +15 2 0 0 OR +15 3 0 0 OR + + +16 2 0 0 OR +16 3 0 0 OR + + +17 2 0 0 OR +17 3 0 0 OR + + +18 2 0 0 OR +18 3 0 0 OR + + +19 2 0 0 OR +19 3 0 0 OR + + diff --git a/examples/add8test.qua b/examples/add8test.qua new file mode 100644 index 0000000..c440c3e --- /dev/null +++ b/examples/add8test.qua @@ -0,0 +1,20 @@ +x y speedX speedY color +50 30 1 0 GE #11001101 +50 31 1 0 GE +50 32 1 0 BL +50 33 1 0 BL +50 34 1 0 GE +50 35 1 0 GE +50 36 1 0 BL +50 37 1 0 GE + +50 39 1 0 BL #01011110 +50 40 1 0 GE +50 41 1 0 BL +50 42 1 0 GE +50 43 1 0 GE +50 44 1 0 GE +50 45 1 0 GE +50 46 1 0 BL +70 47 0 0 !examples/add8.qua +# 11001101 (205) + 01011110 (94) = 100101011 (299)
\ No newline at end of file diff --git a/examples/add8test2.qua b/examples/add8test2.qua new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/add8test2.qua @@ -0,0 +1 @@ + diff --git a/examples/and.qua b/examples/and.qua new file mode 100644 index 0000000..5bc9914 --- /dev/null +++ b/examples/and.qua @@ -0,0 +1,11 @@ +x y speedX speedY color +0 1 0 0 YE +1 1 0 0 GA +2 1 0 0 GA +2 0 0 0 GA +-1 0 0 0 GA +-1 3 0 0 !examples/not.qua +# AND - Input: 0, 0 speed 0, 1 +# 1, 0 speed 0, 1 +# Output: 0, 3 +# Time: 20
\ No newline at end of file diff --git a/examples/andtest.qua b/examples/andtest.qua new file mode 100644 index 0000000..e8e784c --- /dev/null +++ b/examples/andtest.qua @@ -0,0 +1,14 @@ +x y speedX speedY color +100 50 0 1 GE +101 50 0 1 GE +100 100 0 0 !examples/and.qua +120 50 0 1 GE +121 50 0 1 BL +120 100 0 0 !examples/and.qua +140 50 0 1 BL +141 50 0 1 GE +140 100 0 0 !examples/and.qua +160 50 0 1 BL +161 50 0 1 BL +160 100 0 0 !examples/and.qua + diff --git a/examples/full.qua b/examples/full.qua new file mode 100644 index 0000000..fb861f0 --- /dev/null +++ b/examples/full.qua @@ -0,0 +1,87 @@ +x y speedX speedY color +# Bring the third digit down slowly... +2 0 0 0 GA +6 0 0 0 PU +6 -1 0 0 RE +6 1 0 0 CY +6 2 0 0 CY +6 3 0 0 CY +6 4 0 0 CY +6 5 0 0 CY +6 6 0 0 CY +6 7 0 0 CY +6 8 0 0 CY +6 9 0 0 CY +6 10 0 0 CY +6 11 0 0 CY +6 12 0 0 CY +6 13 0 0 CY +6 14 0 0 CY +6 15 0 0 CY +6 16 0 0 CY +6 17 0 0 CY +6 18 0 0 CY +6 19 0 0 CY +6 20 0 0 CY +6 21 0 0 CY +6 22 0 0 CY +6 23 0 0 CY +6 24 0 0 CY +6 25 0 0 CY +6 26 0 0 CY +6 27 0 0 CY +6 28 0 0 CY +6 29 0 0 CY +6 30 0 0 CY +6 34 0 0 GA +16 34 0 0 GA +16 32 0 0 GA +0 32 0 0 GA +# Bring the carry of the first addition to the OR +-2 33 0 0 CY +-2 34 0 0 CY +-2 35 0 0 GA +10 35 0 0 GA +10 25 0 0 GA +9 25 0 0 GA +9 71 0 0 GA +10 71 0 0 GA +10 70 0 0 GA +-2 70 0 0 GA +9 70 0 0 CY +9 69 0 0 CY +9 68 0 0 CY +9 67 0 0 CY +9 66 0 0 CY +9 65 0 0 CY +9 64 0 0 CY +9 63 0 0 CY +9 62 0 0 CY +9 61 0 0 CY +9 60 0 0 CY +9 59 0 0 CY +9 58 0 0 CY +# While the first 2 digits are adding +0 5 0 0 !examples/half.qua +# Add the third digit with the sum of the first 2 +-1 41 0 0 !examples/half.qua # Outputs to -2/-3, 67 +# Bring sum of second addition to answer +-2 68 0 0 GA +7 68 0 0 GA +7 67 0 0 GA +6 67 0 0 GA +6 75 0 0 CY +6 78 0 0 GA +7 78 0 0 GA +7 77 0 0 GA +4 77 0 0 GA +# OR carries +-3 72 0 0 !examples/or.qua + +# FULL-ADDER +# Inputs: 0, 0 +# 1, 0 +# 2, 0 +# Outputs: 3, 77 +# 4, 77 +# Time: 224
\ No newline at end of file diff --git a/examples/fulltest.qua b/examples/fulltest.qua new file mode 100644 index 0000000..2e5964b --- /dev/null +++ b/examples/fulltest.qua @@ -0,0 +1,34 @@ +x y speedX speedY color +20 1 0 1 GE +21 1 0 1 GE +22 1 0 1 GE +20 30 0 0 !examples/full.qua +55 1 0 1 GE +56 1 0 1 GE +57 1 0 1 BL +55 30 0 0 !examples/full.qua +90 1 0 1 GE +91 1 0 1 BL +92 1 0 1 GE +90 30 0 0 !examples/full.qua +125 1 0 1 GE +126 1 0 1 BL +127 1 0 1 BL +125 30 0 0 !examples/full.qua + +160 1 0 1 BL +161 1 0 1 GE +162 1 0 1 GE +160 30 0 0 !examples/full.qua +195 1 0 1 BL +196 1 0 1 GE +197 1 0 1 BL +195 30 0 0 !examples/full.qua +230 1 0 1 BL +231 1 0 1 BL +232 1 0 1 GE +230 30 0 0 !examples/full.qua +265 1 0 1 BL +266 1 0 1 BL +267 1 0 1 BL +265 30 0 0 !examples/full.qua diff --git a/examples/half.qua b/examples/half.qua new file mode 100644 index 0000000..eb23a6b --- /dev/null +++ b/examples/half.qua @@ -0,0 +1,43 @@ +x y speedX speedY color +# Re-route inputs +1 0 0 0 GA +0 1 0 0 GA +1 1 0 0 GA +# 2 duplicators create copies of 2 bits +-1 0 0 0 PU +2 0 0 0 PU +# What happens to the bottom copy (XOR) +-1 2 0 0 GA +2 3 0 0 GA +3 2 0 0 GA +4 3 0 0 GA +3 -1 0 0 GA +4 -2 0 0 GA +-3 -1 0 0 GA +-4 -2 0 0 GA +-4 3 0 0 !examples/xor.qua # Outputs to 2, 15 +# What happens to the top copy (AND) +-1 -3 0 0 GA +2 -4 0 0 GA +-9 -3 0 0 GA +-10 -4 0 0 GA +-9 -2 0 0 CY +-9 -1 0 0 CY +-10 15 0 0 !examples/and.qua # Outputs to -10, 18 +-10 22 0 0 GA +-5 22 0 0 PU +-5 21 0 0 RE +# Delay the top copy (so lines up with the bottom one) +-5 26 0 0 GA +1 26 0 0 GA +1 22 0 0 GA +-2 22 0 0 GA +-2 23 0 0 CY +-2 24 0 0 CY +-2 26 0 0 CY +# A HALF-ADDER B = (A AND B, A XOR B) +# Inputs: 0, 0 +# 1, 0 +# Outputs: -2, 26 +# -1, 26 +# Time: 90
\ No newline at end of file diff --git a/examples/halftest.qua b/examples/halftest.qua new file mode 100644 index 0000000..aad797e --- /dev/null +++ b/examples/halftest.qua @@ -0,0 +1,16 @@ +x y speedX speedY color +100 50 0 1 GE +101 50 0 1 GE +100 100 0 0 !examples/half.qua +130 50 0 1 GE +131 50 0 1 BL +130 100 0 0 !examples/half.qua +160 50 0 1 BL +161 50 0 1 GE +160 100 0 0 !examples/half.qua +190 50 0 1 BL +191 50 0 1 BL +190 100 0 0 !examples/half.qua + + + diff --git a/examples/not.qua b/examples/not.qua new file mode 100644 index 0000000..965b34a --- /dev/null +++ b/examples/not.qua @@ -0,0 +1,12 @@ +x y speedX speedY color +0 0 0 0 PU +-1 0 0 0 GA +2 0 0 0 YE +-1 1 0 0 GA +3 1 0 0 GA +3 -1 0 0 GA +1 -1 0 0 GA + +# NOT - Input: 0, 0 speed 0, 1 +# Output: 1, 0 speed 0, 1 +# Time: 11
\ No newline at end of file diff --git a/examples/nottest.qua b/examples/nottest.qua new file mode 100644 index 0000000..c7b8854 --- /dev/null +++ b/examples/nottest.qua @@ -0,0 +1,26 @@ +x y speedX speedY color +20 16 0 1 GE +20 20 0 0 PU +20 10 0 0 GA +30 10 0 0 GA +30 20 0 0 GA +10 20 0 0 GA +10 30 0 0 GA +# ---- BLUE GENERATOR ---- +230 26 0 1 BL +230 30 0 0 PU +230 20 0 0 GA +240 20 0 0 GA +240 30 0 0 GA +# ---- DOWNIFIER ---- (takes qualums from both sides, makes them go downwards) +120 30 0 0 PU +120 28 0 0 RE +# ---- NOT ---- +120 120 0 0 !examples/not.qua +#120 120 0 0 PU +#118 120 0 0 GA +#123 120 0 0 YE +#118 122 0 0 GA +#124 122 0 0 GA +#124 118 0 0 GA +#122 118 0 0 GA
\ No newline at end of file diff --git a/examples/or.qua b/examples/or.qua new file mode 100644 index 0000000..162fe04 --- /dev/null +++ b/examples/or.qua @@ -0,0 +1,17 @@ +x y speedX speedY color +0 2 0 0 !examples/not.qua +1 0 0 0 GA +6 0 0 0 GA +6 -1 0 0 GA +5 -1 0 0 GA +5 2 0 0 !examples/not.qua +1 4 0 0 GA +7 4 0 0 YE +# OR +# Inputs: 0, 0 +# 1, 0 +# Output: 6, 4 +# Time: 23 +# Notes: +# The left input can come in a while before the right input, but not +# vice versa.
\ No newline at end of file diff --git a/examples/orangetest.qua b/examples/orangetest.qua new file mode 100644 index 0000000..f8ef442 --- /dev/null +++ b/examples/orangetest.qua @@ -0,0 +1,4 @@ +x y speedX speedY color +50 0 0 1 GE +50 50 0 0 GA +100 50 0 0 OR diff --git a/examples/ortest.qua b/examples/ortest.qua new file mode 100644 index 0000000..be08d4e --- /dev/null +++ b/examples/ortest.qua @@ -0,0 +1,15 @@ +x y speedX speedY color +100 50 0 1 GE +101 50 0 1 GE +100 100 0 0 !examples/or.qua +120 50 0 1 GE +121 50 0 1 BL +120 100 0 0 !examples/or.qua +140 50 0 1 BL +141 50 0 1 GE +140 100 0 0 !examples/or.qua +160 50 0 1 BL +161 50 0 1 BL +160 100 0 0 !examples/or.qua + + diff --git a/examples/xor.qua b/examples/xor.qua new file mode 100644 index 0000000..50eb731 --- /dev/null +++ b/examples/xor.qua @@ -0,0 +1,31 @@ +x y speedX speedY color +# Re-route inputs +1 0 0 0 GA +0 1 0 0 GA +1 1 0 0 GA +# 2 duplicators create copies of 2 bits +-1 0 0 0 PU +2 0 0 0 PU +# What is done with the bottom copy (NAND) +-1 2 0 0 GA +2 3 0 0 YE +8 2 0 0 GA +8 1 0 0 GA +6 1 0 0 GA +6 11 0 0 GA +8 11 0 0 GA +8 10 0 0 GA +4 10 0 0 GA +# What is done with the top copy (OR) +-1 -1 0 0 GA +2 -2 0 0 GA +-2 -1 0 0 GA +-3 -2 0 0 GA +-3 5 0 0 !examples/or.qua +# The combining (AND) +3 12 0 0 !examples/and.qua +# A XOR B = (A OR B) AND (A NAND B) +# Inputs: 0, 0 +# 1, 0 +# Output: 6, 12 +# Time: 54 diff --git a/examples/xortest.qua b/examples/xortest.qua new file mode 100644 index 0000000..449145b --- /dev/null +++ b/examples/xortest.qua @@ -0,0 +1,16 @@ +x y speedX speedY color +100 50 0 1 GE +101 50 0 1 GE +100 100 0 0 !examples/xor.qua +120 50 0 1 GE +121 50 0 1 BL +120 100 0 0 !examples/xor.qua +140 50 0 1 BL +141 50 0 1 GE +140 100 0 0 !examples/xor.qua +160 50 0 1 BL +161 50 0 1 BL +160 100 0 0 !examples/xor.qua + + + Binary files differdiff --git a/src/Color.cpp b/src/Color.cpp new file mode 100644 index 0000000..b612315 --- /dev/null +++ b/src/Color.cpp @@ -0,0 +1,32 @@ + +#include "Color.h" +#include <cstdio> +#include <cstdlib> +#include <cstring> + +unsigned Colors::colors[] = {0x888888, 0xFF0000, 0x0000FF, 0x00FF00, + 0x660099, 0xFFFF00, 0x00FFFF, 0xFF8800}; +char* Colors::color_names[] = {"GA", "RE", "BL", "GE", "PU", "YE", "CY", "OR", NULL}; + +Color Colors::read_color(char* s) +{ + for (int i = 0; Colors::color_names[i]; i++) + if (!strcmp(Colors::color_names[i], s)) + return (Color) i; + fprintf(stderr, "Error - Color not found: %s\n", s); + exit(1); +} + +unsigned Colors::get_color(Color c) +{ + // Color to 0xAABBCC format + return colors[(int)c]; +} + +void Colors::to_rgb(Color c, unsigned char* r, unsigned char* g, unsigned char* b) +{ + unsigned c_int = get_color(c); + *r = c_int >> 16; + *g = (c_int >> 8) % 256; + *b = c_int % 256; +}
\ No newline at end of file diff --git a/src/Color.h b/src/Color.h new file mode 100644 index 0000000..0f67023 --- /dev/null +++ b/src/Color.h @@ -0,0 +1,18 @@ + +#ifndef COLOR_H +#define COLOR_H + +enum class Color { GRAY, RED, BLUE, GREEN, PURPLE, YELLOW, CYAN, ORANGE }; + +class Colors { +public: + static Color read_color(char* s); + static void to_rgb(Color c, unsigned char* r, unsigned char* g, unsigned char* b); +private: + static unsigned get_color(Color c); + static unsigned colors[]; + static char* color_names[]; +}; + +#endif /* COLOR_H */ + diff --git a/src/Qualum.cpp b/src/Qualum.cpp new file mode 100644 index 0000000..02327e8 --- /dev/null +++ b/src/Qualum.cpp @@ -0,0 +1,280 @@ +#include "Qualum.h" +#include "Rendering.h" +#include "Color.h" +#include <SDL.h> +#include <vector> +#include <iostream> + +int Qualum::locations[Rendering::GRID_HEIGHT][Rendering::GRID_WIDTH]; +std::vector<Qualum*> Qualum::qualums; +int Qualum::iterations = 0; + +void Qualum::initialize() +{ + for (int i = 0; i < Rendering::GRID_HEIGHT; i++) + { + for (int j = 0; j < Rendering::GRID_WIDTH; j++) + { + locations[i][j] = -1; + } + } +} + +Qualum::Qualum(int x_, int y_, Color color_, int sx, int sy): x(x_), y(y_), color(color_), speedx(sx), speedy(sy) { + index = Qualum::qualums.size(); + can_collide = true; + delayed = 0; + Qualum::qualums.push_back(this); +} + +Qualum* Qualum::create_qualum(int x, int y, Color color, int sx, int sy) +{ + // printf("Position: %d,%d Color: %d Speed: %d,%d\n", x, y, (int)color, sx, sy); + Qualum* newq = (Qualum*)calloc(1,sizeof(Qualum)); + newq = new Qualum(x, y, color, sx, sy); + return newq; +} + +Qualum::~Qualum() +{ + if (index >= 0 && index < Qualum::qualums.size()) + Qualum::qualums[index] = NULL; + if (!(x < 0 || y < 0 || x >= Rendering::GRID_WIDTH || y >= Rendering::GRID_HEIGHT) + && Qualum::locations[y][x] == index) + Qualum::locations[y][x] = -1; +} + +void Qualum::destroy() +{ + // Destroy this qualum + /*printf("%p; ", Qualum::qualums[index]); + printf("Destroying "); + debug(); + printf("\n"); + */ + delete this; +} + +void Qualum::render(SDL_Renderer* renderer) +{ + unsigned char r; + unsigned char g; + unsigned char b; + Colors::to_rgb(color, &r, &g, &b); + SDL_SetRenderDrawColor(renderer, r, g, b, 255); + SDL_Rect rect = {x*Rendering::RENDER_SCALE, y*Rendering::RENDER_SCALE, + Rendering::RENDER_SCALE, Rendering::RENDER_SCALE}; + SDL_RenderFillRect(renderer, &rect); +} + +void Qualum::render_all(SDL_Renderer* renderer) +{ + for (Qualum* qualum: qualums) + { + if (qualum != NULL) + qualum->render(renderer); + } +} + +void Qualum::two_perpendiculars(int speedx, int speedy, int* speedx1, int* speedy1, int* speedx2, int* speedy2) +{ + // [speedx1 speedy1] is [speedx speedy] turned 90d left, and [speedx2 speedy2] is it turned 90d right + if (speedx1 != NULL && speedy1 != NULL) + { + *speedx1 = speedy; + *speedy1 = -speedx; + } + if (speedx2 != NULL && speedy2 != NULL) + { + *speedx2 = -speedy; + *speedy2 = speedx; + } +} + +void Qualum::debug() +{ + printf("(%d: %p) Color: %d; Position: %d,%d; Speed: %d,%d", index, Qualum::qualums[index], (int)color, x, y, speedx, speedy); +} + +void Qualum::collide_with(Qualum* q) +{ + /* + printf("Collision: "); + debug(); + printf(" and "); + q->debug(); + printf("\n"); + */ + if (!can_collide || !q->can_collide) + { + return; + } + if (q->color == Color::RED && color == Color::RED) // Destroy + { + destroy(); + q->destroy(); + return; + } + if (color == Color::RED) + { + q->destroy(); + return; + } + if (q->color == Color::RED) + { + q->collide_with(this); + return; + } + + if (color == Color::CYAN) + { + q->delayed = 1; + q->can_collide = false; + return; + } + if (q->color == Color::CYAN) + { + q->collide_with(this); + return; + } + if (color == Color::ORANGE) + { + q->delayed = 16; + q->can_collide = false; + return; + } + if (q->color == Color::ORANGE) + { + q->collide_with(this); + return; + } + + if (color == Color::GRAY) // Turn + { + Qualum::two_perpendiculars(q->speedx, q->speedy, &q->speedx, &q->speedy, NULL, NULL); + if (q->color == Color::GRAY) + Qualum::two_perpendiculars(speedx, speedy, &speedx, &speedy, NULL, NULL); + return; + } + if (q->color == Color::GRAY) + { + q->collide_with(this); + return; + } + + if ((color == Color::GREEN || color == Color::BLUE) + && (q->color == Color::GREEN || q->color == Color::BLUE)) // NAND - Green=True, Blue=False + { + Color out = !((color == Color::GREEN) && (q->color == Color::GREEN)) ? + Color::GREEN : Color::BLUE; + Qualum::create_qualum(x, y, out, speedx + q->speedx, speedy + q->speedy); + destroy(); + q->destroy(); + return; + } + + if (color == Color::PURPLE && q->color == Color::PURPLE) + { + destroy(); + q->destroy(); + return; + } + if (color == Color::PURPLE) + { + Qualum* newq1 = Qualum::create_qualum(x, y, q->color, 0, 0); + Qualum* newq2 = Qualum::create_qualum(x, y, q->color, 0, 0); + Qualum::two_perpendiculars(q->speedx, q->speedy, &newq1->speedx, &newq1->speedy, &newq2->speedx, &newq2->speedy); + q->destroy(); + return; + } + if (q->color == Color::PURPLE) + { + q->collide_with(this); + return; + } + + if (color == Color::YELLOW) // Stop + { + x -= speedx; // Reverse any movement + y -= speedy; + + q->x -= q->speedx; + q->y -= q->speedy; + + q->speedx = 0; + q->speedy = 0; + + speedx = 0; + speedy = 0; + return; + } + + if (q->color == Color::YELLOW) + { + q->collide_with(this); + return; + } +} + +void Qualum::update() +{ + /* + printf("Updating "); + debug(); + printf("\n"); + */ + if (x < 0 || y < 0 || x >= Rendering::GRID_WIDTH || y >= Rendering::GRID_HEIGHT) + { + destroy(); + return; + } + if (Qualum::locations[y][x] == index) + Qualum::locations[y][x] = -1; + if (delayed) + { + delayed--; + } + else + { + x += speedx; + y += speedy; + if (!can_collide) + { + can_collide = true; + } + } + if (x < 0 || y < 0 || x >= Rendering::GRID_WIDTH || y >= Rendering::GRID_HEIGHT) + { + destroy(); + return; + } + + if (Qualum::locations[y][x] == -1) + { + Qualum::locations[y][x] = index; + } + else + { + collide_with(Qualum::qualums[Qualum::locations[y][x]]); + } +} + +void Qualum::update_all(bool should_update) +{ + /*// Ideally, this code should not be necessary: + for (int y = 0; y < Rendering::GRID_HEIGHT; y++) + for (int x = 0; x < Rendering::GRID_WIDTH; x++) + Qualum::locations[y][x] = -1; + */ + if (!should_update) + return; + Qualum::iterations++; + int size = qualums.size(); + for (int i = 0; i < size; i++) + { + if (qualums[i] != nullptr) + { + qualums[i]->update(); + } + } +}
\ No newline at end of file diff --git a/src/Qualum.h b/src/Qualum.h new file mode 100644 index 0000000..49a92b2 --- /dev/null +++ b/src/Qualum.h @@ -0,0 +1,37 @@ +#ifndef QUALUM_H +#define QUALUM_H + +#include <vector> +#include <SDL.h> +#include "Color.h" +#include "Rendering.h" + +class Qualum { +public: + Qualum(int x, int y, Color color, int sx, int sy); + ~Qualum(); + static Qualum* create_qualum(int x, int y, Color color, int sx, int sy); + void render(SDL_Renderer* renderer); + void update(); + static std::vector<Qualum*> qualums; + static void render_all(SDL_Renderer* renderer); + static void update_all(bool should_update); + static void initialize(); + static int iterations; +private: + static int locations[Rendering::GRID_HEIGHT][Rendering::GRID_WIDTH]; + static void two_perpendiculars(int speedx, int speedy, int* speedx1, int* speedy1, int* speedx2, int* speedy2); + static void combine_speeds(int speedx1, int speedy1, int speedx2, int speedy2, int* speedx, int* speedy); + void collide_with(Qualum* q); + void debug(); + void destroy(); + int x, y, index; + int speedx, speedy; + int delayed; + bool can_collide; + Color color; + +}; + +#endif /* QUALUM_H */ + diff --git a/src/Rendering.cpp b/src/Rendering.cpp new file mode 100644 index 0000000..542c679 --- /dev/null +++ b/src/Rendering.cpp @@ -0,0 +1,5 @@ +#include "Rendering.h" + +int Rendering::RENDER_SCALE = 3; +int Rendering::WIDTH = GRID_WIDTH * RENDER_SCALE; +int Rendering::HEIGHT = GRID_HEIGHT * RENDER_SCALE; diff --git a/src/Rendering.h b/src/Rendering.h new file mode 100644 index 0000000..fcc147b --- /dev/null +++ b/src/Rendering.h @@ -0,0 +1,16 @@ +#ifndef RENDERING_H +#define RENDERING_H + +class Rendering { +public: + static int RENDER_SCALE; + static const int GRID_WIDTH = 400; + static const int GRID_HEIGHT = 300; + static int WIDTH; + static int HEIGHT; +private: + +}; + +#endif /* RENDERING_H */ + diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..d96441f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,124 @@ +#include <iostream> +#include <vector> + +#include "SDL.h" +#include "Qualum.h" +#include "Rendering.h" +#include "Color.h" + +SDL_Window* window; + +float TIME_SCALE = 4.0f; + +void quit() +{ + SDL_DestroyWindow(window); + SDL_Quit(); +} + +void read_file(char* filename, int x, int y, int speedx, int speedy) +{ + // Create the qualums from the given file + // Increasing their positions by (x,y) and their speeds by (speedx, speedy) + FILE* input_file = fopen(filename, "r"); // Skip first line + if (!input_file) + { + fprintf(stderr, "File not found: %s\n", filename); + exit(1); + } + char* buffer = (char*)malloc(4096); + fgets(buffer, 4096, input_file); + + int xrel, yrel, speedxrel, speedyrel; // Read input file + char* color_str = (char*) malloc(4096); + char* include_filename = (char*) malloc(4096); // File name for includes + + while (fgets(buffer, 4096, input_file)) + { + int i; + for (i = 0; i < strlen(buffer); i++) + if (buffer[i] == '#') + break; + buffer[i] = 0; + if (sscanf(buffer, "%d %d %d %d %s", &xrel, &yrel, &speedxrel, &speedyrel, color_str) > 0) + { + if (color_str[0] == '!') // Include + { + int c; + for (c = 0; color_str[c+1]; c++) // Remove ! + include_filename[c] = color_str[c+1]; + include_filename[c] = 0; + read_file(include_filename, x + xrel, y + yrel, speedx + speedxrel, speedy + speedyrel); + } + else // Color + { + Color color = Colors::read_color(color_str); + Qualum::create_qualum(x + xrel, y + yrel, color, speedx + speedxrel, speedy + speedyrel); + } + } + } +} + +int main(int argc, char** argv) +{ + if (argc < 2) + { + fprintf(stderr, "Error: No input file provided.\n"); + return 1; + } + + Qualum::initialize(); + window = SDL_CreateWindow("Qualums", SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, Rendering::WIDTH, Rendering::HEIGHT, + SDL_WINDOW_SHOWN); + SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + + SDL_Event event; + bool will_quit = false; + + read_file(argv[1], 0, 0, 0, 0); + + int i = 0, last_printed = -1; + while (!will_quit) + { + i++; + if (Qualum::iterations != last_printed) + { + printf("%d\n", Qualum::iterations); + last_printed = Qualum::iterations; + } + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + SDL_RenderClear(renderer); + Qualum::update_all(i % ((int)(300/TIME_SCALE)) == 0); + Qualum::render_all(renderer); + SDL_RenderPresent(renderer); + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + will_quit = true; + break; + case SDL_KEYDOWN: + if (event.key.keysym.sym >= SDLK_0 && event.key.keysym.sym <= SDLK_9) + { + TIME_SCALE = (float)(event.key.keysym.sym - SDLK_0); + break; + } + switch (event.key.keysym.sym) + { + case SDLK_SPACE: + Qualum::update_all(true); + break; + case SDLK_ESCAPE: + will_quit = true; + break; + } + break; + } + } + } + + return 0; +} + |