Initial Commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Characters Strings.
|
||||
*
|
||||
* The character datatype, abbreviated as char, stores letters and
|
||||
* symbols in the Unicode format, a coding system developed to support
|
||||
* a variety of world languages. Characters are distinguished from other
|
||||
* symbols by putting them between single quotes ('P').<br />
|
||||
* <br />
|
||||
* A string is a sequence of characters. A string is noted by surrounding
|
||||
* a group of letters with double quotes ("Processing").
|
||||
* Chars and strings are most often used with the keyboard methods,
|
||||
* to display text to the screen, and to load images or files.<br />
|
||||
* <br />
|
||||
* 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.
|
||||
*/
|
||||
|
||||
char letter;
|
||||
String words = "Begin...";
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
// Create the font
|
||||
textFont(createFont("SourceCodePro-Regular.ttf", 36));
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0); // Set background to black
|
||||
|
||||
// Draw the letter to the center of the screen
|
||||
textSize(14);
|
||||
text("Click on the program, then type to add to the String", 50, 50);
|
||||
text("Current key: " + letter, 50, 70);
|
||||
text("The String is " + words.length() + " characters long", 50, 90);
|
||||
|
||||
textSize(36);
|
||||
text(words, 50, 120, 540, 300);
|
||||
}
|
||||
|
||||
void keyTyped() {
|
||||
// The variable "key" always contains the value
|
||||
// of the most recent key pressed.
|
||||
if ((key >= 'A' && key <= 'z') || key == ' ') {
|
||||
letter = key;
|
||||
words = words + key;
|
||||
// Write the letter to the console
|
||||
println(key);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Datatype Conversion.
|
||||
*
|
||||
* It is sometimes beneficial to convert a value from one type of
|
||||
* data to another. Each of the conversion functions converts its parameter
|
||||
* to an equivalent representation within its datatype.
|
||||
* The conversion functions include int(), float(), char(), byte(), and others.
|
||||
*/
|
||||
|
||||
size(640, 360);
|
||||
background(0);
|
||||
noStroke();
|
||||
|
||||
textFont(createFont("SourceCodePro-Regular.ttf",24));
|
||||
|
||||
char c; // Chars are used for storing alphanumeric symbols
|
||||
float f; // Floats are decimal numbers
|
||||
int i; // Integers 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
|
||||
|
||||
//println(f);
|
||||
//println(i);
|
||||
//println(b);
|
||||
|
||||
text("The value of variable c is " + c, 50, 100);
|
||||
text("The value of variable f is " + f, 50, 150);
|
||||
text("The value of variable i is " + i, 50, 200);
|
||||
text("The value of variable b is " + b, 50, 250);
|
||||
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Integers Floats.
|
||||
*
|
||||
* Integers and floats are two different kinds of numerical data.
|
||||
* An integer (more commonly called an int) is a number without
|
||||
* a decimal point. A float is a floating-point number, which means
|
||||
* it is a number that has a decimal place. Floats are used when
|
||||
* more precision is needed.
|
||||
*/
|
||||
|
||||
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(640, 360);
|
||||
stroke(255);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* True/False.
|
||||
*
|
||||
* A Boolean variable has only two possible values: true or false.
|
||||
* It is common to use Booleans with control statements to
|
||||
* determine the flow of a program. In this example, when the
|
||||
* boolean value "x" is true, vertical black lines are drawn and when
|
||||
* the boolean value "x" is false, horizontal gray lines are drawn.
|
||||
*/
|
||||
|
||||
boolean b = false;
|
||||
|
||||
size(640, 360);
|
||||
background(0);
|
||||
stroke(255);
|
||||
|
||||
int d = 20;
|
||||
int middle = width/2;
|
||||
|
||||
for (int i = d; i <= width; i += d) {
|
||||
|
||||
if (i < middle) {
|
||||
b = true;
|
||||
} else {
|
||||
b = false;
|
||||
}
|
||||
|
||||
if (b == true) {
|
||||
// Vertical line
|
||||
line(i, d, i, height-d);
|
||||
}
|
||||
|
||||
if (b == false) {
|
||||
// Horizontal line
|
||||
line(middle, i - middle + d, width-d, i - middle + d);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Variable Scope.
|
||||
*
|
||||
* Variables have a global or local "scope".
|
||||
* For example, variables declared within either the
|
||||
* setup() or draw() functions may be only used in these
|
||||
* functions. Global variables, variables declared outside
|
||||
* of setup() and draw(), may be used anywhere within the program.
|
||||
* If a local variable is declared with the same name as a
|
||||
* global variable, the program will use the local variable to make
|
||||
* its calculations within the current scope. Variables are localized
|
||||
* within each block, the space between a { and }.
|
||||
*/
|
||||
|
||||
int a = 80; // Create a global variable "a"
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
background(0);
|
||||
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 = 120; a < 200; a += 2) {
|
||||
line(a, 0, a, height);
|
||||
}
|
||||
|
||||
// Create a new variable "a" local to the draw() function
|
||||
int a = 300;
|
||||
// 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 = 320;
|
||||
// Draw a line using the local variable "a"
|
||||
line(a, 0, a, height);
|
||||
}
|
||||
|
||||
void drawYetAnotherLine() {
|
||||
// Because no new local variable "a" is set,
|
||||
// this line draws using the original global
|
||||
// variable "a", which is set to the value 80.
|
||||
line(a+2, 0, a+2, height);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Variables.
|
||||
*
|
||||
* Variables are used for storing values. In this example, change
|
||||
* the values of variables to affect the composition.
|
||||
*/
|
||||
|
||||
size(640, 360);
|
||||
background(0);
|
||||
stroke(153);
|
||||
strokeWeight(4);
|
||||
strokeCap(SQUARE);
|
||||
|
||||
int a = 50;
|
||||
int b = 120;
|
||||
int c = 180;
|
||||
|
||||
line(a, b, a+c, b);
|
||||
line(a, b+10, a+c, b+10);
|
||||
line(a, b+20, a+c, b+20);
|
||||
line(a, b+30, a+c, b+30);
|
||||
|
||||
a = a + c;
|
||||
b = height-b;
|
||||
|
||||
line(a, b, a+c, b);
|
||||
line(a, b+10, a+c, b+10);
|
||||
line(a, b+20, a+c, b+20);
|
||||
line(a, b+30, a+c, b+30);
|
||||
|
||||
a = a + c;
|
||||
b = height-b;
|
||||
|
||||
line(a, b, a+c, b);
|
||||
line(a, b+10, a+c, b+10);
|
||||
line(a, b+20, a+c, b+20);
|
||||
line(a, b+30, a+c, b+30);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user