Ejemplo n.º 1
0
void				Map::generate_map()
{
  std::ofstream			debug;
  Leaf				_root = Leaf(Size(0, 0), Size(map_size.x, map_size.y));
  std::vector<Rooms>		tmpRooms;

  if (_seed != -1)
    srand(_seed);
  else
    srand(time(NULL));
  debug.open("map.txt");
  _leafs.push_back(_root);
  split();
  for(size_t i = 0; i < _leafs.size();i++)
    _leafs[i].create_rooms(tmpRooms, room_max_size);
  for (int i = 0; i < room_nbr;i++)
    _rooms.push_back(tmpRooms[rand() % tmpRooms.size()]);
  for(size_t i = 0; i < _leafs.size();i++)
    {
      delete(_leafs[i].leftChild);
      delete(_leafs[i].rightChild);
    }
  blank_map();
  draw_rooms();
  draw_better_walls();
  draw_hallways();
  draw_in_out();
  draw_hallways_walls();
  draw_angles();
  for (size_t i = 0; i < _map.size() ; i++)
    debug << _map[i] << std::endl;
  debug.close();
}
Ejemplo n.º 2
0
void scope_paint(t_scope *x, t_object *view)
{
	t_rect rect;
	jbox_get_rect_for_view((t_object *)x, view, &rect);
	
	x->f_center.x = rect.width * .5;
	x->f_center.y = rect.height * .5;
	
	x->f_rayonGlobal = rect.width * .5;
	if(rect.width > rect.height)
		x->f_rayonGlobal = rect.height * .5;
	
	x->f_fontsize = (x->f_rayonGlobal / 14.) - 1.;
	x->f_rayonAngle = 5. / 6. * x->f_rayonGlobal + x->f_fontsize * 1.5;
	x->f_rayonCircle = x->f_rayonGlobal / 6;
	
	if (x->f_drawCircle) draw_background(x, view, &rect);
    if (x->f_drawAngles) draw_angles(x, view, &rect);
    if (x->f_drawContributions) draw_contribution(x, view, &rect);
    draw_harmonics(x, view, &rect);
}
Ejemplo n.º 3
0
static unsigned long
truchet_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;

  if (st->scrolling)
    {
      st->scrolling--;
      scroll_area(st, st->anim_step_size);
      return st->anim_delay*1000;
    }

  if (!mono_p)
    {
      /* XXX there are probably bugs with this. */
      /* could be...I just borrowed this code from munch */

      st->fgc.red = random() % 65535;
      st->fgc.green = random() % 65535;
      st->fgc.blue = random() % 65535;
	
      if (XAllocColor(st->dpy, st->cmap, &st->fgc)) 
        {
          XSetForeground(st->dpy, st->agc, st->fgc.pixel);
        }
      else
        {
          /* use white if all else fails  */
          XSetForeground(st->dpy,st->agc, st->gcv.background);
        }
    }

      
      

  /* generate a random line width */
  st->linewidth=(random()% st->maxlinewidth);

  /* check for lower bound */
  if(st->linewidth < st->minlinewidth)
    st->linewidth = st->minlinewidth;

  /* try to get an odd linewidth as it seem to work a little better */
  if(st->linewidth%2)
    st->linewidth++;

  /* grab a random height and width */ 
  st->width=(random()%st->max_width);
  st->height=(random()%st->max_height);

  /* make sure we dont get a 0 height or width */
  if(st->width == 0 || st->height == 0)
    {
      st->height=st->max_height;
      st->width=st->max_width;
    }


  /* check for min height and width */
  if(st->height < st->minheight)
    {
      st->height=st->minheight;
    }
  if(st->width < st->minwidth)
    {
      st->width=st->minwidth;
    }

  /* if tiles need to be square, fix it... */
  if(st->square)
    st->height=st->width;

  /* check for sane aspect ratios */
  if((st->width/st->height) > MAXRATIO) 
    st->height=st->width;
  if((st->height/st->width) > MAXRATIO)
    st->width=st->height;
      
  /* to avoid linewidths of zero */
  if(st->linewidth == 0 || st->linewidth < st->minlinewidth)
    st->linewidth = st->minlinewidth;

  /* try to keep from getting line widths that would be too big */
  if(st->linewidth > 0 && st->linewidth >= (st->height/5))
    st->linewidth = st->height/5;
  
  XSetLineAttributes(st->dpy, st->agc, st->linewidth, LineSolid, CapRound, JoinRound);

  if(st->erase || (st->count >= st->eraseCount))
    {
      /*  XClearWindow(dpy,window); */
      XFillRectangle(st->dpy, st->frame, st->bgc, 0, 0, st->xgwa.width+st->overlap, st->xgwa.height+st->overlap);
      st->count=0;
    }
            
  if(!st->scroll)
    st->overlap=0;
            
  /* do the fun stuff...*/
  if(st->curves && st->angles)
    {
      if(random()%2)
        draw_truchet(st);
      else
        draw_angles(st);
    }
  else if(st->curves && !st->angles)
    draw_truchet(st);
  else if(!st->curves && st->angles)
    draw_angles(st);

   
  st->count++;

  if(st->scroll)
    {
      st->scrolling = ((st->overlap / 4) / st->anim_step_size) * 4;
      return 0;
    }

  XCopyArea(st->dpy,st->frame,st->window,st->agc,0,0,st->xgwa.width,st->xgwa.height,0,0);

  return st->delay;
}