Ejemplo n.º 1
0
void main() {
  allegrosetup(scrwid,scrhei);
  makesplitpalette(&redtowhitepalette,&greentowhitepalette);
  PPsetup(scrwid,scrhei,4);
  JBmp j=JBmp(scrwid,scrhei);
  j.clear();
  List<Part> ps=List<Part>();
  for (int i=1;i<=10;i++) {
    Part p;
    newpart(&p);
    ps+p;
  }
  int frame=0;
  do {
    for (int i=1;i<=ps.len;i++) {
      Part *p=ps.p2num(i);
      int sx,sy;
      PPgetscrpos(p->pos,&sx,&sy);
      int sxb,syb;
      PPgetscrpos(p->pos+V3d(p->rad,0,0),&sxb,&syb);
      float rad=sqrt(mysquare(sx-sxb)+mysquare(sy-syb));
      j.filledcircle(sx,sy,rad,p->inc);
//      j.filledcirclenodarker(sx,sy,rad/3,p->inc);
    }
    for (int x=0;x<scrwid;x++)
      for (int y=0;y<scrhei;y++) {
        int k=j.bmp[y][x];
        if (k==128)
          j.bmp[y][x]=0;
        if (k<128)
          j.bmp[y][x]=chop(k-4,0,128);
        else
          j.bmp[y][x]=128+chop(k-4-128,0,128);
      }
    j.writetoscreen();
    Matrix m,n;
    V3d rotaxis=V3d::rotate(V3d(0,1,0),V3d(0,0,1),pi/4.0*sin(2*pi*frame/4000));
    m.makerotation(rotaxis,pi/1000.0);
    n.makerotation(rotaxis,-pi/1000.0);
    for (int i=1;i<=ps.len;i++) {
      Part *p=ps.p2num(i);
      if (p->sgn>0)
        p->pos=m*p->pos;
      else
        p->pos=n*p->pos;
      p->pos=p->pos+V3d(0,0,-0.03);
      if (p->pos.z<-4 || max(myabs(p->pos.x),myabs(p->pos.y))>2)
        newpart(p);
    }
    frame++;
  } while (!key[KEY_ESC]);
}
Ejemplo n.º 2
0
int main(String *argv,int argc) {
  int i;
  allegrosetup(scrwid,scrhei);
  for (i=0;i<numparts;i++) {
    newpart(i);
  }
  while (!key[KEY_ESC]) {
    for (i=0;i<numparts;i++) {
      movepart(i);
    }
  }
  allegro_exit();
}
Ejemplo n.º 3
0
int main(String *argv,int argc) {
  int i;
  allegrosetup(scrwid,scrhei);
  mypalette(0,0,0,0);
  mypalette(255,1,1,1);
  if (glasses) {
  mypalette(128,0,0,0);
  for (i=1;i<128;i++) {
    mypalette(i,0.3+0.4*i/128,0,0);
    mypalette(128+i,0,0.3+0.5*i/128,0);
  }
  }
  for (i=0;i<numparts;i++) {
    part[i].gwell=0;
    newpart(i);
  }
  while (!key[KEY_ESC]) {
    for (i=0;i<numparts;i++) {
      movepart(i);
    }
  }
  allegro_exit();
}
Ejemplo n.º 4
0
void movepart(int i) {
  int j;
  //xor_mode(0);
  if (plotpart(i,0)==0 || part[i].pos.z<znear || part[i].pos.z>zfar)
    newpart(i);
  // Brownian motion
  if (myrnd()<pbrownian) {
  part[i].vel.x=part[i].vel.x+floatrnd(-brownian,brownian);
  part[i].vel.y=part[i].vel.y+floatrnd(-brownian,brownian);
  part[i].vel.z=part[i].vel.z+floatrnd(-brownian,brownian);
  }
  if (part[i].gwell<0.5) {
    // Pulled by gravity wells
    for (j=0;j<gwells;j++) {
      // Gravity well j affects particle i
      if (gwell[j]!=i)
        part[i].vel=V3dadd(part[i].vel,V3dmult(part[gwell[j]].gwell/(V3ddist(part[gwell[j]].pos,part[i].pos)+1)*gwellstr,V3dnorm(V3dsub(part[gwell[j]].pos,part[i].pos))));
    }
  } else {
    // Warping towards user
    part[i].vel.z=part[i].vel.z-warpvel;
  }
  // Damping
  part[i].vel=V3dmult(dampening,part[i].vel);
  // Movement
  part[i].pos=V3dadd(part[i].pos,part[i].vel);
  /* Bouncing off the walls
  if (myabs(part[i].pos.x)>1)
    part[i].vel.x=-part[i].vel.x;
  if (myabs(part[i].pos.y)>1)
    part[i].vel.y=-part[i].vel.y;
  if (myabs(part[i].pos.z)>1)
    part[i].vel.z=-part[i].vel.z;*/
  //xor_mode(1);
  plotpart(i,255);
}
Ejemplo n.º 5
0
/*
 * Parse one partition definition for an MTD. Since there can be many
 * comma separated partition definitions, this function calls itself
 * recursively until no more partition definitions are found. Nice side
 * effect: the memory to keep the mtd_partition structs and the names
 * is allocated upon the last definition being found. At that point the
 * syntax has been verified ok.
 */
