コード例 #1
0
int main()
{
  char keyboard_input[100];
  XColor black_col,white_col,red_col,green_col,blue_col,yellow_col,magenta_col,cyan_col;
  Colormap colormap;
  char black_bits[] = "#000000";
  char white_bits[] = "#FFFFFF";    // Mix red, green and blue to get white
  char red_bits[] = "#FF0000";
  char green_bits[] = "#00FF00";
  char blue_bits[] = "#0000FF";
  char yellow_bits[] = "#FFFF00";   // Mix red and green to get yellow
  char magenta_bits[] = "#FF00FF";  // A sort of purple color
  char cyan_bits[] = "#00FFFF";     // A blue-green color

  //Display *dpy = XOpenDisplay(NIL); 
  dpy = XOpenDisplay(NIL); assert(dpy);   // Open the display
  // Define the colors we want to use
  colormap = DefaultColormap(dpy, 0);
  XParseColor(dpy, colormap, black_bits, &black_col); XAllocColor(dpy, colormap, &black_col);
  XParseColor(dpy, colormap, white_bits, &white_col); XAllocColor(dpy, colormap, &white_col);
  XParseColor(dpy, colormap, red_bits, &red_col); XAllocColor(dpy, colormap, &red_col);
  XParseColor(dpy, colormap, green_bits, &green_col);XAllocColor(dpy, colormap, &green_col);
  XParseColor(dpy, colormap, blue_bits, &blue_col);XAllocColor(dpy, colormap, &blue_col);
  XParseColor(dpy, colormap, yellow_bits, &yellow_col);XAllocColor(dpy, colormap, &yellow_col);
  XParseColor(dpy, colormap, magenta_bits, &magenta_col);XAllocColor(dpy, colormap, &magenta_col);
  XParseColor(dpy, colormap, cyan_bits, &cyan_col);XAllocColor(dpy, colormap, &cyan_col);
  // Create the window  The numbers are the x and y locations on the screen, the width and height, 
  // border width (which is usually zero)
  w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, window_width, window_height,
  0, black_col.pixel, black_col.pixel);
  XSelectInput(dpy, w, StructureNotifyMask);        // We want to get MapNotify events
  XMapWindow(dpy, w);         // "Map" the window (that is, make it appear on the screen)
  for(;;){XEvent e; XNextEvent(dpy,&e); if(e.type == MapNotify) break;} //Wait for the MapNotify event
  // which means that the window has appeared on the screen.
  gc = XCreateGC(dpy, w, 0, NIL);        // Create a "Graphics Context"
  get_pen(white_col);
  //  We are finally ready to do some drawing!  Whew!  

  // ................  Students: you put your beautiful code HERE: .......................
  srand(time(NULL)); //  Get ready to make random numbers.  The time "seeds" the generator.
  int i;
  double x=0,  y=0;
  home();      // Send the turtle to the middle of the window.  That's its "home"
  get_pen(green_col);  pen_down();
  for (i=0; i<36; i++) {
    x = x + rand_range(-30.0, 30.0);  //Generates random number between these two numbers.
    y = y + rand_range(-30.0, 30.0)+5.0;
    gotoxy(x, y);   // Move the turtle to the new location.  It will draw a line if the pen is down.
    XFlush(dpy); // Tell the graphics server that it should really show us the results now.
    printf("1 x=%g y=%g heading=%g\n",turtle_x,turtle_y,turtle_heading); //Optional: use for debugging
    usleep(100000); XFlush(dpy); // Optional: use this to see the lines being drawn, one-by-one
  }
  XFlush(dpy); // Tell the graphics server that it should really show us the results now.
  sleep(1);  // Wait for 1 second
  printf("Press enter when done.\n");
  fgets (keyboard_input,100,stdin); 
  return(0);
}
コード例 #2
0
ファイル: levelmeters.c プロジェクト: rocketsquawk/mudita24
gint level_meters_configure_event(GtkWidget *widget, GdkEventConfigure *event) {
	int idx = get_index(gtk_widget_get_name(widget));
	GtkAllocation allocation;
	gtk_widget_get_allocation(widget, &allocation);
	if (pixmap[idx] != NULL)
		gdk_pixmap_unref(pixmap[idx]);
	pixmap[idx] = gdk_pixmap_new(gtk_widget_get_window(widget),
				     allocation.width,
				     allocation.height,
				     -1);
	penWhiteLight[idx] = get_pen(idx, 0xffff, 0xffff, 0xffff);
	penGreenLight[idx] = get_pen(idx, 0, 0xffff, 0);

	/* NPM: Setup penForeground[idx] color for meters */
	levelmeters_init_fg(widget, (penForeground[idx] = gdk_gc_new(pixmap[idx])));
	/* NPM: Setup penBackground[idx] color for meters */
	levelmeters_init_bg(widget, (penBackground[idx] = gdk_gc_new(pixmap[idx])));

	penOrangeLight[idx] = get_pen(idx, 0xff11, 0x9911, 0);

	peak_label_color = (GdkColor *)g_malloc(sizeof(GdkColor)); /* free()'d on exit() */
        gdk_color_parse("red", peak_label_color);
	gdk_color_alloc(gdk_colormap_get_system(), peak_label_color);

	penRedLight[idx] = get_pen(idx, 0xffff, 0, 0);

	gdk_draw_rectangle(pixmap[idx],
			   gtk_widget_get_style(widget)->black_gc,
			   TRUE,
			   0, 0,
			   allocation.width,
			   allocation.height);

	/* NPM: ensure redraw_meters() below does a full refresh, per meter  */
	if (idx == 0) {		/* "if stereo" -- special case for L/R output pair of digital mixer */
	  // g_print("level_meters_configure_event() for stereo\n");
	  peak_levels[IDX_LMIX]     = 0;
	  peak_levels[IDX_RMIX]     = 0;
	  previous_levels[IDX_LMIX] = 0;
	  previous_levels[IDX_RMIX] = 0;
	  peak_changed[IDX_LMIX]    = RESET;
	  peak_changed[IDX_RMIX]    = RESET;
	}
	else {
	  // g_print("level_meters_configure_event() for %i\n", idx);
	  peak_levels[idx-1]        = 0;
	  previous_levels[idx-1]    = 0;
	  peak_changed[idx-1]       = RESET;
	}
	
	// g_print("configure: %i:%i\n", allocation.width, allocation.height);
	redraw_meters(idx, allocation.width, allocation.height, 0, 0);
	return TRUE;
}
コード例 #3
0
void draw_rect(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
{
	uint16_t lcd_width, lcd_height;
	uint16_t * vram = lcdc_get_vram_address();
	lcdc_get_dimensions(&lcd_width, &lcd_height);
	uint32_t stopx, stopy;
	uint16_t color = get_pen();
	uint16_t x1, y1;
	uint32_t index;
	stopx = (width + x > lcd_width ? lcd_width : width + x);
	stopy = (height + y > lcd_height ? lcd_height : height + y);
	for (y1 = y; y1 < stopy; ++y1) {
		for(x1 = x; x1 < stopx; ++x1) {
			index = (y1 * lcd_width) + x1;
			vram[index] = color;
		}
	}
}
コード例 #4
0
void draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
	int32_t i, delta_x, delta_y, sdelta_x, sdelta_y, absdelta_x, absdelta_y;
	int32_t x, y, plot_x, plot_y;
	uint16_t color = get_pen();
	delta_x = x2 - x1;
	delta_y = y2 - y1;
	absdelta_x = (delta_x >= 0 ? delta_x : -delta_x);
	absdelta_y = (delta_y >= 0 ? delta_y : -delta_y);
	sdelta_x = (delta_x >= 0 ? 1 : -1);
	sdelta_y = (delta_y >= 0 ? 1 : -1);
	x = absdelta_y>>1;
  	y = absdelta_x>>1;
	plot_x = x1;
	plot_y = y1;

	if (absdelta_x >= absdelta_y) {
		for(i = 0; i < absdelta_x; i++) {
			y += absdelta_y;
			if (y >= absdelta_x) {
				y -= absdelta_x;
				plot_y += sdelta_y;
			}
			plot_x += sdelta_x;
			set_pixel(plot_x, plot_y, color);
		}
	} else {
		for(i = 0; i < absdelta_y; i++) {
			x += absdelta_x;
			if (x >= absdelta_y) {
				x -= absdelta_y;
				plot_x += sdelta_x;
			}
			plot_y += sdelta_y;
			set_pixel(plot_x, plot_y, color);
		}
	}
}