void snis_slider_draw(struct slider *s)
{
	double v;
	float width, tx1;
	int bar_color = DARKGREEN;
	float ptr_height = s->height / 2.0;
	float ptr_width = s->height / 3.0;

	s->timer++;
	if (s->vertical) {
		snis_slider_draw_vertical(s);
		return;
	}
	float f;

	if (s->fuzz) {
		f = (float) ((snis_randn(1000) - 500.0f) * s->fuzz) / 100000.0f;
		f = f * s->length;
	} else {
		f = 0.0f;
	}

	v = s->sample();
	s->value = (v - s->r1) / (s->r2 - s->r1);
	if (s->value == 0)
		f = 0.0f; /* no fuzz if no power */
	v = s->sample();
	bar_color = choose_barcolor(s, v);
	sng_set_foreground(s->color);
	sng_current_draw_rectangle(0, s->x, s->y, s->length, s->height);
	width = s->value * (s->length - 2.0);
	width = width + f;
	if (width < 0.0)
		width = 0;
	if (width > s->length - 2.0)
		width = s->length - 2.0;
	if (!s->clicked)
		sng_set_foreground(bar_color);
	sng_current_draw_rectangle(1, s->x + 1.0, s->y + 1.0, width, s->height - 2.0);
	if (!s->clicked)
		sng_set_foreground(s->color);

	tx1 = (s->input * s->length) + s->x;

	if (s->clicked) {
		sng_current_draw_line(tx1, s->y, tx1 - ptr_width, s->y - ptr_height);
		sng_current_draw_line(tx1, s->y, tx1 + ptr_width, s->y - ptr_height);
		sng_current_draw_line(tx1 - ptr_width, s->y - ptr_height,
						tx1 + ptr_width, s->y - ptr_height); 
		sng_current_draw_line(tx1, s->y + s->height,
				tx1 - ptr_width, s->y + s->height + ptr_height); 
		sng_current_draw_line(tx1, s->y + s->height,
				tx1 + ptr_width, s->y + s->height + ptr_height); 
		sng_current_draw_line(tx1 - ptr_width, s->y + s->height + ptr_height,
				tx1 + ptr_width, s->y + s->height + ptr_height); 
	}
	sng_abs_xy_draw_string(s->label, s->font,
				s->x + s->length + 5.0, s->y + 2.0 * s->height / 3.0);
}
static void sng_bright_electric_line_plot_func(int x, int y, void *context)
{
	struct sng_dotted_plot_func_context *c = context;

	if (snis_randn(100) < 20) {
		sng_set_foreground(c->i);
		graph_dev_draw_point(x, y);
	}
}
示例#3
0
void mesh_distort_helper(struct mesh *m, float distortion)
{
	int i;

	for (i = 0; i < m->nvertices; i++) {
		float dx, dy, dz;

		dx = (float) snis_randn(1000) / 1000.0 * distortion - 0.5;
		dy = (float) snis_randn(1000) / 1000.0 * distortion - 0.5;
		dz = (float) snis_randn(1000) / 1000.0 * distortion - 0.5;

		m->v[i].x += m->v[i].x * dx;
		m->v[i].y += m->v[i].y * dy;
		m->v[i].z += m->v[i].z * dz;
	}
	m->radius = mesh_compute_radius(m);
	mesh_set_flat_shading_vertex_normals(m);
}
示例#4
0
void random_quat(union quat *q)
{
	float angle;
	union vec3 v;

	random_point_on_sphere(1.0, &v.v.x, &v.v.y, &v.v.z);
	angle = (float) snis_randn(360) * M_PI / 180.0;
	quat_init_axis_v(q, &v, angle);

}
static void snis_slider_draw_vertical(struct slider *s)
{
	double v;
	int height, ty1;
	int bar_color;
	int ptr_height = s->height / 2;
	int ptr_width = s->height / 3;
	float f;

	if (s->fuzz) {
		f = (float) ((snis_randn(1000) - 500.0f) * s->fuzz) / 100000.0f;
		f = f * s->length;
	} else {
		f = 0.0f;
	}

	s->timer++;
	v = s->sample();
	s->value = (v - s->r1) / (s->r2 - s->r1);
	if (s->value == 0)
		f = 0.0f; /* no fuzz if no power */
	v = s->sample();
	ty1 = (int) (s->y + s->length - s->input * s->length);
	bar_color = choose_barcolor(s, v);
	sng_set_foreground(s->color);
	sng_current_draw_rectangle(0, s->x, s->y, s->height, s->length);
	height = s->value * s->length - 1;
	height += f;
	if (height < 0)
		height = 0;
	if (height > s->length - 1)
		height = s->length - 1;
	if (!s->clicked)
		sng_set_foreground(bar_color);
	sng_current_draw_rectangle(1, s->x + 1, s->y + s->length - height,
					s->height - 2, height);
	if (!s->clicked)
		sng_set_foreground(s->color);

	if (s->clicked) {
		sng_current_draw_line(s->x, ty1, s->x - ptr_height, ty1 - ptr_width);
		sng_current_draw_line(s->x - ptr_height, ty1 - ptr_width, s->x - ptr_height, ty1 + ptr_width);
		sng_current_draw_line(s->x - ptr_height, ty1 + ptr_width, s->x, ty1);

		sng_current_draw_line(s->x + s->height, ty1, s->x + ptr_height + s->height, ty1 - ptr_width);
		sng_current_draw_line(s->x + ptr_height + s->height, ty1 - ptr_width,
			s->x + ptr_height + s->height, ty1 + ptr_width);
		sng_current_draw_line(s->x + ptr_height + s->height, ty1 + ptr_width,
			s->x + s->height, ty1);
	}
	/* sng_abs_xy_draw_string(s->label, s->font, s->x + s->length + 5, s->y + 2 * s->height / 3);  */
} 
示例#6
0
void mesh_derelict(struct mesh *m, float distortion)
{
	int i;

	for (i = 0; i < m->nvertices; i++) {
		float dx, dy, dz;

		dx = (float) (snis_randn(1000) / 1000.0 - 0.5) * distortion;
		dy = (float) (snis_randn(1000) / 1000.0 - 0.5) * (distortion / 10.0) - 0.5;
		dz = (float) (snis_randn(1000) / 1000.0 - 0.5) * (distortion / 10.0) - 0.5;

		if (m->v[i].x < 0) {
			m->v[i].x = dx;
			m->v[i].y += dy;
			m->v[i].z += dz;
		}
	}
	m->radius = mesh_compute_radius(m);
	for (i = 0; i < m->nvertices; i++)
		m->v[i].x -= m->radius / 2.0;
	m->radius = mesh_compute_radius(m);
	mesh_set_flat_shading_vertex_normals(m);
	mesh_graph_dev_init(m);
}
示例#7
0
void create_crater_heightmap(unsigned char *image, int imagew, int imageh, int x, int y, int r, int h)
{
	int i, npoints = (int) (1.7 * (M_PI * 2.0 * r));
	float angle;

	crater_dimple(image, imagew, imageh, x, y, r * 0.95, base_level);
	for (i = 0; i < npoints; i++) {
		int tx, ty;

		angle = (2.0 * M_PI * i) / (float) npoints + snis_random_float() * 10.0 * M_PI / 180.0;
		tx = x + cos(angle) * r + snis_random_float() * snis_random_float() * r * 3.9;
		ty = y - sin(angle) * r + snis_random_float() * snis_random_float() * r * 3.9;

		add_cone(image, imagew, imageh, tx, ty, (0.2 + 0.50 * zerotoone()) * r, h);
	}
	add_rays(image, imagew, imageh, x, y, r, h * 2.75, 50 + snis_randn(350));
}
示例#8
0
static void add_ray(unsigned char *image, int imagew, int imageh, int x, int y, int r, int h)
{
	int i;
	int npoints = snis_randn(100);
	float angle = snis_random_float() * 2.0 * M_PI;
	float radius = r;
	float con_rad = radius * 0.1;
	float tx, ty;
	float height = h;

	for (i = 0; i < npoints; i++) {
		tx = x + cos(angle) * radius;
		ty = y - sin(angle) * radius;
		add_cone(image, imagew, imageh, tx, ty, (int) con_rad, height);
		con_rad = con_rad * 0.98;
		height = height * (0.9 + 0.08 * zerotoone());
		radius = radius + zerotoone() * r * 0.3;
	}
}
示例#9
0
/* This is not very good, but better than nothing. */
void mesh_random_uv_map(struct mesh *m)
{
	int i;

	if (m->tex)
		free(m->tex);
	m->tex = malloc(sizeof(*m->tex) * m->ntriangles * 3);
	if (!m)
		return;
	for (i = 0; i < m->ntriangles; i++) {
		float u1, v1, u2, v2, u3, v3;

		u1 = (float) snis_randn(25) / 100.0f;
		v1 = (float) snis_randn(25) / 100.0f;
		u2 = (float) (50.0f + snis_randn(25)) / 100.0f;
		v2 = (float) snis_randn(25) / 100.0f;
		u3 = (float) (50.0f + snis_randn(25)) / 100.0f;
		v3 = (float) (50.0f + snis_randn(25)) / 100.0f;
		mesh_set_triangle_texture_coords(m, i, u1, v1, u2, v2, u3, v3);
	}
}
示例#10
0
void sng_setup_colors(void *gtk_widget, char *user_color_file)
{
	int i;

	BUILD_ASSERT(ARRAY_SIZE(gradient_colors) == NGRADIENTS);

	/* values extracted from gdk_color_parse */
	huex[WHITE].red = 65535;
	huex[WHITE].green = 65535;
	huex[WHITE].blue = 65535;

	huex[BLACK].red = 0;
	huex[BLACK].green = 0;
	huex[BLACK].blue = 0;

	huex[LIMEGREEN].red = 12850;
	huex[LIMEGREEN].green = 52685;
	huex[LIMEGREEN].blue = 12850;

	huex[DARKGREEN].red = 0;
	huex[DARKGREEN].green = 25700;
	huex[DARKGREEN].blue = 0;

	huex[YELLOW].red = 65535;
	huex[YELLOW].green = 65535;
	huex[YELLOW].blue = 0;

	huex[RED].red = 65535;
	huex[RED].green = 0;
	huex[RED].blue = 0;

	huex[ORANGE].red = 65535;
	huex[ORANGE].green = 42405;
	huex[ORANGE].blue = 0;

	huex[MAGENTA].red = 65535;
	huex[MAGENTA].green = 0;
	huex[MAGENTA].blue = 65535;

	huex[DARKRED].red = 35723;
	huex[DARKRED].green = 0;
	huex[DARKRED].blue = 0;

	huex[AMBER].red = 65535;
	huex[AMBER].green = 42405;
	huex[AMBER].blue = 0;

	huex[DARKTURQUOISE].red = 0;
	huex[DARKTURQUOISE].green = 52942;
	huex[DARKTURQUOISE].blue = 53713;

	huex[ORANGERED].red = 65535;
	huex[ORANGERED].green = 17733;
	huex[ORANGERED].blue = 0;

	for (i = 0; i < NSHADESOFGRAY; i++) {
		huex[GRAY + i].red = (i * 32767 * 2) / 256;
		huex[GRAY + i].green = (i * 32767 * 2) / 256;
		huex[GRAY + i].blue = (i * 32767 * 2) / 256;
	}

	for (i = 1; i <= NSHADECOLORS; i++) {
		int j, r, g, b;

		r = snis_randn(32767); 
		g = snis_randn(32767); 
		b = snis_randn(32767); 

		for (j = 0; j < NSHADESOFGRAY / 2; j++) { 
			int index;
			float f;

			f = (float) j / (float) (NSHADESOFGRAY / 2.0);

			index = GRAY + (i * NSHADESOFGRAY) + j;
			huex[index].red = (f * (float) r);
			huex[index].green = (f * (float) g); 
			huex[index].blue = (f * (float) b); 
		}

		for (j = NSHADESOFGRAY / 2; j < NSHADESOFGRAY; j++) {
			int index;
			float f;

			f = (float) (j - NSHADESOFGRAY / 2) / (float) NSHADESOFGRAY / 2.0;

			index = GRAY + (i * NSHADESOFGRAY) + j;
			huex[index].red = r + (f * ((32767.0 * 2.0) - (float) r));
			huex[index].green = g + (f * ((32767.0 * 2.0) - (float) g)); 
			huex[index].blue = b + (f * ((32767.0 * 2.0) - (float) b)); 
		}
	}

	int grad_index = GRADIENTS;

	for (i=0; i<NGRADIENTS; i++ ) {
		int j;
		double h = gradient_colors[i].h;
		double s = gradient_colors[i].s;
		double v = gradient_colors[i].v;

		/* add the shades from black to color */
		for (j=0; j<NGRADIENT_SHADES; j++) {
			double f = j/(double)NGRADIENT_SHADES;
			double fi = 1.0 - f;
			hsv2rgb(h, s + (1.0-s)*fi, v * f, &huex[grad_index]);
			grad_index++;
		}

		/* add the pure color */
		hsv2rgb(h, s, v, &huex[grad_index]);
		*gradient_colors[i].color_index = grad_index;
		grad_index++;

		/* add the shades from color to white */
		for (j=1; j<=NGRADIENT_SHADES; j++) {
			double f = (NGRADIENT_SHADES-j)/(double)NGRADIENT_SHADES;
			double fi = 1.0 - f;
			hsv2rgb(h, s * f, v + (1.0-v)*fi, &huex[grad_index]);
			grad_index++;
		}
	}

	sng_read_user_colors(user_color_file);

	fixup_ui_color(BLUE_FIXUP, BLUE);
	fixup_ui_color(GREEN_FIXUP, GREEN);
	fixup_ui_color(CYAN_FIXUP, CYAN);

	graph_dev_setup_colors(gtk_widget, huex, TOTAL_COLORS);
}
示例#11
0
void sng_electric_line_plot_func(int x, int y, void *context)
{
	if (snis_randn(100) < 10)
		graph_dev_draw_point(x, y);
}