static struct mtd_partition * newpart(char *s,
                                      char **retptr,
                                      int *num_parts,
                                      int this_part,
                                      unsigned char **extra_mem_ptr,
                                      int extra_mem_size)
{
	struct mtd_partition *parts;
	unsigned long size;
	unsigned long offset = 0;
	char *name;
	int name_len;
	unsigned char *extra_mem;
	char delim;
	unsigned int mask_flags;

	/* fetch the partition size */
	if (*s == '-')
	{	/* assign all remaining space to this partition */
		size = SIZE_REMAINING;
		s++;
	}
	else
	{
		size = memparse(s, &s);
		if (size < PAGE_SIZE)
		{
			printk(KERN_ERR ERRP "partition size too small (%lx)\n", size);
			return NULL;
		}
	}

	/* fetch partition name and flags */
	mask_flags = 0; /* this is going to be a regular partition */
	delim = 0;
        /* check for offset */
        if (*s == '@')
	{
                s++;
                offset = memparse(s, &s);
        }
        /* now look for name */
	if (*s == '(')
	{
		delim = ')';
	}

	if (delim)
	{
		char *p;

	    	name = ++s;
		if ((p = strchr(name, delim)) == 0)
		{
			printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim);
			return NULL;
		}
		name_len = p - name;
		s = p + 1;
	}
	else
	{
	    	name = NULL;
		name_len = 13; /* Partition_000 */
	}

	/* record name length for memory allocation later */
	extra_mem_size += name_len + 1;

        /* test for options */
        if (strncmp(s, "ro", 2) == 0)
	{
		mask_flags |= MTD_WRITEABLE;
		s += 2;
        }

	/* test if more partitions are following */
	if (*s == ',')
	{
		if (size == SIZE_REMAINING)
		{
			printk(KERN_ERR ERRP "no partitions allowed after a fill-up partition\n");
			return NULL;
		}
		/* more partitions follow, parse them */
		if ((parts = newpart(s + 1, &s, num_parts,
		                     this_part + 1, &extra_mem, extra_mem_size)) == 0)
		  return NULL;
	}
	else
	{	/* this is the last partition: allocate space for all */
		int alloc_size;

		*num_parts = this_part + 1;
		alloc_size = *num_parts * sizeof(struct mtd_partition) +
			     extra_mem_size;
		parts = kmalloc(alloc_size, GFP_KERNEL);
		if (!parts)
		{
			printk(KERN_ERR ERRP "out of memory\n");
			return NULL;
		}
		memset(parts, 0, alloc_size);
		extra_mem = (unsigned char *)(parts + *num_parts);
	}
	/* enter this partition (offset will be calculated later if it is zero at this point) */
	parts[this_part].size = size;
	parts[this_part].offset = offset;
	parts[this_part].mask_flags = mask_flags;
	if (name)
	{
		strlcpy(extra_mem, name, name_len + 1);
	}
	else
	{
		sprintf(extra_mem, "Partition_%03d", this_part);
	}
	parts[this_part].name = extra_mem;
	extra_mem += name_len + 1;

	dbg(("partition %d: name <%s>, offset %x, size %x, mask flags %x\n",
	     this_part,
	     parts[this_part].name,
	     parts[this_part].offset,
	     parts[this_part].size,
	     parts[this_part].mask_flags));

	/* return (updated) pointer to extra_mem memory */
	if (extra_mem_ptr)
	  *extra_mem_ptr = extra_mem;

	/* return (updated) pointer command line string */
	*retptr = s;

	/* return partition table */
	return parts;
}
Ejemplo n.º 6
0
/*
 * Parse the command line.
 */
