Maddie Busig 8a05e20c33 Fix rotations and add second token value
Rotations only took cosine of the angle, but this is not enough to
determine all possible angles. create_rotation now takes sin of the
angle too. Modified tokens to have a second value to accomodate this
change
2025-05-06 23:55:50 -07:00

86 lines
2.5 KiB
C++

#include <cmath>
#include <tonc.h>
#include <mtl/log.hpp>
#include <etl/vector.h>
#include <mtl/exception.hpp>
#include "fractal.hpp"
using namespace mtl;
using namespace fractal;
int main(void) {
REG_DISPCNT = DCNT_MODE3 | DCNT_BG2;
log::debug << "Hello world!" << mtl::endl;
constexpr float cos_PI_2 = std::cos(M_PI_2);
constexpr float cos_PI_4 = std::cos(M_PI_4);
constexpr float sin_PI_2 = std::sin(M_PI_2);
constexpr float sin_PI_4 = std::sin(M_PI_4);
fixed cos_PI_2_fx = cos_PI_2;
fixed cos_PI_4_fx = cos_PI_4;
fixed sin_PI_2_fx = sin_PI_2;
fixed sin_PI_4_fx = sin_PI_4;
ruleset_t rules;
try {
fixed branch_angle = M_PI_4;
token_id_t walk_petal_length = rules.add_token(token_type_e::walk, 8);
token_id_t walk_petal_side = rules.add_token(token_type_e::walk, 2);
token_id_t rotate_axiom = rules.add_token(token_type_e::rotate, cos_PI_2_fx, sin_PI_2_fx);
token_id_t rotate_petal = rules.add_token(token_type_e::rotate, cos_PI_2_fx, -sin_PI_2_fx);
token_id_t rotate_branchr = rules.add_token(token_type_e::rotate, cos_PI_4_fx, -sin_PI_4_fx);
token_id_t rotate_branchl = rules.add_token(token_type_e::rotate, cos_PI_2_fx, sin_PI_2_fx);
token_id_t branch = rules.add_token(token_type_e::empty);
token_id_t petal = rules.add_token(token_type_e::empty);
token_id_t mark = rules.add_token(token_type_e::empty, 0, 0, 1);
log::info << "Added tokens" << endl;
uint32_t axiom_factor = 4;
etl::vector axiom_chr{ branch, rotate_axiom };
group_id_t axiom_grp = rules.add_group_characteristic(axiom_chr, axiom_factor);
etl::vector branch_chr{ petal, rotate_branchr, branch, rotate_branchl, branch };
group_id_t branch_grp = rules.add_group_characteristic(branch_chr);
etl::vector petal_chr{ mark, walk_petal_length, mark, rotate_petal, walk_petal_side, mark };
group_id_t petal_grp = rules.add_group_characteristic(petal_chr);
log::info << "Added group characteristics" << endl;
rules.add_branch_rule(branch, branch_grp);
rules.add_branch_rule(petal, petal_grp);
log::info << "Added rules" << endl;
log::info << "Finished configuring ruleset" << endl;
} catch(const mtl::exception&) {
log::info << "Failed to configure ruleset, caught exception" << endl;
return 0;
}
generator_t gen(rules);
etl::vector<marker_t, 100> output;
while (gen.step_generation(output)) {
log::debug << "Stepped generation" << gen.generation_num() << endl;
for (const marker_t& m : output) {
log::debug << ' ' << m.m_id << ", " << m.m_pos << endl;
}
}
while (true) {
vid_vsync();
}
return 0;
}