コード例 #1
0
ファイル: testAnim.c プロジェクト: jbornschein/farbborg
void upgoingRandom() {
	color curColor = {100, 100, 100};
	unsigned char i;
	unsigned short j;
	signed char addR = 2, addG = -1, addB = 4; 
	for (j = 0; j < 600; j++) {
		for (i = 0; i < j%8 + 4; i++) {
			curColor.r += addR;
			curColor.g += addG;
			curColor.b += addB;
			if (curColor.r < 10 || curColor.r > 245) 
				addR = -addR;
			if (curColor.g < 10 || curColor.g > 245) 
				addG = -addG;
			if (curColor.b < 10 || curColor.b > 245) 
				addB = -addB;
			setVoxel((voxel) {easyRandom()%5, easyRandom()%5, 0}, curColor);
		}
		fade(8, 16);
		shift(up);
		addR = (easyRandom() % 16) - 8;
		addG = (easyRandom() % 16) - 8;
		addB = (easyRandom() % 16) - 8;
	}
	clearImage(black);
	fade(10, 30);
	swapAndWait(1000);
}
コード例 #2
0
ファイル: testAnim.c プロジェクト: jbornschein/farbborg
void wobbeln() {
	unsigned char i, j, z, y, x;
	color colors[5] = {{0,   0,  250},
				   { 250,  150,    0},
				   {0xef, 0xae, 0x30},
				   {   0  ,250,   18},
				   { 255,   0,     0}
				  };
	for (j = 0; j < 30; j++) {
		for (i = 1; i < 6; i++) {
			for (z = 0; z < i; z++) {
				for (y = 0; y < i; y++) {
					for (x = 0; x < i; x++) {
						switch (j % 8) {
							case 0: 
								setVoxel((voxel) {x, y, z}, colors[j%5]);
								break;
							case 1:
								setVoxel((voxel) {4-x, y, z}, blue);
								break;
							case 2:
								setVoxel((voxel) {x, 4-y, z}, red);
								break;
							case 3:
								setVoxel((voxel) {4-x, 4-y, z}, green);
								break;
							case 4: 
								setVoxel((voxel) {x, y, 4-z}, white);
								break;
							case 5:
								setVoxel((voxel) {4-x, y, 4-z}, red);
								break;
							case 6:
								setVoxel((voxel) {x, 4-y, 4-z}, blue);
								break;
							case 7:
								setVoxel((voxel) {4-x, 4-y, 4-z}, green);
								break;
							
						}
					}
				}
			}
			fade(5, 9);
		}
		swapAndWait(300);
		if (j < 20)
			clearImage(black);	
	}
	clearImage(black);
	fade(10, 30);
	swapAndWait(1000);
}
コード例 #3
0
ファイル: testAnim.c プロジェクト: jbornschein/farbborg
/*  4 2 2 2 2 2  
 *  3 2 1 1 1 2
 *  2 2 1 0 1 2
 *  1 2 1 1 1 2
 *  0 2 2 2 2 2 
 *    0 1 2 3 4 
 */