static int mtdpart_setup_real(char *s)
{
	cmdline_parsed = 1;

	for( ; s != NULL; )
	{
		struct cmdline_mtd_partition *this_mtd;
		struct mtd_partition *parts;
	    	int mtd_id_len;
		int num_parts;
		char *p, *mtd_id;

	    	mtd_id = s;
		/* fetch <mtd-id> */
		if (!(p = strchr(s, ':')))
		{
			printk(KERN_ERR ERRP "no mtd-id\n");
			return 0;
		}
		mtd_id_len = p - mtd_id;

		dbg(("parsing <%s>\n", p+1));

		/*
		 * parse one mtd. have it reserve memory for the
		 * struct cmdline_mtd_partition and the mtd-id string.
		 */
		parts = newpart(p + 1,		/* cmdline */
				&s,		/* out: updated cmdline ptr */
				&num_parts,	/* out: number of parts */
				0,		/* first partition */
				(unsigned char**)&this_mtd, /* out: extra mem */
				mtd_id_len + 1 + sizeof(*this_mtd) +
				sizeof(void*)-1 /*alignment*/);
		if(!parts)
		{
			/*
			 * An error occurred. We're either:
			 * a) out of memory, or
			 * b) in the middle of the partition spec
			 * Either way, this mtd is hosed and we're
			 * unlikely to succeed in parsing any more
			 */
			 return 0;
		 }

		/* align this_mtd */
		this_mtd = (struct cmdline_mtd_partition *)
			ALIGN((unsigned long)this_mtd, sizeof(void*));
		/* enter results */
		this_mtd->parts = parts;
		this_mtd->num_parts = num_parts;
		this_mtd->mtd_id = (char*)(this_mtd + 1);
		strlcpy(this_mtd->mtd_id, mtd_id, mtd_id_len + 1);

		/* link into chain */
		this_mtd->next = partitions;
		partitions = this_mtd;

		dbg(("mtdid=<%s> num_parts=<%d>\n",
		     this_mtd->mtd_id, this_mtd->num_parts));


		/* EOS - we're done */
		if (*s == 0)
			break;

		/* does another spec follow? */
		if (*s != ';')
		{
			printk(KERN_ERR ERRP "bad character after partition (%c)\n", *s);
			return 0;
		}
		s++;
	}
	return 1;
}
Ejemplo n.º 7
0
/* 
 * Parse the command line. 
 */
