mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 05:39:18 +01:00
Removing Topics from SVN
This commit is contained in:
@@ -1,112 +0,0 @@
|
||||
/**
|
||||
* Fire Cube demo effect
|
||||
* by luis2048.
|
||||
*
|
||||
* A rotating wireframe cube with flames rising up the screen.
|
||||
* The fire effect has been used quite often for oldskool demos.
|
||||
* First you create a palette of 256 colors ranging from red to
|
||||
* yellow (including black). For every frame, calculate each row
|
||||
* of pixels based on the two rows below it: The value of each pixel,
|
||||
* becomes the sum of the 3 pixels below it (one directly below, one
|
||||
* to the left, and one to the right), and one pixel directly two
|
||||
* rows below it. Then divide the sum so that the fire dies out as
|
||||
* it rises.
|
||||
*/
|
||||
|
||||
// This will contain the pixels used to calculate the fire effect
|
||||
int[][] fire;
|
||||
|
||||
// Flame colors
|
||||
color[] palette;
|
||||
float angle;
|
||||
int[] calc1,calc2,calc3,calc4,calc5;
|
||||
|
||||
PGraphics pg;
|
||||
|
||||
void setup(){
|
||||
size(640, 360, P2D);
|
||||
|
||||
// Create buffered image for 3d cube
|
||||
pg = createGraphics(width, height, P3D);
|
||||
|
||||
calc1 = new int[width];
|
||||
calc3 = new int[width];
|
||||
calc4 = new int[width];
|
||||
calc2 = new int[height];
|
||||
calc5 = new int[height];
|
||||
|
||||
colorMode(HSB);
|
||||
|
||||
fire = new int[width][height];
|
||||
palette = new color[255];
|
||||
|
||||
// Generate the palette
|
||||
for(int x = 0; x < palette.length; x++) {
|
||||
//Hue goes from 0 to 85: red to yellow
|
||||
//Saturation is always the maximum: 255
|
||||
//Lightness is 0..255 for x=0..128, and 255 for x=128..255
|
||||
palette[x] = color(x/3, 255, constrain(x*3, 0, 255));
|
||||
}
|
||||
|
||||
// Precalculate which pixel values to add during animation loop
|
||||
// this speeds up the effect by 10fps
|
||||
for (int x = 0; x < width; x++) {
|
||||
calc1[x] = x % width;
|
||||
calc3[x] = (x - 1 + width) % width;
|
||||
calc4[x] = (x + 1) % width;
|
||||
}
|
||||
|
||||
for(int y = 0; y < height; y++) {
|
||||
calc2[y] = (y + 1) % height;
|
||||
calc5[y] = (y + 2) % height;
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
angle = angle + 0.05;
|
||||
|
||||
// Rotating wireframe cube
|
||||
pg.beginDraw();
|
||||
pg.translate(width >> 1, height >> 1);
|
||||
pg.rotateX(sin(angle/2));
|
||||
pg.rotateY(cos(angle/2));
|
||||
pg.background(0);
|
||||
pg.stroke(128);
|
||||
pg.scale(25);
|
||||
pg.noFill();
|
||||
pg.box(4);
|
||||
pg.endDraw();
|
||||
|
||||
// Randomize the bottom row of the fire buffer
|
||||
for(int x = 0; x < width; x++)
|
||||
{
|
||||
fire[x][height-1] = int(random(0,190)) ;
|
||||
}
|
||||
|
||||
loadPixels();
|
||||
|
||||
int counter = 0;
|
||||
// Do the fire calculations for every pixel, from top to bottom
|
||||
for (int y = 0; y < height; y++) {
|
||||
for(int x = 0; x < width; x++) {
|
||||
// Add pixel values around current pixel
|
||||
|
||||
fire[x][y] =
|
||||
((fire[calc3[x]][calc2[y]]
|
||||
+ fire[calc1[x]][calc2[y]]
|
||||
+ fire[calc4[x]][calc2[y]]
|
||||
+ fire[calc1[x]][calc5[y]]) << 5) / 129;
|
||||
|
||||
// Output everything to screen using our palette colors
|
||||
pixels[counter] = palette[fire[x][y]];
|
||||
|
||||
// Extract the red value using right shift and bit mask
|
||||
// equivalent of red(pg.pixels[x+y*w])
|
||||
if ((pg.pixels[counter++] >> 16 & 0xFF) == 128) {
|
||||
// Only map 3D cube 'lit' pixels onto fire array needed for next frame
|
||||
fire[x][y] = 128;
|
||||
}
|
||||
}
|
||||
}
|
||||
updatePixels();
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/**
|
||||
* Lens Demo Effect
|
||||
* by luis2048.
|
||||
*
|
||||
* A picture is shown and it looks like a magnifying glass
|
||||
* is drawn over the picture. One of the most famous demos
|
||||
* that has a lens effect is 2nd reality by future crew.
|
||||
* The trick is to precalculate the entire effect. Just make
|
||||
* an array that for each pixel in the destination picture
|
||||
* tells which pixel to take from the source picture. This
|
||||
* array is called the transformation array. The tricky part
|
||||
* is to calculate the transformation array to make the
|
||||
* destination look like a lens is beeing held over the source
|
||||
* picture. Based on lens formula by on Abe Racadabra.
|
||||
*/
|
||||
|
||||
int lensD = 256; // Lens diameter
|
||||
int[] lensArray = new int[lensD*lensD]; // Height and width of lens
|
||||
|
||||
PGraphics lensEffect;
|
||||
PImage lensImage;
|
||||
PImage lensImage2;
|
||||
|
||||
int xx = 0;
|
||||
int yy = 0;
|
||||
int dx = 1;
|
||||
int dy = 1;
|
||||
|
||||
void setup() {
|
||||
|
||||
size(640, 360);
|
||||
|
||||
// Create buffered image for lens effect
|
||||
lensEffect = createGraphics(width, height, P2D);
|
||||
|
||||
// Load background image
|
||||
lensEffect.beginDraw();
|
||||
lensEffect.image(loadImage("red_smoke.jpg"), 0, 0,
|
||||
lensEffect.width, lensEffect.height);
|
||||
lensEffect.endDraw();
|
||||
|
||||
// Create buffered image for image to warp
|
||||
lensImage = createGraphics(lensD, lensD, P2D);
|
||||
lensImage2 = createGraphics(lensD, lensD, P2D);
|
||||
|
||||
// Lens algorithm (transformation array)
|
||||
int magFactor = 40; // Magnification factor
|
||||
int m, a, b;
|
||||
|
||||
int r = lensD / 2;
|
||||
float s = sqrt(r*r - magFactor*magFactor);
|
||||
|
||||
for (int y = -r; y < r; y++) {
|
||||
for (int x = -r ;x < r; x++) {
|
||||
if(x*x + y*y >= s*s) {
|
||||
a = x;
|
||||
b = y;
|
||||
}
|
||||
else {
|
||||
float z = sqrt(r*r - x*x - y*y);
|
||||
a = int(x * magFactor / z + 0.5);
|
||||
b = int(y * magFactor / z + 0.5);
|
||||
}
|
||||
lensArray[(y + r)*lensD + (x + r)] = (b + r) * lensD + (a + r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
// Bounce lens around the screen
|
||||
if((xx+dx+lensD > lensEffect.width) || (xx+dx < 0)) {
|
||||
dx =- dx;
|
||||
}
|
||||
if((yy+dy+lensD > lensEffect.height) || (yy+dy < 0)) {
|
||||
dy =- dy;
|
||||
}
|
||||
xx += dx;
|
||||
yy += dy;
|
||||
|
||||
lensImage = createGraphics(lensD, lensD, P2D);
|
||||
|
||||
// save the backgrounlensD of lensHeight*lensWilensDth pixels rectangle at the coorlensDinates
|
||||
// where the lens effect will be applielensD.
|
||||
lensImage2.copy(lensEffect, xx, yy, lensD, lensD, 0, 0, lensD, lensD);
|
||||
|
||||
// output into a bufferelensD image for reuse
|
||||
lensImage.loadPixels();
|
||||
|
||||
// For each pixel in the destination rectangle, apply the color
|
||||
// from the appropriate pixel in the saved background. The lensArray
|
||||
// array tells the offset into the saved background.
|
||||
for (int i = 0; i < lensImage.pixels.length; i++) {
|
||||
lensImage.pixels[i] = lensImage2.pixels[lensArray[i]];
|
||||
}
|
||||
lensImage.updatePixels();
|
||||
|
||||
// Restore the original picture
|
||||
image(lensEffect, 0, 0, width, height);
|
||||
|
||||
// Overlay the lens square
|
||||
image(lensImage, xx, yy, lensD, lensD);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/**
|
||||
* Metaball Demo Effect
|
||||
* by luis2048.
|
||||
*
|
||||
* Organic-looking n-dimensional objects. The technique for rendering
|
||||
* metaballs was invented by Jim Blinn in the early 1980s. Each metaball
|
||||
* is defined as a function in n-dimensions.
|
||||
*/
|
||||
|
||||
int numBlobs = 3;
|
||||
|
||||
int[] blogPx = { 0, 90, 90 };
|
||||
int[] blogPy = { 0, 120, 45 };
|
||||
|
||||
// Movement vector for each blob
|
||||
int[] blogDx = { 1, 1, 1 };
|
||||
int[] blogDy = { 1, 1, 1 };
|
||||
|
||||
PGraphics pg;
|
||||
int[][] vy,vx;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
pg = createGraphics(160, 90, P2D);
|
||||
vy = new int[numBlobs][pg.height];
|
||||
vx = new int[numBlobs][pg.width];
|
||||
}
|
||||
|
||||
void draw() {
|
||||
for (int i=0; i<numBlobs; ++i) {
|
||||
blogPx[i]+=blogDx[i];
|
||||
blogPy[i]+=blogDy[i];
|
||||
|
||||
// bounce across screen
|
||||
if (blogPx[i] < 0) {
|
||||
blogDx[i] = 1;
|
||||
}
|
||||
if (blogPx[i] > pg.width) {
|
||||
blogDx[i] = -1;
|
||||
}
|
||||
if (blogPy[i] < 0) {
|
||||
blogDy[i] = 1;
|
||||
}
|
||||
if (blogPy[i] > pg.height) {
|
||||
blogDy[i]=-1;
|
||||
}
|
||||
|
||||
for (int x = 0; x < pg.width; x++) {
|
||||
vx[i][x] = int(sq(blogPx[i]-x));
|
||||
}
|
||||
|
||||
for (int y = 0; y < pg.height; y++) {
|
||||
vy[i][y] = int(sq(blogPy[i]-y));
|
||||
}
|
||||
}
|
||||
|
||||
// Output into a buffered image for reuse
|
||||
pg.beginDraw();
|
||||
pg.loadPixels();
|
||||
for (int y = 0; y < pg.height; y++) {
|
||||
for (int x = 0; x < pg.width; x++) {
|
||||
int m = 1;
|
||||
for (int i = 0; i < numBlobs; i++) {
|
||||
// Increase this number to make your blobs bigger
|
||||
m += 60000/(vy[i][y] + vx[i][x]+1);
|
||||
}
|
||||
pg.pixels[x+y*pg.width] = color(0, m+x, (x+m+y)/2);
|
||||
}
|
||||
}
|
||||
pg.updatePixels();
|
||||
pg.endDraw();
|
||||
|
||||
// Display the results
|
||||
image(pg, 0, 0, width, height);
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Plasma Demo Effect
|
||||
* by luis2048.
|
||||
*
|
||||
* Cycles of changing colours warped to give an illusion
|
||||
* of liquid, organic movement.Colors are the sum of sine
|
||||
* functions and various formulas. Based on formula by Robert Klep.
|
||||
*/
|
||||
|
||||
int pixelSize=2;
|
||||
PGraphics pg;
|
||||
|
||||
void setup(){
|
||||
size(640, 360);
|
||||
// Create buffered image for plasma effect
|
||||
pg = createGraphics(160, 90, P2D);
|
||||
colorMode(HSB);
|
||||
noSmooth();
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
float xc = 25;
|
||||
|
||||
// Enable this to control the speed of animation regardless of CPU power
|
||||
// int timeDisplacement = millis()/30;
|
||||
|
||||
// This runs plasma as fast as your computer can handle
|
||||
int timeDisplacement = frameCount;
|
||||
|
||||
// No need to do this math for every pixel
|
||||
float calculation1 = sin( radians(timeDisplacement * 0.61655617));
|
||||
float calculation2 = sin( radians(timeDisplacement * -3.6352262));
|
||||
|
||||
// Output into a buffered image for reuse
|
||||
pg.beginDraw();
|
||||
pg.loadPixels();
|
||||
|
||||
// Plasma algorithm
|
||||
for (int x = 0; x < pg.width; x++, xc += pixelSize)
|
||||
{
|
||||
float yc = 25;
|
||||
float s1 = 128 + 128 * sin(radians(xc) * calculation1 );
|
||||
|
||||
for (int y = 0; y < pg.height; y++, yc += pixelSize)
|
||||
{
|
||||
float s2 = 128 + 128 * sin(radians(yc) * calculation2 );
|
||||
float s3 = 128 + 128 * sin(radians((xc + yc + timeDisplacement * 5) / 2));
|
||||
float s = (s1+ s2 + s3) / 3;
|
||||
pg.pixels[x+y*pg.width] = color(s, 255 - s / 2.0, 255);
|
||||
}
|
||||
}
|
||||
pg.updatePixels();
|
||||
pg.endDraw();
|
||||
|
||||
// display the results
|
||||
image(pg,0,0,width,height);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
/**
|
||||
* Tunnel Demo Effect
|
||||
* by luis2048.
|
||||
*
|
||||
* This effect shows a tunnel in which you fly while the tunnel
|
||||
* rotates, seemingly in 3D. The animation of the tunnel actually
|
||||
* isn't calculated on the fly while the animation runs, but is
|
||||
* precalculated. These calculations are stored in two tables:
|
||||
* one for the angle and one for the distance. For every frame,
|
||||
* go through every pixel (x,y) and use the angle and distance
|
||||
* tables to get which pixel of the texture it should draw at the
|
||||
* current pixel. To look like its rotating and zooming, the values
|
||||
* of the angle and distance tables are shifted.
|
||||
*/
|
||||
|
||||
int x, y, radius, l;
|
||||
PGraphics tunnelEffect;
|
||||
PImage textureImg;
|
||||
|
||||
// build lookup table
|
||||
int[][] distanceTable;
|
||||
int[][] angleTable;
|
||||
int[][] shadeTable;
|
||||
int w, h;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
|
||||
// Load texture 512 x 512
|
||||
textureImg = loadImage("red_smoke.jpg");
|
||||
textureImg.loadPixels();
|
||||
|
||||
// Create buffer screen
|
||||
tunnelEffect = createGraphics(320, 200, P2D);
|
||||
w = tunnelEffect.width;
|
||||
h = tunnelEffect.height;
|
||||
|
||||
float ratio = 32.0;
|
||||
int angle;
|
||||
int depth;
|
||||
int shade = 0;
|
||||
|
||||
// Make the tables twice as big as the screen.
|
||||
// The center of the buffers is now the position (w,h).
|
||||
distanceTable= new int[2 * w][2 * h];
|
||||
angleTable= new int[2 * w][2 * h];
|
||||
|
||||
for (int x = 0; x < w*2; x++)
|
||||
{
|
||||
for (int y = 0; y < h*2; y++)
|
||||
{
|
||||
depth = int(ratio * textureImg.height
|
||||
/ sqrt(float((x - w) * (x - w) + (y - h) * (y - h)))) ;
|
||||
angle = int(0.5 * textureImg.width * atan2(float(y - h),
|
||||
float(x - w)) / PI) ;
|
||||
|
||||
// The distance table contains for every pixel of the
|
||||
// screen, the inverse of the distance to the center of
|
||||
// the screen this pixel has.
|
||||
distanceTable[x][y] = depth ;
|
||||
|
||||
// The angle table contains the angle of every pixel of the screen,
|
||||
// where the center of the screen represents the origin.
|
||||
angleTable[x][y] = angle ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
|
||||
tunnelEffect.beginDraw();
|
||||
tunnelEffect.loadPixels();
|
||||
|
||||
float timeDisplacement = millis() / 1000.0;
|
||||
|
||||
// Calculate the shift values out of the time value
|
||||
int shiftX = int(textureImg.width * .2 * timeDisplacement+300); // speed of zoom
|
||||
int shiftY = int(textureImg.height * .15 * timeDisplacement+300); //speed of spin
|
||||
|
||||
// Calculate the look values out of the time value
|
||||
// by using sine functions, it'll alternate between
|
||||
// looking left/right and up/down
|
||||
int shiftLookX = w / 2 + int(w / 4 * sin(timeDisplacement));
|
||||
int shiftLookY = h / 2 + int(h / 4 * sin(timeDisplacement * 1.5));
|
||||
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
|
||||
// Make sure that x + shiftLookX never goes outside
|
||||
// the dimensions of the table
|
||||
int texture_x = constrain((distanceTable[x + shiftLookX][y + shiftLookY]
|
||||
+ shiftX) % textureImg.width ,0, textureImg.width);
|
||||
|
||||
int texture_y = (angleTable[x + shiftLookX][y + shiftLookY]
|
||||
+ shiftY) % textureImg.height;
|
||||
|
||||
tunnelEffect.pixels[x+y*w] = textureImg.pixels[texture_y
|
||||
* textureImg.width + texture_x];
|
||||
|
||||
// Test lookuptables
|
||||
// tunnelEffect.pixels[x+y*w] = color( 0,texture_x,texture_y);
|
||||
}
|
||||
}
|
||||
|
||||
tunnelEffect.updatePixels();
|
||||
tunnelEffect.endDraw();
|
||||
|
||||
// Display the results
|
||||
image(tunnelEffect, 0, 0, width, height);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Unlimited Sprites Demo Effect
|
||||
* by luis2048.
|
||||
*
|
||||
* An infinate number of sprites drawn to screen. It's basically
|
||||
* a flick-book effect; you draw the same sprite in different
|
||||
* positions on different bufffer 'screens' and flip between them.
|
||||
* When you've drawn on all frames, you loop back to the beginning
|
||||
* and repeat.
|
||||
*/
|
||||
|
||||
PGraphics[] spriteFrames = new PGraphics[6];
|
||||
PImage sprite;
|
||||
|
||||
float x, y;
|
||||
float xang = 0.0;
|
||||
float yang = 0.0;
|
||||
int surf = 0;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
noSmooth();
|
||||
background(0);
|
||||
|
||||
// Create sprite
|
||||
sprite=loadImage("Aqua-Ball-48x48.png");
|
||||
|
||||
// Create blank surfaces to draw on
|
||||
for (int i = 0; i < spriteFrames.length; i++) {
|
||||
spriteFrames[i] = createGraphics(width, height, JAVA2D);
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
// Get X, Y positions
|
||||
x = (width/2)*sin((radians(xang))*0.95);
|
||||
y = (height/2)*cos((radians(yang))*0.97);
|
||||
|
||||
// Inc the angle of the sine
|
||||
xang += 1.17;
|
||||
yang += 1.39;
|
||||
|
||||
// Blit our 'bob' on the 'active' surface
|
||||
spriteFrames[surf].beginDraw();
|
||||
spriteFrames[surf].image(sprite, x+(width/2)-32, y+(height/2)-32);
|
||||
spriteFrames[surf].endDraw();
|
||||
|
||||
// Blit the active surface to the screen
|
||||
image(spriteFrames[surf], 0, 0, width, height);
|
||||
|
||||
// Inc the active surface number
|
||||
surf = (surf+1) % spriteFrames.length;
|
||||
|
||||
// Display the results
|
||||
//image(spriteEffect, 0, 0, width, height);
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/**
|
||||
* Wormhole Demo Effect
|
||||
* by luis2048.
|
||||
*
|
||||
* A funnel-shaped hole sucking its texture to the middle.
|
||||
* The effect is accomplished like the tunnel effect but with
|
||||
* a 15 x 15 texture and static lookup table. The texture is shifted
|
||||
* and mapped to the static lookup table.
|
||||
*/
|
||||
|
||||
PImage wormImg, wormTexture;
|
||||
int[] reg = new int[15];
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P2D);
|
||||
noSmooth();
|
||||
|
||||
// Reference image used to transpose texture
|
||||
wormImg = loadImage("wormhole.png");
|
||||
wormImg.resize(width, height);
|
||||
wormImg.loadPixels();
|
||||
|
||||
// Texture image array
|
||||
wormTexture = loadImage("texture.gif");
|
||||
wormTexture.loadPixels();
|
||||
}
|
||||
|
||||
// Moves the bottom row of pixels to the top and shifting remaining pixels 1 over
|
||||
void shiftup() {
|
||||
for (int k = 0; k < 15; k++) {
|
||||
reg[k] = wormTexture.pixels[k];
|
||||
}
|
||||
|
||||
for (int k = 15; k < 225; k++) {
|
||||
wormTexture.pixels[k-15] = wormTexture.pixels[k];
|
||||
}
|
||||
for (int k = 0; k < 15; k++) {
|
||||
wormTexture.pixels[k+210] = reg[k];
|
||||
}
|
||||
}
|
||||
|
||||
// Moves left column of pixels to the right and shifting remaining pixels 1 over
|
||||
void shiftright() {
|
||||
for(int k = 0; k < 15; k++) {
|
||||
reg[k] = wormTexture.pixels[15*k+14];
|
||||
for(int i = 14;i > 0; i--) {
|
||||
wormTexture.pixels[15*k+i] = wormTexture.pixels[15*k+(i-1)];
|
||||
}
|
||||
wormTexture.pixels[15*k] = reg[k];
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
// Load pixel data array
|
||||
loadPixels();
|
||||
|
||||
// Loop through all pixels
|
||||
for (int i = 0; i < pixels.length; i++){
|
||||
// Map texture to wormhole in a bit shift blue
|
||||
pixels[i] = wormTexture.pixels[constrain(wormImg.pixels[i] & 0xFF, 0, 224)];
|
||||
}
|
||||
|
||||
updatePixels();
|
||||
|
||||
shiftright();
|
||||
shiftup();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 95 B |
Reference in New Issue
Block a user