void movingArrows() {
     unsigned char x, y, cnt, cnt2 = 0;
	 color colors[4] = {{255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 0}};
     color curColor = {0,0,0};
	 for (cnt = 0; cnt < 100; cnt++) {
         shift(up);
         for (x = 0; x < MAX_X; x++) {
             for (y = 0; y < MAX_Y; y++) {
				switch (cnt % 3) {
					case 0:
						if (x == 2 && y == 2) {
							curColor = colors[cnt2++ % 4];
							setVoxel((voxel) {x, y, 0}, curColor);
						} 
						break;
					case 1:
						if ((x == 1 || x == 3) && (y == 1 || y == 3)) {
							setVoxel((voxel) {x, y, 0}, 
									 (color) {curColor.r/2, curColor.g/2, 
											  curColor.b/2});
						}
						break;
					case 2:
						if ((x == 0 || x == 4) && (y == 0 || y == 4)) {
							setVoxel((voxel) {x, y, 0}, 
									 (color) {curColor.r/4, curColor.g/4, 
											  curColor.b/4});
						}
						break;
				}
			 }	
         }
         fade(10, 10);
     }
     clearImage(black);
	 fade(10, 50);
}
コード例 #4
0
ファイル: testAnim.c プロジェクト: jbornschein/farbborg
void testBlur() {
	int i, j;
	for (i = 0; i < 23; i++)
	{
		clearImage(black);
		for (j = 0; j < 23; j++) {
			setVoxel((voxel) {easyRandom()%5, easyRandom()%5, easyRandom()%5}, 
			         HtoRGB((easyRandom() << 23) | (easyRandom() << 15) | (easyRandom() << 7)));
		}
		
		blur();
		blur();
		normalize();
		//swapAndWait(1000);
		fade(35, 70);
	}
	clearImage(black);
	fade(23, 50);
}
コード例 #5
0
ファイル: testAnim.c プロジェクト: jbornschein/farbborg
void planeBall() {
	unsigned char x;
	clearScreen(black);
	// draw a red plane
	for (x = 0; x < 5; x++) {
		drawLine3D(x, 0, 1, 
		           x, 4, 1, red);
	}
	fade(5, 10);
	swapAndWait(1000);
	setVoxel((voxel) {2, 2, 5}, green);
	swapAndWait(100);
	setVoxel((voxel) {2, 2, 5}, black);
	setVoxel((voxel) {2, 2, 4}, green);
	swapAndWait(100);
	setVoxel((voxel) {2, 2, 4}, black);
	setVoxel((voxel) {2, 2, 3}, green);
	swapAndWait(100);
	setVoxel((voxel) {2, 2, 3}, black);
	setVoxel((voxel) {2, 2, 2}, green);
	swapAndWait(100);
	setVoxel((voxel) {2, 2, 2}, black);
	setVoxel((voxel) {2, 2, 3}, green);
	swapAndWait(100);
	setVoxel((voxel) {2, 2, 3}, black);
	setVoxel((voxel) {2, 2, 2}, green);
	swapAndWait(1000);
	clearImage(black);
	
	for (x = 0; x < 5; x++) {
		drawLine3D(x, 0, 0, 
		           x, 4, 2, red);
	}
	fade(5, 5);
	// now the ball has to roll to y = 0
	swapAndWait(400);
	setVoxel((voxel) {2, 2, 2}, black);
	setVoxel((voxel) {2, 1, 2}, green);
	swapAndWait(200);
	setVoxel((voxel) {2, 1, 2}, black);
	setVoxel((voxel) {2, 0, 1}, green);
		
	swapAndWait(1000);
	clearImage(black);
	
	for (x = 0; x < 5; x++) {
		drawLine3D(x, 0, 1, 
		           x, 4, 1, red);
	}
	setVoxel((voxel) {2, 0, 2}, green);
	fade(5, 5);
	swapAndWait(400);
	clearImage(black);
	for (x = 0; x < 5; x++) {
		drawLine3D(x, 0, 2, 
		           x, 4, 0, red);
	}
	setVoxel((voxel) {2, 0, 3}, green);
	fade(5, 5);
	swapAndWait(400);
	setVoxel((voxel) {2, 0, 3}, black);
	setVoxel((voxel) {2, 1, 2}, green);
	swapAndWait(200);
	setVoxel((voxel) {2, 1, 2}, black);
	setVoxel((voxel) {2, 2, 2}, green);
	swapAndWait(200);	
	setVoxel((voxel) {2, 2, 2}, black);
	setVoxel((voxel) {2, 3, 1}, green);
	swapAndWait(200);
	setVoxel((voxel) {2, 3, 1}, black);
	setVoxel((voxel) {2, 4, 1}, green);
	swapAndWait(200);
	setVoxel((voxel) {2, 2, 2}, black);
	setVoxel((voxel) {2, 3, 1}, green);
	swapAndWait(200);
	setVoxel((voxel) {2, 3, 1}, black);
	setVoxel((voxel) {2, 4, 1}, green);
	swapAndWait(200);
	
	swapAndWait(1000);
	clearImage(black);
	
	for (x = 0; x < 5; x++) {
		drawLine3D(x, 0, 1, 
		           x, 4, 1, red);
	}
	setVoxel((voxel) {2, 4, 2}, green);
	fade(5, 5);
}
コード例 #6
0
ファイル: testAnim.c プロジェクト: jbornschein/farbborg
void funkyBeat() {
	beat beats[31] = {// erster Takt
					  {chess,      White,   8}, 
				  	  {chessInv,   C2,     12},
					  {all,        Black,   4},
					  {blockDiagonal,        Red,     6},
					  {all,        Black,  10},	
					  {chess,      C1,     12},
					  {fade1,      Yellow, 16},
					  {chessInv,   C2,      8},
					  {chess,      Black,   8},
					  {blockDiagonal,   Red,     8},
					  {blockDown,       White,   8},
					  {smallCube,  Red,    12},
					  {chessInv,   Blue,    4},  
					  {all,        Green,   6},
					  {all,        Black,   2},
					  {chess,      Yellow,  8}, 
					  // zeiter Takt
					  {all,        Black,   8},
					  {smallCube,  White,  10},
					  {chess,      Black,   6},
					  {chessInv,   C3,      2},
					  {blockDiagonal,        Green,   8},
					  {smallCube,  Black,   8},
					  {chess,      Red,     8},
					  {all,        Black,   8},
					  {smallCube,  Yellow,  8},
					  {all,        Black,   8},
					  {fade1,       C2,     16},
					  {smallCube,  White,   4},
					  {chessInv,   Red,     6},
					  {blockUp,    Green,   2},
					  {chess,      C1,      8}
					};
	unsigned char i, j, b, x, y, z;
	color curColor;
	uint32_t *im;
	
	for (j = 0; j < 10; j++) {
		for (b = 0; b < 31; b++) {
			clearImage(black);
			switch (beats[b].bC) {
				case Black:
					curColor = black;
					break;
				case White:
					curColor = white;
					break;
				case Red:
					curColor = red;
					break;
				case Green:
					curColor = green;
					break;
				case Blue:
					curColor = blue;
					break;
				case Yellow:
					curColor = (color) {255, 255, 102};
					break;
				case C1:
					curColor = (color) {102, 102, 255};
					break;
				case C2:
					curColor = (color) {102, 102, 255};
					break;
				case C3:
					curColor = (color) {113, 120, 204};
					break;
			}
			switch (beats[b].pP) {
				case fade1:
				case all:
					clearImage(curColor);
					break;
					
				case chess:
					im = (uint32_t *) imag;
					for (i = 0; i < MAX_Z*MAX_Y*MAX_X; i++) {
						if (i & 1) {
							*im++ = curColor.r;
							*im++ = curColor.g;
							*im++ = curColor.b;
						} else {
							im += 3;
						}
					}	
					break;
					
				case chessInv:
					im = (uint32_t *) imag;
					for (i = 0; i < MAX_Z*MAX_Y*MAX_X; i++) {
						if (!(i & 1)) {
							*im++ = curColor.r;
							*im++ = curColor.g;
							*im++ = curColor.b;
						} else {
							im += 3;
						}
					}
					break;
					
				case smallCube:
					for (z = 1; z < 4; z++) {
						for (y = 1; y < 4; y++) {
							for (x = 1; x < 4; x++) {
								setVoxel((voxel) {x, y, z}, curColor);
							}
						}
					}
					break;
					
				case blockUp:
					for (z = 2; z < 5; z++) {
						for (y = 0; y < 5; y++) {
							for (x = 0; x < 5; x++) {
								setVoxel((voxel) {x, y, z}, curColor);
							}
						}
					}
					break;	
				
				case blockDown:
					for (z = 0; z < 3; z++) {
						for (y = 0; y < 5; y++) {
							for (x = 0; x < 5; x++) {
								setVoxel((voxel) {x, y, z}, curColor);
							}
						}
					}
					break;
					
				case blockRight:
					for (z = 0; z < 5; z++) {
						for (y = 2; y < 5; y++) {
							for (x = 0; x < 5; x++) {
								setVoxel((voxel) {x, y, z}, curColor);
							}
						}
					}
					break;
					
				case blockDiagonal:
					for (z = 0; z < 5; z++) {
						for (y = 0; y < 5; y++) {
							for (x = 0; x < 5; x++) {
								if ((x + y + z) < 6)
									setVoxel((voxel) {x, y, z}, curColor);
							}
						}
					}
					break;
			}
			
			if (beats[b].pP == fade1)
				fade(16, beats[b].time);
			else 
				swapAndWait(beats[b].time*16);
		}
	}
}
コード例 #7
0
ファイル: plasmaAnims.c プロジェクト: jbornschein/farbborg
//this asnimation features a nice plasmaball emerging from the borg's center
//a hollowed sphere is drawn by altering a voxels color-brightness depending on it's distance to the sphere's radius
//the color brightness weakening, and thus the sphere's hull thickness, which is in fact a gradient, is tuned by PLASBALL_M_FILTER, see top of file
//in other words, voxels which are too distant from the sphere, are weakened till they reach zero, producing a nice sphere in the video ram
void plasmaBall()
{
	int32_t col, scale;
	int32_t x, y, z;
	int sqx, sqy, distCalc;
	unsigned int dist;
	color colRGB;
	int dingsVal;

	scale = 10*0x5000;
	dist = 0;
	ioffset = 0;
	
	while (!false)
	{
		//clear backbuffer
		clearImage(black);
		
		//move plasma "forward"
		ioffset += 48;

		//dist is the ball's radius
		dist = (ioffset / 128) % 80;

		for(x = 0; x < MAX_X; x++)
		{
			//cache squared X
			sqx = SQUARE(x-2) * 256;
	
			for(y = 0; y < MAX_Y; y++)
			{
				sqy = SQUARE(y-2) * 256;
				
				for(z = 0; z < MAX_Z; z++)
				{
					//calculate distance to center and check against desired distance
					distCalc = isqrt(sqx + sqy + (z-2)*(z-2)*256);
					
					//reset color;
					col = 0;
					
					//diagonal scrolling sine 
					col += plasmaDiag(x, y, z, scale, ioffset);
				
					//colorspace offset
					col += 0x8000 + (ioffset/32);

					//calculate a voxel brightness (?) weakening value based on the distance to the balls outer hull
					dingsVal = abs((int)dist - distCalc);
					dingsVal *= 255 / PLASBALL_M_FILTER;
					if (dingsVal > 255)
						continue;
					
					//get the voxels rgb color value
					colRGB = HtoRGB(col);
					//alter the voxels brightness (?), without uint overflows ;-)
					colRGB.r = max((int)colRGB.r - dingsVal, 0);
					colRGB.g = max((int)colRGB.g - dingsVal, 0);
					colRGB.b = max((int)colRGB.b - dingsVal, 0);
					
					//finally draw the voxel
					setVoxel((voxel) {x, y, z}, colRGB);			
				} 
			}
		}

		//show frame
		swapAndWait(10);
		
		if((ioffset) >= PLASBALL_ITERATIONS * 0x8000)
			break;
	}
}
コード例 #8
0
ファイル: plasmaAnims.c プロジェクト: jbornschein/farbborg
void plasmaSnake()
{
	float scale = 4.0;
	
	voxel pixels[SNAKE_LEN]; 
	voxel *head = &pixels[1];
	voxel *tail = &pixels[0];
	voxel old_head;
	float snakeColor;
	voxel apples[10];
	unsigned char apple_num = 0;
	//char addR = 2, addG = -1, addB = 1;
	pixels[0].x = 1; 
	pixels[0].y = 1;
	pixels[0].z = 0;
	pixels[1].x = 1; 
	pixels[1].y = 2;
	pixels[1].z = 0;
	
	direction dir = forward;

	clearScreen(black);

	unsigned char x = 0, dead = 0;
	while (1) {
		offset += 0.09;
		x++;
		old_head = *head;
		if (++head == pixels + SNAKE_LEN) 
			head = pixels;
		
		unsigned char dead_cnt=0;
		
		unsigned char apple_found = 0, j;
		for (j = 0; j < apple_num; j++) {
			unsigned char i;
			for (i = 1; i < 7; i++) {
				if ((getNextVoxel(old_head, (direction)i).x == apples[j].x) && 
					(getNextVoxel(old_head, (direction)i).y == apples[j].y) &&
				    (getNextVoxel(old_head, (direction)i).z == apples[j].z)) {
					apple_found = 1;
					dir = (direction)i+1; 
					for(; j < apple_num-1; j++) {
						apples[j] = apples[j+1];
					}
					apple_num--;
					goto apple_se;
				}
			}
		}
		apple_se:
		if (!apple_found) {
			while (isVoxelSet(getNextVoxel(old_head, dir))) {
				if ((dead_cnt++) == 4) {
					dead = 1;
					break;
				}
				dir = direction_r(dir);
			}
		}
		if (!dead) {
			*head = getNextVoxel(old_head, dir);
			snakeColor = 0.5;
			snakeColor += 0.5 * sinf(((float)head->x * (PI / (fMAX_X * scale))) + ((float)head->y * (PI / (fMAX_Y * scale))) + ((float)head->z * (PI / (fMAX_Z * scale))) + offset);
			setVoxelH_f(head->x, head->y, head->z, snakeColor);
			if (easyRandom() < 80) {
				dir = 1 + (direction) (easyRandom() % 6);
			}
			if ((apple_num<10) && (easyRandom()<10)) {
				voxel new_apple = (voxel) {easyRandom() % MAX_X,
										   easyRandom() % MAX_Y,
										   easyRandom() % MAX_Z};
				if (!isVoxelSet(new_apple)){
					apples[apple_num++] = new_apple;
				}
			}
			if (!apple_found) {
				setVoxel(*tail, black);
				if (++tail == pixels + SNAKE_LEN) 
					tail = pixels;
			}
		} else {
			while (tail != head) {
				setVoxel(*tail, black);
				if ((++tail) > pixels + SNAKE_LEN) 
					tail = pixels;
			}
			break;
		}
		for (j = 0; j < apple_num; j++) {
			if (x & 1) { // let the apples blink
				snakeColor = 0.5;
				snakeColor += 0.5 * sinf(((float)apples[j].x * (PI / (fMAX_X * scale))) + ((float)apples[j].y * (PI / (fMAX_Y * scale))) + ((float)apples[j].z * (PI / (fMAX_Z * scale))) + offset);
				setVoxelH_f(apples[j].x, apples[j].y, apples[j].z, snakeColor);
			} else {
				setVoxel(apples[j], black);
			}
		}
		/*if (snakeColor.r < 5 || snakeColor.r > 250) 
			addR = -addR;
		if (snakeColor.g < 5 || snakeColor.g > 250) 
			addG = -addG;
		if (snakeColor.b < 5 || snakeColor.b > 250) 
			addB = -addB;
			
		snakeColor.r += addR;
		snakeColor.g += addG;
		snakeColor.b += addB;
		*/
		swapAndWait(90);
	}
}
コード例 #9
0
ファイル: plasmaAnims.c プロジェクト: jbornschein/farbborg
void plasmaSea()
{
	int32_t col, scale, tmpR, tmpG, tmpB;
	int32_t x, y, z, i;
	int sqx, sqy, dingsVal, borgDiameter, distCalc;
	color colRGB;
    plasmaSeaWaveList dummy;
	plasmaSeaWaveList *head = &dummy, *runner;
	
	//drops
	plasmaSeaDrop drops[PLASSEA_MAXDROPS];

	scale = 16;
	borgDiameter = BORGDIAMETER_XY;
	ioffset = 0;
	dummy.next = NULL;

	//iqnit all drops as "fallen", so they'll get initialized by the usual pseudorandomness
	for(i = 0; i < PLASSEA_MAXDROPS; i++)
	{	
        drops[i].vPos.x = (MAX_X - 1) / 2;
        drops[i].vPos.y = (MAX_Y - 1) / 2;
		drops[i].zDist = PLASSEA_ZDISTMAX + 16; //overshoot zdistmax, to be sure
	}
	
	while(!false)
	{
		//clear backbuffer
		clearImage(black);
		
		//move plasma "forward"
		ioffset += PLASSEA_PLASMASPEED;

		//advance the drops
		for(i = 0; i < PLASSEA_MAXDROPS; i++)
		{
            //is the drop in z=0 and has spawned no effect yet?
            if(!drops[i].spawnFlag && (drops[i].zDist > (PLASSEA_ZDISTMAX - PLASSEA_ZDIST_RESSCALE)))
            {
                drops[i].spawnFlag = 1;
                
            	//add a new wave to the list
				for(runner = head; runner->next != NULL; runner = runner->next);
				runner->next = (plasmaSeaWaveList *)malloc(sizeof(plasmaSeaWaveList));
				runner = runner->next;
				runner->next = NULL;
				
				runner->element.center.x = drops[i].vPos.x;
			    runner->element.center.y = drops[i].vPos.y;
				runner->element.center.z = 0;
				runner->element.pDist = 0;			
				//set a custom offset for the plasma colors
				runner->element.myIOff = 0;//rnd32;
		        runner->element.speed = drops[i].speed;
            }
			//is the drop already fallen?
			else if(drops[i].zDist > PLASSEA_ZDISTMAX)
			{
				//yes, spawn a new drop			
				drops[i].vPos.x = easyRandom() % MAX_X;
				drops[i].vPos.y = easyRandom() % MAX_Y;
				drops[i].speed = (easyRandom() % 2) + 1;
				//put drop somewehere in the non-visible range
				drops[i].zDist = easyRandom() % (PLASSEA_Z_HEADROOM * PLASSEA_ZDIST_RESSCALE);
				drops[i].spawnFlag = 0;
			}
			else
			{
				//no, add speed 
				drops[i].zDist += drops[i].speed;
			}
		}

		//advance and recycle waves
		for(runner = head; runner->next != NULL; runner = runner->next)
		{
            plasmaSeaWaveList *ltmp = (plasmaSeaWaveList *)runner->next;
            if(ltmp->element.pDist > PLASSEA_PDISTMAX)
            {
                //recycle
                runner->next = ltmp->next;
                free(ltmp);
                
                if(runner->next == NULL)
                    break;
            }
            else
    		{
                //add speed, but half as fast
                if(ioffset % (2*PLASSEA_PLASMASPEED) == 0)
                   ltmp->element.pDist += ltmp->element.speed;
            }
        }

		for(x = 0; x < MAX_X; x++)
		{
			//z = 0
			for(y = 0; y < MAX_Y; y++)
			{
                tmpR = 0; tmpG = 0; tmpB = 0;
                
                //for all waves
                for(runner = head; runner != NULL; runner = runner->next)
		        {                 
                    if((runner != head) && (runner->element.pDist <= PLASSEA_PDISTMAX))
                    {
                        //modified calculation with custom centerpoint
                        sqx = SQUARE(x - runner->element.center.x);
         				sqy = SQUARE(y - runner->element.center.y);
         				
         				//calculate distance to wave center
	                    distCalc = isqrt(sqx*SQUARE(PLASSEA_ZDIST_RESSCALE) + sqy*SQUARE(PLASSEA_ZDIST_RESSCALE));

        				//reset color;
        				col = 0;
        				
        				//diagonal scrolling sine 
        				col += plasmaPolarFlat(sqx, sqy, scale, borgDiameter, ioffset + runner->element.myIOff);
        			
        				//colorspace offset
        				col += 0x8000;
        				//col  = (col * 49152) / 0xFFFF;
        				
        				//some mystic scaling stolen from setVoxelH, this removes yet another color clipping effect
        				col = (col*49152)/32768;
        				
        				//calculate a voxel brightness (?) weakening value based on the distance to the balls outer hull
    					dingsVal = abs((int)runner->element.pDist - distCalc);
    					dingsVal *= 255 / PLASSEA_M_FILTER;
    					if (dingsVal > 255)
    						continue;
						
        				//get new voxels color
        				colRGB = HtoRGB(col);
        				//alter the voxels brightness (?), without uint overflows ;-)
                        colRGB.r = max((int)colRGB.r - dingsVal, 0);
         				colRGB.g = max((int)colRGB.g - dingsVal, 0);
		                colRGB.b = max((int)colRGB.b - dingsVal, 0);
        				
        				//finally add the new color
        				tmpR += colRGB.r; tmpG += colRGB.g; tmpB += colRGB.b;
                    }
                }
                
                //draw the voxel
                tmpR /= 2; tmpG /= 2; tmpB /= 2;
                colRGB.r = min(tmpR, 255);
                colRGB.g = min(tmpG, 255);
                colRGB.b = min(tmpB, 255);
                setVoxel((voxel) {x, y, 0}, colRGB);
                
                //normalize();
                    
				//for all drops
				for(i = 0; i < PLASSEA_MAXDROPS; i++)
				{                                     	
					//check if this drop is in our z-column
					if((drops[i].vPos.x == x) && (drops[i].vPos.y == y))
					{
						//if so, walk the z-range and see if we have to light up the pixel
						//see plasmaball for this technique
						for(z = 0; z < MAX_Z; z++)
						{
							dingsVal = abs((int)drops[i].zDist - ((4 - z + PLASSEA_Z_HEADROOM) * PLASSEA_ZDIST_RESSCALE));
							dingsVal *= 255 / PLASSEA_M_FILTER;
							if (dingsVal > 255)
								continue;
							
							//if(z == 0)
							//{
                                // colRGB.r = 0;
							   //  colRGB.g = 128;
							 //    colRGB.b = 255;
                            //}
                            //else
                            //{
    							//alter the voxels brightness (?), without uint overflows ;-)
    							colRGB.r = 0;//max(0 - dingsVal, 0);
    							colRGB.g = max(128 - dingsVal, 0);
    							colRGB.b = max(255 - dingsVal, 0);
                            //}
							
							//finally draw the voxel
							drops[i].vPos.z = z;
							setVoxel(drops[i].vPos, colRGB);					
						}
					}
				}
			}
		}

		//show frame
		swapAndWait(10);
		
		if((ioffset) >= PLASSEA_ITERATIONS * 0x8000)
			break;
	}
}
コード例 #10
0
ファイル: plasmaAnims.c プロジェクト: jbornschein/farbborg
void plasmaWave() {
	unsigned short data[5][5], l;
	unsigned char j, k, z, r, g ,b;
	int dingsVal, borgDiameter, sqy, sqx;
	unsigned int i;
	color colRGB;
	
	ioffset = 0;
	borgDiameter = BORGDIAMETER;
	
	//clear screen and backbuffer
	clearScreen(black);

	for (i = 0; i < WAVES_ITERATIONS; i++)
    {
        //advance plasma
        ioffset += WAVES_PLASMASPEED;
        
        //clear backbuffer
        clearImage(black);
        
        //calc z positions for one corner
        // x x x x x
        // 0 0 0 0 x
        // 0 0 0 0 x
        // 0 0 0 0 x
        // 0 0 0 0 x       
		for (j = 0; j < 5; j++) {
			l = Sine(j * (0x8000 / (MAX_Z-1)) + (i*WAVES_ANIMSPEED)) + 0x8000;
			data[j][0] = l;
			data[0][j] = l;
		}
		
		//multiplex data over whole plane
		for (j = 1; j < 5; j++) {
			for (k = 1; k < 5; k++) {
				data[j][k] = (data[j-1][k] + data[j][k-1] + data[j-1][k-1])/3;
			}
		}
        		
		//z-anti-aliasing
		for (j = 0; j < 5; j++)
        {
            sqy = ISQPY(j);
			for (k = 0; k < 5; k++)
            {   
                sqx = ISQPX(k);
                          
                //scale value (distcalc)
                data[j][k] = (data[j][k] * MAX_Z * WAVES_ZDIST_RESSCALE) / 0xFFFF;
                
 		        //walk the z-range and see if we have to light up the pixel
                //see plasmaball for this technique
                for(z = 0; z < MAX_Z; z++)
                {
                    unsigned int col;
                    //calc plasma
                    //strange glitches happen here..
                    col = ((plasmaPolar(sqx, sqy, ISQPZ(2*z), 12, borgDiameter, ioffset) + 0x8000) * 49152) / 0xFFFF;
                    col = (col*49152)/32768;
                    
                    colRGB = HtoRGB(col);
                                      
                    dingsVal = abs((int)data[j][k] - (z * WAVES_ZDIST_RESSCALE));
                    dingsVal = (dingsVal * 255) / WAVES_M_FILTER;
                    if (dingsVal > 255)
                    	continue;                                   		
                    
                    //alter the voxels brightness (?), without uint overflows ;-)
                    r = max((int)colRGB.r - dingsVal, 0);
                    g = max((int)colRGB.g - dingsVal, 0);
                    b = max((int)colRGB.b - dingsVal, 0);
                    
                    //finally draw the voxel
                    setVoxel((voxel){j, k, z}, (color){r, g, b});					
                }
			}
		}
		
		swapAndWait(8);
	}
}