static int mtdpart_setup_real(char *s)
{
	cmdline_parsed = 1;

	for( ; s != NULL; )
	{
		struct cmdline_mtd_partition *this_mtd;
		struct mtd_partition *parts;
	    	int mtd_id_len;
		int num_parts;
		char *p, *mtd_id;

	    	mtd_id = s;
		/* fetch <mtd-id> */
		if (!(p = strchr(s, ':')))
		{
			printk(KERN_ERR ERRP "no mtd-id\n");
			return 0;
		}
		mtd_id_len = p - mtd_id;

		dbg(("parsing <%s>\n", p+1));

		/* 
		 * parse one mtd. have it reserve memory for the
		 * struct cmdline_mtd_partition and the mtd-id string.
		 */
		parts = newpart(p + 1,		/* cmdline */
				&s,		/* out: updated cmdline ptr */
				&num_parts,	/* out: number of parts */
				0,		/* first partition */
				(unsigned char**)&this_mtd, /* out: extra mem */
				mtd_id_len + 1 + sizeof(*this_mtd));

		/* enter results */	    
		this_mtd->parts = parts;
		this_mtd->num_parts = num_parts;
		this_mtd->mtd_id = (char*)(this_mtd + 1);
		strncpy(this_mtd->mtd_id, mtd_id, mtd_id_len);
		this_mtd->mtd_id[mtd_id_len] = 0;

		/* link into chain */
		this_mtd->next = partitions;	    	
		partitions = this_mtd;

		dbg(("mtdid=<%s> num_parts=<%d>\n", 
		     this_mtd->mtd_id, this_mtd->num_parts));
		

		/* EOS - we're done */
		if (*s == 0)
			break;

		/* does another spec follow? */
		if (*s != ';')
		{
			printk(KERN_ERR ERRP "bad character after partition (%c)\n", *s);
			return 0;
		}
		s++;
	}
	return 1;
}
Ejemplo n.º 8
0
static struct mtd_partition * newpart(char *s,
                                      char **retptr,
                                      int *num_parts,
                                      int this_part,
                                      unsigned char **extra_mem_ptr,
                                      int extra_mem_size)
{
	struct mtd_partition *parts;
	unsigned long size;
	unsigned long offset = OFFSET_CONTINUOUS;
	char *name;
	int name_len;
	unsigned char *extra_mem;
	char delim;
	unsigned int mask_flags;

	/* fetch the partition size */
	if (*s == '-')
	{	/* assign all remaining space to this partition */
		size = SIZE_REMAINING;
		s++;
	}
	else
	{
		size = memparse(s, &s);
		if (size < PAGE_SIZE)
		{
			printf("partition size too small (%lx)\n", size);
			return 0;
		}
	}

	/* fetch partition name and flags */
	mask_flags = 0; /* this is going to be a regular partition */
	delim = 0;
        /* check for offset */
        if (*s == '@')
	{
                s++;
                offset = memparse(s, &s);
        }
        /* now look for name */
	if (*s == '(')
	{
		delim = ')';
	}

	if (delim)
	{
		char *p;

	    	name = ++s;
		p = strchr(name, delim);
		if (!p)
		{
			printf("no closing %c found in partition name\n", delim);
			return 0;
		}
		name_len = p - name;
		s = p + 1;
	}
	else
	{
	    	name = 0;
		name_len = 13; /* Partition_000 */
	}

	/* record name length for memory allocation later */
	extra_mem_size += name_len + 1;

        /* test for options */
        if (strncmp(s, "ro", 2) == 0)
	{
		mask_flags |= MTD_WRITEABLE;
		s += 2;
        }

        /* if lk is found do NOT unlock the MTD partition*/
        if (strncmp(s, "lk", 2) == 0)
	{
		mask_flags |= MTD_POWERUP_LOCK;
		s += 2;
        }

	/* test if more partitions are following */
	if (*s == ',')
	{
		if (size == SIZE_REMAINING)
		{
			printf("no partitions allowed after a fill-up partition\n");
			return 0;
		}
		/* more partitions follow, parse them */
		parts = newpart(s + 1, &s, num_parts, this_part + 1,
				&extra_mem, extra_mem_size);
		if (!parts)
			return 0;
	}
	else
	{	/* this is the last partition: allocate space for all */
		int alloc_size;

		*num_parts = this_part + 1;
		alloc_size = *num_parts * sizeof(struct mtd_partition) +
			     extra_mem_size;
		parts = (struct mtd_partition *)malloc(alloc_size);
		if (!parts)
		{
			printf("out of memory\n");
			return 0;
		}
		extra_mem = (unsigned char *)(parts + *num_parts);
	}
	/* enter this partition (offset will be calculated later if it is zero at this point) */
	parts[this_part].size = size;
	parts[this_part].offset = offset;
	parts[this_part].mask_flags = mask_flags;
	if (name)
	{
		strlcpy(extra_mem, name, name_len + 1);
	}
	else
	{
		sprintf(extra_mem, "Partition_%03d", this_part);
	}
	parts[this_part].name = extra_mem;
	extra_mem += name_len + 1;

	/*printf("partition %02d: name <%14s>, offset %08x, size %08x, mask flags %08x\n",
	     this_part,
	     parts[this_part].name,
	     parts[this_part].offset,
	     parts[this_part].size,
	     parts[this_part].mask_flags);*/
	
	     if (current_part >= 0) {
		current_part --;
		memset(&(realpartname[current_part]), 0, 255);
		strcpy(realpartname[current_part], parts[this_part].name);
		realpart[current_part].name = realpartname[current_part];
		//printf("realname = %14s  partname = %14s\n", realpart[current_part].name, parts[this_part].name);
		realpart[current_part].offset = parts[this_part].offset;
		realpart[current_part].size = parts[this_part].size;
	    } else
		printf("mtdparts partition is too much\n");


	/* return (updated) pointer to extra_mem memory */
	if (extra_mem_ptr)
	  *extra_mem_ptr = extra_mem;

	/* return (updated) pointer command line string */
	*retptr = s;

	/* return partition table */
	return parts;
}
Ejemplo n.º 9
0
void main() {
  allegrosetup(scrwid,scrhei);
  makesplitpalette(&redtowhitepalette,&greentowhitepalette);
  PPsetup(scrwid,scrhei,4);
  JBmp j=JBmp(scrwid,scrhei);
  j.clear();
  JBmp k=JBmp(scrwid,scrhei);
  k.clear();
  JBmp l=JBmp(scrwid,scrhei);
  l.clear();
  List<Part> ps=List<Part>();
  for (int i=1;i<=20;i++) {
    Part p;
    newpart(&p);
    ps+p;
  }
  int frame=0;
  do {
    for (int i=1;i<=ps.len;i++) {
      Part *p=ps.p2num(i);
      int sx,sy;
      PPgetscrpos(p->pos,&sx,&sy);
      int sxb,syb;
      PPgetscrpos(p->pos+V3d(p->rad,0,0),&sxb,&syb);
      float rad=sqrt(mysquare(sx-sxb)+mysquare(sy-syb));
      if (p->sgn>0)
        j.addcircle(sx,sy,rad,p->c);
      else
        k.addcircle(sx,sy,rad,p->c);
    }
    for (int x=0;x<scrwid;x++)
      for (int y=0;y<scrhei;y++) {
        if (j.bmp[y][x]>=3)
          j.bmp[y][x]-=3;
        if (k.bmp[y][x]>=3)
          k.bmp[y][x]-=3;
        int c=j.bmp[y][x]/2.0;
        int d=k.bmp[y][x]/2.0;
        if (c>d)
          l.bmp[y][x]=c;
        else
          l.bmp[y][x]=128+d;
      }
    l.writetoscreen();
    Matrix m,n;
    V3d rotaxis=V3d::rotate(V3d(0,1,0),V3d(0,0,1),pi/4.0*sin(2*pi*frame/4000));
    m.makerotation(rotaxis,pi/1000.0);
    n.makerotation(rotaxis,-pi/1000.0);
    for (int i=1;i<=ps.len;i++) {
      Part *p=ps.p2num(i);
      if (p->sgn>0)
        p->pos=m*p->pos;
      else
        p->pos=n*p->pos;
      p->pos=p->pos+V3d(0,0,-0.03);
      if (p->pos.z<-4 || max(myabs(p->pos.x),myabs(p->pos.y))>2)
        newpart(p);
    }
    frame++;
  } while (!key[KEY_ESC]);
}
Ejemplo n.º 10
0
/*
 * Parse one partition definition for an MTD. Since there can be many
 * comma separated partition definitions, this function calls itself
 * recursively until no more partition definitions are found. Nice side
 * effect: the memory to keep the mtd_partition structs and the names
 * is allocated upon the last definition being found. At that point the
 * syntax has been verified ok.
 */
