Why have I forgotten trigonometry again

This commit is contained in:
XANTRONIX Development 2019-05-25 21:30:31 -05:00
parent b05df93160
commit e5b2b11ec0
3 changed files with 38 additions and 15 deletions

View file

@ -6,8 +6,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
static void redraw(cairo_surface_t *sfc, cairo_t *ctx) {
static void redraw(cairo_t *ctx) {
/*
* Paint canvas black
*/
@ -27,10 +28,10 @@ static void redraw(cairo_surface_t *sfc, cairo_t *ctx) {
/*
* Draw two smaller circles
*/
cairo_arc(ctx, 442, 368, 64, 0, 360);
cairo_arc(ctx, 442, 368, 64, 0, 360 * (M_PI/180));
cairo_stroke(ctx);
cairo_arc(ctx, 578, 368, 64, 0, 360);
cairo_arc(ctx, 582, 368, 64, 0, 360 * (M_PI/180));
cairo_stroke(ctx);
/*
@ -41,9 +42,38 @@ static void redraw(cairo_surface_t *sfc, cairo_t *ctx) {
cairo_line_to(ctx, 592, 288);
cairo_line_to(ctx, 432, 288);
cairo_line_to(ctx, 432, 48);
cairo_set_source_rgb(ctx, 0.75, 0, 0);
cairo_fill(ctx);
cairo_move_to(ctx, 432, 48);
cairo_line_to(ctx, 592, 48);
cairo_line_to(ctx, 592, 288);
cairo_line_to(ctx, 432, 288);
cairo_line_to(ctx, 432, 48);
cairo_set_source_rgb(ctx, 1, 1, 1);
cairo_stroke(ctx);
}
static void draw_text(cairo_t *cr) {
cairo_select_font_face(cr, "Helvetica",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, 13);
cairo_move_to(cr, 208 + 192, 240);
cairo_save(cr);
cairo_rotate(cr, 45.0 * (M_PI/180));
cairo_show_text(cr, "10");
cairo_restore(cr);
cairo_move_to(cr, 208, 240 + 192);
cairo_save(cr);
cairo_rotate(cr, 90.0 * (M_PI/180));
cairo_show_text(cr, "20");
cairo_restore(cr);
}
int main(int argc, char **argv) {
Display *display;
Window win;
@ -79,7 +109,8 @@ int main(int argc, char **argv) {
ctx = cairo_create(sfc);
redraw(sfc, ctx);
redraw(ctx);
draw_text(ctx);
while (1) {
XExposeEvent *expose;

View file

@ -14,8 +14,6 @@ int hexagram_module_close(hexagram_module *module);
const char *hexagram_module_name(hexagram_module *module);
int hexagram_module_win(hexagram_module *module);
int hexagram_module_run(hexagram_module *module,
hexagram_dict *buses);

View file

@ -5,13 +5,15 @@
#include <dlfcn.h>
#include <sys/wait.h>
#include <X11/Xlib.h>
#include <hexagram/module.h>
#include <hexagram/window.h>
struct _hexagram_module {
const char *soname;
void *handle;
char *(*name)();
int (*win)();
int (*run)(hexagram_dict *buses);
pid_t pid;
};
@ -58,14 +60,6 @@ const char *hexagram_module_name(hexagram_module *module) {
return module->name();
}
int hexagram_module_win(hexagram_module *module) {
if (module->win == NULL) {
return -1;
}
return module->win();
}
int hexagram_module_run(hexagram_module *module,
hexagram_dict *buses) {
if (module->run == NULL) {