This commit is contained in:
davidovski 2021-07-18 01:00:19 +01:00
commit 25426b2fa5
6 changed files with 173 additions and 0 deletions

38
CMakeLists.txt Normal file
View File

@ -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()

24
README.md Normal file
View File

@ -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

BIN
assets-fx/example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -0,0 +1,3 @@
example.png:
type: bopti-image
name: img_example

BIN
assets-fx/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

108
src/main.c Normal file
View File

@ -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;
}