static struct mtd_partition * newpart(char *s,
				      char **retptr,
				      int *num_parts,
				      int this_part,
				      unsigned char **extra_mem_ptr,
				      int extra_mem_size)
{
	struct mtd_partition *parts;
	unsigned long long size, offset = OFFSET_CONTINUOUS;
	char *name;
	int name_len;
	unsigned char *extra_mem;
	char delim;
	unsigned int mask_flags;

	/* fetch the partition size */
	if (*s == '-') {
		/* assign all remaining space to this partition */
		size = SIZE_REMAINING;
		s++;
	} else {
		size = memparse(s, &s);
		if (!size) {
			pr_err("partition has size 0\n");
			return ERR_PTR(-EINVAL);
		}
	}

	/* fetch partition name and flags */
	mask_flags = 0; /* this is going to be a regular partition */
	delim = 0;

	/* check for offset */
	if (*s == '@') {
		s++;
		offset = memparse(s, &s);
	}

	/* now look for name */
	if (*s == '(')
		delim = ')';

	if (delim) {
		char *p;

		name = ++s;
		p = strchr(name, delim);
		if (!p) {
			pr_err("no closing %c found in partition name\n", delim);
			return ERR_PTR(-EINVAL);
		}
		name_len = p - name;
		s = p + 1;
	} else {
		name = NULL;
		name_len = 13; /* Partition_000 */
	}

	/* record name length for memory allocation later */
	extra_mem_size += name_len + 1;

	/* test for options */
	if (strncmp(s, "ro", 2) == 0) {
		mask_flags |= MTD_WRITEABLE;
		s += 2;
	}

	/* if lk is found do NOT unlock the MTD partition*/
	if (strncmp(s, "lk", 2) == 0) {
		mask_flags |= MTD_POWERUP_LOCK;
		s += 2;
	}

	/* test if more partitions are following */
	if (*s == ',') {
		if (size == SIZE_REMAINING) {
			pr_err("no partitions allowed after a fill-up partition\n");
			return ERR_PTR(-EINVAL);
		}
		/* more partitions follow, parse them */
		parts = newpart(s + 1, &s, num_parts, this_part + 1,
				&extra_mem, extra_mem_size);
		if (IS_ERR(parts))
			return parts;
	} else {
		/* this is the last partition: allocate space for all */
		int alloc_size;

		*num_parts = this_part + 1;
		alloc_size = *num_parts * sizeof(struct mtd_partition) +
			     extra_mem_size;

		parts = kzalloc(alloc_size, GFP_KERNEL);
		if (!parts)
			return ERR_PTR(-ENOMEM);
		extra_mem = (unsigned char *)(parts + *num_parts);
	}

	/*
	 * enter this partition (offset will be calculated later if it is
	 * OFFSET_CONTINUOUS at this point)
	 */
	parts[this_part].size = size;
	parts[this_part].offset = offset;
	parts[this_part].mask_flags = mask_flags;
	if (name)
		strlcpy(extra_mem, name, name_len + 1);
	else
		sprintf(extra_mem, "Partition_%03d", this_part);
	parts[this_part].name = extra_mem;
	extra_mem += name_len + 1;

	dbg(("partition %d: name <%s>, offset %llx, size %llx, mask flags %x\n",
	     this_part, parts[this_part].name, parts[this_part].offset,
	     parts[this_part].size, parts[this_part].mask_flags));

	/* return (updated) pointer to extra_mem memory */
	if (extra_mem_ptr)
		*extra_mem_ptr = extra_mem;

	/* return (updated) pointer command line string */
	*retptr = s;

	/* return partition table */
	return parts;
}