Processing4 Data
/*--Data--*/
size(200, 200);
background(0);
stroke(153);
int a = 20;
int b = 50;
int c = a*8;
int d = a*9;
int e = b-a;
int f = b*2;
int g = f+e;
line(a, f, b, g);
line(b, e, b, g);
line(b, e, d, c);
line(a, e, d-e, c);
int a = 0; // Create a variable "a" of the datatype "int"
float b = 0.0; // Create a variable "b" of the datatype "float"
void setup()
{
size(200, 200); stroke(255); frameRate(30); }
void draw() { background(51); a = a + 1; b = b + 0.2; line(a, 0, a, height/2); line(b, height/2, b, height); if(a > width) { a = 0; } if(b > width) { b = 0; } }
boolean x = false;
size(200, 200);
background(0);
stroke(0);
for(int i=1; i<width; i+=2)
{
if(i < width/2) { x = true; } else { x = false; } if(x) { stroke(255); line(i, 1, i, height-1); } if(!x) { stroke(126); line(width/2 , i, width-2, i); } }size(200, 200);
float[] coswave = new float[width];
for(int i=0; i<width; i++) {
float ratio = (float)i/(float)width; coswave[i] = abs( cos(ratio*PI) ); }
for(int i=0; i<width; i++) { stroke(coswave[i]*255); line(i, 0, i, width/3); }
for(int i=0; i<width; i++) { stroke(coswave[i]*255/4); line(i, width/3, i, width/3*2); }
for(int i=0; i<width; i++) { stroke(255-coswave[i]*255); line(i, width/3*2, i, height); }
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); } }
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 xxx, yyy = 0; int xdir = 1; int ydir = 1; float speed; // Contructor (required) Module(float imx, float imy, float ixxx, float iyyy, float ispeed) { mx = imy; my = imx; xxx = int(ixxx); yyy = int(iyyy); speed = ispeed; } // Custom method for updating the variables void update() { xxx = xxx + (speed * xdir); if (xxx >= size || xxx <= 0) { xdir *= -1; xxx = xxx + (1 * xdir); yyy = yyy + (1 * ydir); } if (yyy >= size || yyy <= 0) { ydir *= -1; yyy = yyy + (1 * ydir); } } // Custom method for drawing the object void draw() { stroke(second()*4); point(mx+xxx-1, my+yyy-1); } }
PImage frog;
PFont fontA;
int lettersize = 90;
int xoffset;
char letter;
void setup()
{
size(200, 200); fontA = loadFont("Eureka90.vlw"); textFont(fontA); textSize(lettersize); // The String datatype must be capitalized because it is a complex datatype. // A String is actually a class with its own methods, some of which are // featured below. String name= "rathausFrog"; String extension = ".jpg"; int nameLength = name.length(); println("The length of " + name + " is " + nameLength + "."); name = name.concat(extension); nameLength = name.length(); println("The length of " + name + " is " + nameLength + ".");
// The parameter for the loadImage() method must be a string // This line could also be written "frog = loadImage("rathausFrog.jpg"); frog = loadImage(name); }
void draw() { background(51); // Set background to dark gray image(frog, xoffset, 0); // Draw an X line(0, 0, width, height); line(0, height, width, 0); // Get the width of the letter int letterWidth = int(fontA.width(letter) * lettersize); // Draw the letter to the center of the screen text(letter, width/2-letterWidth/2, height/2); }
void keyPressed() { // The variable "key" always contains the value of the most recent key pressed. // If the key is an upper or lowercase letter between 'A' and 'z' // the image is shifted to the corresponding value of that key if(key >= 'A' && key <= 'z') { letter = char(key); // Scale the values to numbers between 0 and 100 float scale = 100.0/57.0; int temp = int((key - 'A') * scale); // Set the offset for the image xoffset = temp; println(key); } }
size(200, 200);
background(51);
noStroke();
char c; // Chars are used for storing typographic symbols
float f; // Floats are decimal numbers
int i; // Ints are values between 2,147,483,647 and -2147483648
byte b; // Bytes are values between -128 and 128
c = 'A';
f = float(c); // Sets f = 65.0
i = int(f * 1.4); // Sets i to 91
b = byte(c / 2); // Sets b to 32
rect(f, 0, 40, 66);
fill(204);
rect(i, 67, 40, 66);
fill(255);
rect(b, 134, 40, 66);
int a = 20; // Create a global variable "a"
void setup() { size(200, 200); background(51); stroke(255); noLoop(); }
void draw() { // Draw a line using the global variable "a" line(a, 0, a, height); // Create a new variable "a" local to the for() statement for(int a=50; a<80; a += 2) { line(a, 0, a, height); } // Create a new variable "a" local to the loop() method int a = 100; // Draw a line using the new local variable "a" line(a, 0, a, height); // Make a call to the custom function drawAnotherLine() drawAnotherLine(); // Make a call to the custom function setYetAnotherLine() drawYetAnotherLine(); }
void drawAnotherLine() { // Create a new variable "a" local to this method int a = 185; // Draw a line using the local variable "a" line(a, 0, a, height); }
void drawYetAnotherLine() { // Because no new local variable "a" is set, // this lines draws using the original global // variable "a" which is set to the value 20. line(a+2, 0, a+2, height);/*--Control--*/ }
int k; int xpos1 = 100; int xpos2 = 118; int count = 0; int timey = 0; int num = 12;
size(200, 200); background(102); noStroke(); // Draw gray bars fill(255); k=60; for(int i=0; i < num/3; i++) { rect(25, k, 155, 5); k+=10; }
// Black bars fill(51); k = 40; for(int i=0; i < num; i++) { rect(105, k, 30, 5); k += 10; } k = 15; for(int i = 0; i < num; i++) { rect(125, k, 30, 5); k +=10; } // Thin lines k = 42; fill(0); for(int i=0; i < num-1; i++) { rect(36, k, 20, 1); k+=10; }float box_size = 11;
float box_space = 12;
int margin = 7;
size(200, 200); background(0); noStroke(); // Draw gray boxes for(int i = margin; i < width-margin; i += box_space) { for(int j = margin; j < height-margin; j += box_space) { fill(255 - box_size*10); rect(j, i, box_size, box_size); } box_size = box_size - 0.6; }size(200, 200);
background(0);
for(int i=10; i<width; i+=10) {
// If 'i' divides by 20 with no remainder draw the first line // else draw the second line if(i%20 == 0) { stroke(153); line(i, 40, i, height/2); } else { stroke(102); line(i, 20, i, 180); } }size(200, 200);
background(0);
for(int i=2; i<width-2; i+=2) {
// If 'i' divides by 20 with no remainder // draw the first line else draw the second line if(i%20 == 0) { stroke(255); line(i, 40, i, height/2); } else if (i%10 == 0) { stroke(153); line(i, 20, i, 180); } else { stroke(102); line(i, height/2, i, height-40); } }size(200, 200);
background(126);
boolean op = false;
for(int i=5; i<=195; i+=5) {
// Logical AND stroke(0); if((i > 35) && (i < 100)) { line(5, i, 95, i); op = false; } // Logical OR stroke(76); if((i <= 35) || (i >= 100)) { line(105, i, 195, i); op = true; } // Testing if a boolean value is "true" // The expression "if(op)" is equivalent to "if(op == true)" if(op) { stroke(0); point(width/2, i); } // Testing if a boolean value is "false" // The expression "if(!op)" is equivalent to "if(op == false)" if(!op) { stroke(255); point(width/4, i); } }
2006年11月16日(木) 11:43:37 Modified by notarejini06