Exemple #1
0
void ins(GtkWidget *widget, gpointer data) {
  GtkWidget *darea = (GtkWidget *) data;

  int s = gtk_entry_get_text(widget);
  int n = atoi(s);

  if (n > 0 && n < 100)
    print_circle(darea, s, RED, 16, 16, 15, 16);
  else
    print_circle(darea, "?", RED, 16, 16, 15, 16);
}
Exemple #2
0
void ins_r(GtkWidget *widget, gpointer data) {
  GtkWidget *darea = (GtkWidget *) data;

  char *s = (char*) malloc(3 * sizeof(char));
  sprintf(s, "%d", randnum);

  print_circle(darea, s, RED, 16, 16, 15, 16);
}
Exemple #3
0
int chess_doing(int x, int y)
{
    int m_x = x;
    int m_y = y;
    int dx = (x-ST_X)%SPACE;
    int dy = (y-ST_Y)%SPACE;
    
    if(x < ST_X || x > ST_X+SPACE*(BOARD_X-1)){
        
        if((x > 25)&&(x < 75)&&(y > 75)&&(y < 125)&&(current_player == 1)){
            current_color = WHITE;
            current_player = 2;
        }    
        if((x > 25)&&(x < 75)&&(y > 175)&&(y < 225)&&(current_player == 2)){
            current_color = BLACK;
            current_player = 1;
        } 

        return 0;
     }


    if(y < ST_Y || y > ST_Y+SPACE*(BOARD_Y-1)){
        
        return 0;
    }

    /*adjust*/
    if(dx < SPACE/2){
        x -= dx;
    }else{
        x +=(SPACE-dx);
     }
    if(dy < SPACE/2){
        y -= dy;
    }else{
        y +=(SPACE-dy);
     
     }

    if((diff != current_player)&&(chess_board[(x-ST_X)/SPACE+BOARD_X*(y-ST_Y)/SPACE]) == 0){ 
        restore(m_x, m_y);
    //    restore(80, 230);
        print_circle(x, y, 13, current_color);
        diff = current_player;
        draw_cursor(m_x, m_y);
        chess_sort(x, y);
      //  draw_cursor(80, 130);
    }
   
   // print_logical();
    if(chess_vic() != 0){
      //  print_smile();
        return current_player;
    }
    return 0;
}
Exemple #4
0
int main(void)
{
	ninsert(0, 0);
	ninsert(1, 1);
	ninsert(2, 2);
	ndelete(-1);
	print_circle();
	//printf("front = %d, rear = %d, length = %d\n", front, rear, length());

	return 0;
}
Exemple #5
0
void print_tree(GtkWidget *widget, rbtree_node node) {
  if (node != NULL) {
    char *s = (char*) malloc(3 * sizeof(char));
    sprintf(s, "%d", node->key);

    print_lines(widget, node->left != NULL, node->right != NULL, node->x, node->y, node->r);

    print_tree(widget, node->left);
    print_circle(widget, s, node_color(node), node->x, node->y, 15, 16);
    print_tree(widget, node->right);
  }
}
Exemple #6
0
/* *
   * in this function, when we get a radom location.
   * we must correct the location to our chessmap line.
   * at last we print a chessmen on the net we darw.
   *
   * draw and fill a circle as a chessman
   * */
void print_chessman(int x, int y, int r, u32_t color)
{
	int x1 = 0, y1 = 0;

	if(x > Starting_X-Space/2 && x < Starting_X+Size_X*Space-Space/2 && 
		y > Starting_Y-Space/2 && y < Starting_Y+Size_Y*Space-Space/2)
	{
		x1 = (x - Starting_X + Space/2) / Space * Space + Starting_X;
		y1 = (y - Starting_Y + Space/2) / Space * Space + Starting_Y;

		print_circle(x1,y1,r,color);
	}
}
Exemple #7
0
int
main(int argc, char* argv[])
{
	line* l;
	int nl, ind;
	parse_cl(argc, argv);
	print_title();
	base_triangles();

	nl = border(sfile->trg, sfile->hdr->nfacets, &l);
	printf("Facets %d\n", sfile->hdr->nfacets);
	printf("Border segments %d\n", nl);

	for(int i=0; i<nl; i++)
		print_line(&l[i]);

	print_circle();

}
Exemple #8
0
node lookup_node(GtkWidget *darea, rbtree t, int key) {
  char *s = (char*) malloc(3 * sizeof(char));
  sprintf(s, "%d", key);

  node n = t->root;

  while (n != NULL) {
    if (path)
      print_circle(darea, s, RED, n->x - 20, n->y, 10, 12);

    int comp = compare(key, n->key);

    if (comp == 0)
      return n;
    else if (comp < 0)
      n = n->left;
    else
      n = n->right;
  }

  return n;
}
Exemple #9
0
void on_delete_event(GtkWidget *widget, GdkEventExpose *event, const char *s) {
  print_circle(widget, s, BLACK, 16, 16, 15, 16);
}
Exemple #10
0
void on_insert_event(GtkWidget *widget, GdkEventExpose *event, const char *s) {
  print_circle(widget, s, RED, 16, 16, 15, 16);
}
Exemple #11
0
void rbtree_insert(GtkWidget *darea, rbtree t, int key) {
  int x = WIDTH / 2, y = 22, r = (WIDTH - 20) / 2;

  char *s = (char*) malloc(3 * sizeof(char));
  sprintf(s, "%d", key);

  node inserted_node = new_node(key, RED, NULL, NULL);

  if (t->root == NULL) {
    inserted_node->x = x;
    inserted_node->y = y;
    inserted_node->r = r;

    t->root = inserted_node;
  }
  else {
    node n = t->root;

    while (1) {
      int comp = compare(key, n->key);

      if (comp == 0) {
        if (path)
          print_circle(darea, s, RED, x - 20, y, 10, 12);

        free (inserted_node);

        return;
      }
      else if (comp < 0) {
        if (path)
          print_circle(darea, s, RED, x - 20, y, 10, 12);

        if (n->left == NULL) {
          inserted_node->x = x - r / 2;
          inserted_node->y = y + 30;
          inserted_node->r = r / 2;

          n->left = inserted_node;

          print_circle(darea, s, RED, inserted_node->x, inserted_node->y, 15, 16);

          break;
        }
        else {
          x -= r / 2;
          y += 30;
          r /= 2;

          n = n->left;
        }
      }
      else {
        if (path)
          print_circle(darea, s, RED, x - 20, y, 10, 12);

        if (n->right == NULL) {
          inserted_node->x = x + r / 2;
          inserted_node->y = y + 30;
          inserted_node->r = r / 2;

          n->right = inserted_node;

          print_circle(darea, s, RED, inserted_node->x, inserted_node->y, 15, 16);

          break;
        }
        else {
          x += r / 2;
          y += 30;
          r /= 2;

          n = n->right;
        }
      }
    }

    inserted_node->parent = n;
  }

  insert_case1(darea, t, inserted_node);
}
Exemple #12
0
/**
 * @brief Get all possible collisions with another line
 * @param aCompare Line to check
 * @param aOutput Output circle
 * @return If circle is found or not
 */
bool Line::GetCollisions(Line const &aCompare, Circle &aOutput)
{
  Vector3 d = aCompare.position - position;
  float dist = d.length();
  float longer = length >= aCompare.length ? length : aCompare.length;
  float shorter = length >= aCompare.length ? aCompare.length : length;

  print_line(*this);
  print_line(aCompare);

  // If they're in the exact same location that would be a problem
  if (position == aCompare.position)
  {
    // IS THIS THE SAME EXACT SPHERE?!
    if (length == aCompare.length)
    {
      aOutput.position = position;
      aOutput.radius = length;
      aOutput.up = Vector3(0, 1, 0);
      aOutput.right = Vector3(0, 0, 1);
      DebugLogPrint("Same exact sphere, gonna return false\n\n");
    }
    else
    {
      DebugLogPrint("One sphere is inside of another, WAT\n");
      DebugLogPrint("Therefore, cannot touch, gonna return false\n\n");
    }
    print_circle(aOutput);
    DebugLogPrint("\n\n");
    return false;
  }

  // > is an early out
  if (dist < length + aCompare.length && dist != longer - shorter)
  {
    // THE IDEA: Find one point, rotate about arbitrary axis between spheres
    // Reduce the problem to solving a circle
    Vector3 axis = d.normalize();
    float xylength = sqrt(axis.x * axis.x + axis.y * axis.y);
    float xyzlength = axis.length();
    // Don't want to divide by zero
    float templength = xylength > 0.0f ? xylength : 1.0f;
    // Our matrices
    // First, go to xz plane
    float xzvalues[3][3] =
    {
    { axis.x / templength, axis.y / templength, 0 },
    { -axis.y / templength, axis.x / templength, 0 },
    { 0, 0, 1 } };
    // Then, only to z axis
    float zvalues[3][3] =
    {
    { axis.z / xyzlength, 0, -xylength / xyzlength },
    { 0, 1, 0 },
    { xylength / xyzlength, 0, axis.z / xyzlength } };

    // Create identity matrix if we're already on the z plane
    if (xylength <= 0.0f)
    {
      xzvalues[0][0] = 1.0f;
      xzvalues[1][1] = 1.0f;
      xzvalues[1][0] = 0.0f;
      xzvalues[0][1] = 0.0f;
    }

    // Create our matrices and invert them
    Matrix33 xztrans(xzvalues);
    Matrix33 ztrans(zvalues);
    Matrix33 toZAxis = ztrans * xztrans;
    Matrix33 toZAxisInverse = toZAxis.Invert();

    Vector3 comparePos = toZAxis * d;
    dist = comparePos.length();

    // Circle collision function
    float z = ((dist * dist) - (aCompare.length * aCompare.length)
        + (length * length)) / (2.0f * dist);
    float y = sqrt((length * length) - (z * z));

    // Create our circle
    aOutput.position = Vector3(0, 0, z);
    aOutput.up = Vector3(0, 1, 0);
    aOutput.right = Vector3(0, 0, 1);
    aOutput.radius = y;

    aOutput.position = toZAxisInverse * aOutput.position;
    aOutput.position += position;
    aOutput.up = toZAxisInverse * aOutput.up;
    aOutput.right = toZAxisInverse * aOutput.right;
  }
  else if (dist == length + aCompare.length)
  {
    // They barely touch, from the outside
    Vector3 largerPos =
        length >= aCompare.length ? position : aCompare.position;
    Vector3 smallerPos =
        length >= aCompare.length ? aCompare.position : position;
    float smallerLen = length >= aCompare.length ? aCompare.length : length;
    d = smallerPos - largerPos;

    DebugLogPrint("The radii barely touch, will still return true, but radius is zero\n");
    aOutput.position = smallerPos - (d.normalize() * smallerLen);
    aOutput.radius = 0;
    aOutput.up = Vector3(0, 1, 0);
    aOutput.right = Vector3(0, 0, 1);
  }
  else if (dist == longer - shorter)
  {
    // They barely touch, from the inside
    Vector3 largerPos =
        length >= aCompare.length ? position : aCompare.position;
    Vector3 smallerPos =
        length >= aCompare.length ? aCompare.position : position;
    float smallerLen = length >= aCompare.length ? aCompare.length : length;
    d = smallerPos - largerPos;

    DebugLogPrint("The radii barely touch, will still return true, but radius is zero\n");
    aOutput.position = smallerPos + (d.normalize() * smallerLen);
    aOutput.radius = 0;
    aOutput.up = Vector3(0, 1, 0);
    aOutput.right = Vector3(0, 0, 1);
  }
  else
  {
    DebugLogPrint("These LineSegments can never touch. Returning false.\n\n");
    return false;
  }

  print_circle(aOutput);
  DebugLogPrint("\n\n");
  return true;
}
Exemple #13
0
int transmit(void) {
	// Hide the cursor, and make sure it comes back before exiting.
	set_cursor(false);
	signal(SIGINT, sigint_handler);

	// Set up the keyboard listener.
	long time_unit = calibrate_listener();
	if (time_unit == EOF) {
		return 0;
	}
	if (!spawn_listener()) {
		print_error("error creating thread");
		return 1;
	}

	// Set up the circular buffers.
	int buf_size = number_of_columns();
	char code_buf[buf_size];
	char text_buf[buf_size];
	struct Circle code_circ, text_circ;
	init_empty(&code_circ, code_buf, buf_size);
	init_empty(&text_circ, text_buf, buf_size);
	append(&code_circ, '*');

	// Begin the main loop.
	Code code = 0;
	int code_size = 0;
	bool done = false;
	long time = current_millis();
	enum { NONE, CHAR, WORD } wait_mode = NONE;
	while (!done) {
		// Check the state of the keyboard listener.
		long time_now = current_millis();
		enum ListenerState state = get_listener_state(time_now);
		switch (state) {
		case LS_EOF:
			done = true;
			continue;
		case LS_NONE:
			break;
		case LS_DOWN:
			insert(&code_circ, '.');
			wait_mode = NONE;
			code <<= 1;
			code_size++;
			break;
		case LS_REPEAT:
			insert(&code_circ, '-');
			code |= 1;
			break;
		case LS_HOLD:
		case LS_HOLD_R:
			break;
		case LS_UP:
			append(&code_circ, '*');
			time = time_now;
			wait_mode = CHAR;
			break;
		}

		// Check if enough time has passed to start a new character or word.
		long elapsed = time_now - time;
		switch (wait_mode) {
		case NONE:
			break;
		case CHAR:
			if (elapsed > TIME_BETWEEN_CHARS) {
				insert(&code_circ, ' ');
				append(&code_circ, '*');
				wait_mode = WORD;

				char ch = INVALID_CODE;
				if (code_size <= MAX_SIZE) {
					code = add_size(code, code_size);
					char decoded = code_to_char(code);
					if (decoded) {
						ch = decoded;
					}
				}
				append(&text_circ, ch);
				code = 0;
				code_size = 0;
			}
			break;
		case WORD:
			if (elapsed > TIME_BETWEEN_WORDS) {
				insert(&code_circ, '/');
				append(&code_circ, ' ');
				append(&code_circ, '*');
				wait_mode = NONE;
				append(&text_circ, ' ');
			}
			break;
		}

		// Print the contents of both buffers.
		putchar('\r');
		print_circle(&code_circ);
		fputs("   \n", stdout);
		print_circle(&text_circ);
		fputs("   \x1B[F", stdout);
		fflush(stdout);

		usleep(SLEEP_TIME_US);
	}

	cleanup();
	return 0;
}