mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
*
|
||||
* Brightness is the relative lightness or darkness of a color.
|
||||
* Move the cursor vertically over each bar to alter its brightness.
|
||||
*
|
||||
* Updated 28 February 2010.
|
||||
*/
|
||||
|
||||
int barWidth = 20;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* Conditionals 2.
|
||||
*
|
||||
* We extend the language of conditionals by adding the
|
||||
* keyword "else". This allows conditionals to ask
|
||||
* two or more sequential questions, each with a different
|
||||
* We extend the language of conditionals from the previous
|
||||
* example by adding the keyword "else". This allows conditionals
|
||||
* to ask two or more sequential questions, each with a different
|
||||
* action.
|
||||
*/
|
||||
|
||||
@@ -11,14 +11,16 @@ size(640, 360);
|
||||
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' divides by 20 with no remainder
|
||||
if((i % 20) == 0) {
|
||||
stroke(255);
|
||||
line(i, 80, i, height/2);
|
||||
// If 'i' divides by 10 with no remainder
|
||||
} else if ((i % 10) == 0) {
|
||||
stroke(153);
|
||||
line(i, 20, i, 180);
|
||||
// If neither of the above two conditions are met
|
||||
// then draw this line
|
||||
} else {
|
||||
stroke(102);
|
||||
line(i, height/2, i, height-20);
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
/**
|
||||
* Variables.
|
||||
*
|
||||
* Variables are used for storing values. In this example, changing
|
||||
* the values of variables 'a' and 'b' significantly change the composition.
|
||||
* Variables are used for storing values. In this example, change
|
||||
* the values of variables 'a' and 'b' to affect the composition.
|
||||
*/
|
||||
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
background(0);
|
||||
stroke(153);
|
||||
strokeWeight(2);
|
||||
|
||||
int a = 60;
|
||||
int b = 100;
|
||||
int c = 200;
|
||||
int d = 120;
|
||||
|
||||
line(a, b, a+c, b);
|
||||
|
||||
a += 100;
|
||||
b += 50;
|
||||
line(a, b, a+c, b);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
@@ -37,7 +37,8 @@ class CA {
|
||||
for (int i = 0; i < cells.length; i++) {
|
||||
cells[i] = 0;
|
||||
}
|
||||
cells[cells.length/2] = 1; // We arbitrarily start with just the middle cell having a state of "1"
|
||||
// We arbitrarily start with just the middle cell having a state of "1"
|
||||
cells[cells.length/2] = 1;
|
||||
generation = 0;
|
||||
}
|
||||
|
||||
@@ -69,7 +70,8 @@ class CA {
|
||||
}
|
||||
|
||||
// Implementing the Wolfram rules
|
||||
// Could be improved and made more concise, but here we can explicitly see what is going on for each case
|
||||
// Could be improved and made more concise, but here we can
|
||||
// explicitly see what is going on for each case
|
||||
int rules (int a, int b, int c) {
|
||||
if (a == 1 && b == 1 && c == 1) return rules[0];
|
||||
if (a == 1 && b == 1 && c == 0) return rules[1];
|
||||
|
||||
@@ -33,6 +33,3 @@ void mousePressed() {
|
||||
ca.randomize();
|
||||
ca.restart();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,10 +10,9 @@ float x, y; // X and Y coordinates of text
|
||||
float hr, vr; // horizontal and vertical radius of the text
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
PFont font = loadFont("AmericanTypewriter-24.vlw");
|
||||
textFont(font);
|
||||
size(640, 360);
|
||||
textAlign(CENTER, CENTER);
|
||||
textSize(48);
|
||||
hr = textWidth(message) / 2;
|
||||
vr = (textAscent() + textDescent()) / 2;
|
||||
noStroke();
|
||||
@@ -22,7 +21,7 @@ void setup() {
|
||||
}
|
||||
|
||||
void draw() {
|
||||
// instead of clearing the background, fade it by drawing
|
||||
// Instead of clearing the background, fade it by drawing
|
||||
// a semi-transparent rectangle on top
|
||||
fill(204, 120);
|
||||
rect(0, 0, width, height);
|
||||
|
||||
Reference in New Issue
Block a user