adding basics folder to the android dist

This commit is contained in:
benfry
2011-03-07 00:13:51 +00:00
parent 7dcad20514
commit 4f2985a30a
408 changed files with 16462 additions and 0 deletions
@@ -0,0 +1,35 @@
/**
* Array.
*
* An array is a list of data. Each piece of data in an array
* is identified by an index number representing its position in
* the array. Arrays are zero based, which means that the first
* element in the array is [0], the second element is [1], and so on.
* In this example, an array named "coswav" is created and
* filled with the cosine values. This data is displayed three
* separate ways on the screen.
*/
size(200, 200);
float[] coswave = new float[width];
for (int i = 0; i < width; i++) {
float amount = map(i, 0, width, 0, PI);
coswave[i] = abs(cos(amount));
}
for (int i = 0; i < width; i++) {
stroke(coswave[i]*255);
line(i, 0, i, height/3);
}
for (int i = 0; i < width; i++) {
stroke(coswave[i]*255 / 4);
line(i, height/3, i, height/3*2);
}
for (int i = 0; i < width; i++) {
stroke(255 - coswave[i]*255);
line(i, height/3*2, i, height);
}
@@ -0,0 +1,56 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class Array extends PApplet {
public void setup() {/**
* Array.
*
* An array is a list of data. Each piece of data in an array
* is identified by an index number representing its position in
* the array. Arrays are zero based, which means that the first
* element in the array is [0], the second element is [1], and so on.
* In this example, an array named "coswav" is created and
* filled with the cosine values. This data is displayed three
* separate ways on the screen.
*/
size(200, 200);
float[] coswave = new float[width];
for (int i = 0; i < width; i++) {
float amount = map(i, 0, width, 0, PI);
coswave[i] = abs(cos(amount));
}
for (int i = 0; i < width; i++) {
stroke(coswave[i]*255);
line(i, 0, i, height/3);
}
for (int i = 0; i < width; i++) {
stroke(coswave[i]*255 / 4);
line(i, height/3, i, height/3*2);
}
for (int i = 0; i < width; i++) {
stroke(255 - coswave[i]*255);
line(i, height/3*2, i, height);
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Array" });
}
}
@@ -0,0 +1,35 @@
/**
* Array.
*
* An array is a list of data. Each piece of data in an array
* is identified by an index number representing its position in
* the array. Arrays are zero based, which means that the first
* element in the array is [0], the second element is [1], and so on.
* In this example, an array named "coswav" is created and
* filled with the cosine values. This data is displayed three
* separate ways on the screen.
*/
size(200, 200);
float[] coswave = new float[width];
for (int i = 0; i < width; i++) {
float amount = map(i, 0, width, 0, PI);
coswave[i] = abs(cos(amount));
}
for (int i = 0; i < width; i++) {
stroke(coswave[i]*255);
line(i, 0, i, height/3);
}
for (int i = 0; i < width; i++) {
stroke(coswave[i]*255 / 4);
line(i, height/3, i, height/3*2);
}
for (int i = 0; i < width; i++) {
stroke(255 - coswave[i]*255);
line(i, height/3*2, i, height);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

@@ -0,0 +1,32 @@
/**
* Array 2D.
*
* Demonstrates the syntax for creating a two-dimensional (2D) array.
* Values in a 2D array are accessed through two index values.
* 2D arrays are useful for storing images. In this example, each dot
* is colored in relation to its distance from the center of the image.
*/
float[][] distances;
float maxDistance;
size(200, 200);
background(0);
maxDistance = dist(width/2, height/2, width, height);
distances = new float[width][height];
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
float dist = dist(width/2, height/2, j, i);
distances[j][i] = dist/maxDistance * 255;
}
}
for(int i=0; i<height; i+=2) {
for(int j=0; j<width; j+=2) {
stroke(distances[j][i]);
point(j, i);
}
}
@@ -0,0 +1,53 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class Array2D extends PApplet {
public void setup() {/**
* Array 2D.
*
* Demonstrates the syntax for creating a two-dimensional (2D) array.
* Values in a 2D array are accessed through two index values.
* 2D arrays are useful for storing images. In this example, each dot
* is colored in relation to its distance from the center of the image.
*/
float[][] distances;
float maxDistance;
size(200, 200);
background(0);
maxDistance = dist(width/2, height/2, width, height);
distances = new float[width][height];
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
float dist = dist(width/2, height/2, j, i);
distances[j][i] = dist/maxDistance * 255;
}
}
for(int i=0; i<height; i+=2) {
for(int j=0; j<width; j+=2) {
stroke(distances[j][i]);
point(j, i);
}
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Array2D" });
}
}
@@ -0,0 +1,32 @@
/**
* Array 2D.
*
* Demonstrates the syntax for creating a two-dimensional (2D) array.
* Values in a 2D array are accessed through two index values.
* 2D arrays are useful for storing images. In this example, each dot
* is colored in relation to its distance from the center of the image.
*/
float[][] distances;
float maxDistance;
size(200, 200);
background(0);
maxDistance = dist(width/2, height/2, width, height);
distances = new float[width][height];
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
float dist = dist(width/2, height/2, j, i);
distances[j][i] = dist/maxDistance * 255;
}
}
for(int i=0; i<height; i+=2) {
for(int j=0; j<width; j+=2) {
stroke(distances[j][i]);
point(j, i);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

@@ -0,0 +1,39 @@
/**
* Array Objects.
*
* Demonstrates the syntax for creating an array of custom objects.
*
* Updated 26 February 2010.
*/
int unit = 40;
int count;
Module[] mods;
void setup() {
size(320, 240);
background(176);
noStroke();
int wideCount = width / unit;
int highCount = height / unit;
count = wideCount * highCount;
mods = new Module[count];
int index = 0;
for (int y = 0; y < highCount; y++) {
for (int x = 0; x < wideCount; x++) {
mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8));
}
}
}
void draw() {
for (int i = 0; i < count; i++) {
mods[i].update();
mods[i].draw();
}
}
@@ -0,0 +1,38 @@
class Module {
int mx, my;
int big;
float x, y;
int xdir = 1;
int ydir = 1;
float speed;
// Contructor (required)
Module(int imx, int imy, int ix, int iy, float ispeed) {
mx = imx;
my = imy;
x = ix;
y = iy;
speed = ispeed;
big = unit;
}
// Custom method for updating the variables
void update() {
x = x + (speed * xdir);
if (x >= big || x <= 0) {
xdir *= -1;
x = x + (1 * xdir);
y = y + (1 * ydir);
}
if (y >= big || y <= 0) {
ydir *= -1;
y = y + (1 * ydir);
}
}
// Custom method for drawing the object
void draw() {
stroke(second() * 4);
point(mx+x-1, my+y-1);
}
}
@@ -0,0 +1,94 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class ArrayObjects extends PApplet {
/**
* Array Objects.
*
* Demonstrates the syntax for creating an array of custom objects.
*/
int unit = 40;
int num;
Module[] mods;
public void setup()
{
size(200, 200);
background(176);
noStroke();
num = width/unit * width/unit;
mods = new Module[num];
for (int i=0; i<height/unit; i++) {
for(int j=0; j<height/unit; j++) {
int index = i*height/unit + j;
mods[index] = new Module(j*unit, i*unit, unit/2, unit/2, random(0.05f, 0.8f));
}
}
}
public void draw()
{
for(int i=0; i<num; i++) {
mods[i].update();
mods[i].draw();
}
}
class Module {
float mx, my;
int size = unit;
float x, y = 0;
int xdir = 1;
int ydir = 1;
float speed;
// Contructor (required)
Module(float imx, float imy, float ix, float iy, float ispeed) {
mx = imy;
my = imx;
x = PApplet.parseInt(ix);
y = PApplet.parseInt(iy);
speed = ispeed;
}
// Custom method for updating the variables
public void update() {
x = x + (speed * xdir);
if (x >= size || x <= 0) {
xdir *= -1;
x = x + (1 * xdir);
y = y + (1 * ydir);
}
if (y >= size || y <= 0) {
ydir *= -1;
y = y + (1 * ydir);
}
}
// Custom method for drawing the object
public void draw() {
stroke(second()*4);
point(mx+x-1, my+y-1);
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "ArrayObjects" });
}
}
@@ -0,0 +1,74 @@
/**
* Array Objects.
*
* Demonstrates the syntax for creating an array of custom objects.
*/
int unit = 40;
int num;
Module[] mods;
void setup()
{
size(200, 200);
background(176);
noStroke();
num = width/unit * width/unit;
mods = new Module[num];
for (int i=0; i<height/unit; i++) {
for(int j=0; j<height/unit; j++) {
int index = i*height/unit + j;
mods[index] = new Module(j*unit, i*unit, unit/2, unit/2, random(0.05, 0.8));
}
}
}
void draw()
{
for(int i=0; i<num; i++) {
mods[i].update();
mods[i].draw();
}
}
class Module {
float mx, my;
int size = unit;
float x, y = 0;
int xdir = 1;
int ydir = 1;
float speed;
// Contructor (required)
Module(float imx, float imy, float ix, float iy, float ispeed) {
mx = imy;
my = imx;
x = int(ix);
y = int(iy);
speed = ispeed;
}
// Custom method for updating the variables
void update() {
x = x + (speed * xdir);
if (x >= size || x <= 0) {
xdir *= -1;
x = x + (1 * xdir);
y = y + (1 * ydir);
}
if (y >= size || y <= 0) {
ydir *= -1;
y = y + (1 * ydir);
}
}
// Custom method for drawing the object
void draw() {
stroke(second()*4);
point(mx+x-1, my+y-1);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB