diff options
-rw-r--r-- | CMakeLists.txt | 38 | ||||
-rw-r--r-- | README.md | 24 | ||||
-rw-r--r-- | assets-fx/example.png | bin | 0 -> 3569 bytes | |||
-rw-r--r-- | assets-fx/fxconv-metadata.txt | 3 | ||||
-rw-r--r-- | assets-fx/icon.png | bin | 0 -> 9980 bytes | |||
-rw-r--r-- | src/main.c | 108 |
6 files changed, 173 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e6b6273 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +# Configure with [fxsdk build-fx] or [fxsdk build-cg], which provide the +# toolchain file and module path of the fxSDK + +cmake_minimum_required(VERSION 3.15) +project(fractals) + +include(GenerateG1A) +include(GenerateG3A) +include(Fxconv) +find_package(Gint 2.1 REQUIRED) + +set(SOURCES + src/main.c + # ... +) +# Shared assets, fx-9860G-only assets and fx-CG-50-only assets +set(ASSETS + # ... +) +set(ASSETS_fx + assets-fx/example.png + # ... +) +set(ASSETS_cg + assets-cg/example.png + # ... +) + +fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA) + +add_executable(fractals ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}}) +target_compile_options(fractals PRIVATE -Wall -Wextra -Os) +target_link_libraries(fractals Gint::Gint) + +if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) + generate_g1a(TARGET fractals OUTPUT "fractals.g1a" + NAME "fractals" ICON assets-fx/icon.png) +endif() diff --git a/README.md b/README.md new file mode 100644 index 0000000..b6f8c1c --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Mandelbrot Casio + +An attempt at rendering the mandelbrot set fractal using [gint](https://gitea.planet-casio.com/Lephenixnoir/gint) for the fx series casio calculators. + +At the moment I am using a (probably) very inefficient algorithm for calcualting the mandelbrot set, so if you happen to know how to optimise this, feel free to! + +I would advise overclocking your calculator using a tool such as [ftune](http://pm.matrix.jp/ftune2e.html) to help with performance. + +## Controls + +- + zoom in +- - zoom out +- ↑ pan up +- ↓ pan down +- ← pan left +- → pan right + +## Building + +I would reccomend using [fxsdk](https://gitea.planet-casio.com/Lephenixnoir/fxsdk) to build this: + +`fxsdk build-fx` + +inside the project directory diff --git a/assets-fx/example.png b/assets-fx/example.png Binary files differnew file mode 100644 index 0000000..b26ba9a --- /dev/null +++ b/assets-fx/example.png diff --git a/assets-fx/fxconv-metadata.txt b/assets-fx/fxconv-metadata.txt new file mode 100644 index 0000000..d435d5f --- /dev/null +++ b/assets-fx/fxconv-metadata.txt @@ -0,0 +1,3 @@ +example.png: + type: bopti-image + name: img_example diff --git a/assets-fx/icon.png b/assets-fx/icon.png Binary files differnew file mode 100644 index 0000000..5b3e5ad --- /dev/null +++ b/assets-fx/icon.png diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..fd0f84e --- /dev/null +++ b/src/main.c @@ -0,0 +1,108 @@ +// fractals add-in by davidovski +// Copyright (C) 2021 davidovski +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. +#include <gint/gint.h> +#include <gint/display.h> +#include <gint/keyboard.h> +#include <gint/keycodes.h> + +typedef struct vec2 { + float x; + float y; +} vec2; + + +vec2 offset = {0, 0}; +vec2 poi = {1.5f, 0.5f}; + + +vec2 screen = {128, 64}; + +float zoom = 2.0f; +float max = 40.0f; + +vec2 add(vec2 a, vec2 b) { + vec2 r = {a.x + b.x, a.y + b.y}; + return r; +} + +double dot(vec2 a, vec2 b) { + return a.x*b.x + a.y+b.y; +} + +vec2 compsquare(vec2 z) { + float temp = z.x; + z.x = z.x*z.x - z.y*z.y; + z.y = 2.0*temp*z.y; + return z; +} + +bool mandelbrot(vec2 point) { + vec2 z = {0, 0}; + for (float iters = 0.0f; iters < max; ++iters) { + vec2 sq = compsquare(z); + z.x = sq.x + point.x; + z.y = sq.y + point.y; + z.x = sq.x + point.x; + + if (dot(z, z) > 4.0) return false; + } + return true; +} + +int main(void) { + gint_setrestart(1); + while (true) { + getkey(); + dclear(C_WHITE); + for (float x = 0; x < 128; x++) { + for (float y = 0; y < 64; y++) { + vec2 point = {x / screen.x, y / screen.y}; + point.x *= screen.x / screen.y; + + point.x -= poi.x; + point.y -= poi.y; + + point.x *= zoom; + point.y *= zoom; + + point.x -= offset.x; + point.y -= offset.y; + + if (mandelbrot(point)) { + dpixel(x , y, C_BLACK); + } + dupdate(); + } + } + + drect(1, 1, 3, 3, C_BLACK); + dupdate(); + + getkey(); + + if (keydown(KEY_ADD)) zoom -= zoom * 0.2f; + if (keydown(KEY_SUB)) zoom += zoom * 0.2f; + + if (keydown(KEY_UP)) offset.y -= zoom * 0.1f; + if (keydown(KEY_DOWN)) offset.y += zoom * 0.1f; + if (keydown(KEY_RIGHT)) offset.x -= zoom * 0.1f; + if (keydown(KEY_LEFT)) offset.x += zoom * 0.1f; + + if (keydown(KEY_EXIT)) gint_osmenu(); + + } + return 0; +} |