From 4887b4b649a5807ff456252e6e14395f04f02c9d Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Wed, 11 Apr 2018 21:39:32 -0400 Subject: Fix brot scaling for window aspect ratio --- bin/brot.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'bin') diff --git a/bin/brot.c b/bin/brot.c index 3402955c..3302ee9e 100644 --- a/bin/brot.c +++ b/bin/brot.c @@ -40,39 +40,45 @@ static uint32_t mandelbrot(double complex c) { return 0; } -static double complex origin = -0.75 + 0.0 * I; -static double complex scale = 3.5 + 2.0 * I; -static double complex rotate = 1; +static uint32_t color(uint32_t n) { + uint32_t gray = (double)n / (double)depth * 255.0; + return gray << 16 | gray << 8 | gray; +} + +static double complex translate = -0.75; +static double complex rotate = 1.0; +static double scale = 2.5; void draw(uint32_t *buf, size_t width, size_t height) { + double yRatio = (height > width) ? (double)height / (double)width : 1.0; + double xRatio = (width > height) ? (double)width / (double)height : 1.0; for (size_t y = 0; y < height; ++y) { - double complex zy = ((double)y / (double)height - 0.5) * cimag(scale) * I; for (size_t x = 0; x < width; ++x) { - double complex zx = ((double)x / (double)width - 0.5) * creal(scale); - uint64_t n = mandelbrot(origin + (zx + zy) * rotate); - uint32_t g = (double)n / (double)depth * 255.0; - buf[y * width + x] = g << 16 | g << 8 | g; + double zx = ((double)x / (double)width - 0.5) * xRatio; + double zy = ((double)y / (double)height - 0.5) * yRatio; + uint32_t n = mandelbrot((zx + zy * I) * scale * rotate + translate); + buf[y * width + x] = color(n); } } } bool input(char in) { const double PI = acos(-1.0); - double complex realTrans = 0.01 * creal(scale) * rotate; - double complex imagTrans = 0.01 * cimag(scale) * I * rotate; - double complex rotation = cexp(0.01 * PI * I); + double complex realTrans = 0.01 * scale * rotate; + double complex imagTrans = 0.01*I * scale * rotate; + double complex theta = cexp(0.01 * PI * I); switch (in) { case 'q': return false; case '.': depth++; break; case ',': if (depth) depth--; break; case '+': scale *= 0.9; break; case '-': scale *= 1.1; break; - case 'l': origin += realTrans; break; - case 'h': origin -= realTrans; break; - case 'j': origin += imagTrans; break; - case 'k': origin -= imagTrans; break; - case 'u': rotate *= rotation; break; - case 'i': rotate /= rotation; break; + case 'l': translate += realTrans; break; + case 'h': translate -= realTrans; break; + case 'j': translate += imagTrans; break; + case 'k': translate -= imagTrans; break; + case 'u': rotate *= theta; break; + case 'i': rotate /= theta; break; } return true; } @@ -81,11 +87,11 @@ const char *status(void) { static char buf[256]; snprintf( buf, sizeof(buf), - "%u %g+%gi %g+%gi %g+%gi", + "%u %g+%gi %g+%gi %g", depth, - creal(origin), cimag(origin), - creal(scale), cimag(scale), - creal(rotate), cimag(rotate) + creal(translate), cimag(translate), + creal(rotate), cimag(rotate), + scale ); return buf; } -- cgit 1.4.1 ='#n30'>30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
/* ui-commit.c: generate commit view
 *
 * Copyright (C) 2006 Lars Hjemli
 *
 * Licensed under GNU General Public License v2
 *   (see COPYING for full license text)
 */

#include "cgit.h"
#include "html.h"
#include "ui-shared.h"
#include "ui-diff.h"

void cgit_print_commit(char *hex)
{
	struct commit *commit, *parent;
	struct commitinfo *info;
	struct commit_list *p;
	unsigned char sha1[20];
	char *tmp;
	int parents = 0;

	if (!hex)
		hex = ctx.qry.head;

	if (get_sha1(hex, sha1)) {
		cgit_print_error(fmt("Bad object id: %s", hex));
		return;
	}
	commit = lookup_commit_reference(sha1);
	if (!commit) {
		cgit_print_error(fmt("Bad commit reference: %s", hex));
		return;
	}
	info = cgit_parse_commit(commit);

	html("<table summary='commit info' class='commit-info'>\n");
	html("<tr><th>author</th><td>");
	html_txt(info->author);
	html(" ");
	html_txt(info->author_email);
	html("</td><td class='right'>");
	cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
	html("</td></tr>\n");
	html("<tr><th>committer</th><td>");
	html_txt(info->committer);
	html(" ");
	html_txt(info->committer_email);
	html("</td><td class='right'>");
	cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
	html("</td></tr>\n");
	html("<tr><th>commit</th><td colspan='2' class='sha1'>");
	tmp = sha1_to_hex(commit->object.sha1);
	cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp);
	html(" (");
	cgit_patch_link("patch", NULL, NULL, NULL, tmp);
	html(")</td></tr>\n");
	html("<tr><th>tree</th><td colspan='2' class='sha1'>");
	tmp = xstrdup(hex);
	cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
		       ctx.qry.head, tmp, NULL);
	html("</td></tr>\n");
      	for (p = commit->parents; p ; p = p->next) {
		parent = lookup_commit_reference(p->item->object.sha1);
		if (!parent) {
			html("<tr><td colspan='3'>");
			cgit_print_error("Error reading parent commit");
			html("</td></tr>");
			continue;
		}
		html("<tr><th>parent</th>"
		     "<td colspan='2' class='sha1'>");
		cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
				 ctx.qry.head, sha1_to_hex(p->item->object.sha1));
		html(" (");
		cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
			       sha1_to_hex(p->item->object.sha1), NULL);
		html(")</td></tr>");
		parents++;
	}
	if (ctx.repo->snapshots) {
		html("<tr><th>download</th><td colspan='2' class='sha1'>");
		cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
					  hex, ctx.repo->snapshots);
		html("</td></tr>");
	}
	html("</table>\n");
	html("<div class='commit-subject'>");
	html_txt(info->subject);
	html("</div>");
	html("<div class='commit-msg'>");
	html_txt(info->msg);
	html("</div>");
	if (parents < 3) {
		if (parents)
			tmp = sha1_to_hex(commit->parents->item->object.sha1);
		else
			tmp = NULL;
		cgit_print_diff(ctx.qry.sha1, tmp, NULL);
	}
	cgit_free_commitinfo(info);
}