Skip to content

Changes to Variable Examples #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 45 additions & 45 deletions 04_Variables/circle_fade_out/circle_fade_out.pde
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
// Candle (circle fade out)
// The Coding Train / Daniel Shiffman
// Processing Intro Series
// 1: Declare and 2: initialize the variable!
float circleX, circleY, circleSize, circleColor;
void setup() {
size(640, 360);
circleSize = 0; // initial circle size
circleX = width/2;
circleY = height/2;
circleColor = 255;
background(0);
}
void mousePressed() {
//reset when mouse is pressed!
circleSize = 0;
circleX = width/2;
circleY = height/2;
circleColor = 255;
}
void draw() {
noStroke();
fill(circleColor, circleColor, 0); //circle color
//Use the variables!
circle(circleX, circleY, circleSize);
/*1: Gradually move circle up while 2: circle increases in size and
3: circleColor decreases to 0 (fade out)*/
circleY = circleY - 3;
circleSize = circleSize + 5;
circleColor = circleColor - 1;
// Add a candle stick!
rectMode(CENTER);
fill(240);
/*Adding a 4th parameter in rect rounds the corners.
Check out the reference page for more detail!*/
rect(width/2, height, 30, height, 5);
}
// Candle (circle fade out)
// The Coding Train / Daniel Shiffman
// Processing Intro Series

// 1: Declare and 2: initialize the variable!
float circleX, circleY, circleSize, circleColor;

void setup() {
size(640, 360);
circleSize = 0; // initial circle size
circleX = width/2;
circleY = 3*height/4;
circleColor = 255;
background(0);
}

void mousePressed() {
//reset when mouse is pressed!
circleSize = 0;
circleX = width/2;
circleY = 3*height/4;
circleColor = 255;
}

void draw() {
noStroke();
fill(circleColor, circleColor, 0); //circle color

//Use the variables!
circle(circleX, circleY, circleSize);

/*1: Gradually move circle up while 2: circle increases in size and
3: circleColor decreases to 0 (fade out)*/
circleY = circleY - 1;
circleSize = circleSize + 1;
circleColor = circleColor - 1;

// Add a candle stick!
rectMode(CENTER);
fill(240);

/*Adding a 4th parameter in rect rounds the corners.
Check out the reference page for more detail!*/
rect(width/2, height, 15, height/2, 5);
}
45 changes: 45 additions & 0 deletions 04_Variables/circle_y_only/circle_y_only.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Candle (circle fade out)
// The Coding Train / Daniel Shiffman
// Processing Intro Series

// 1: Declare and 2: initialize the variable!
float circleX, circleY, circleSize, circleColor;

void setup() {
size(640, 360);
circleSize = 48; // initial circle size
circleX = width/2;
circleY = 3*height/4;
circleColor = 255;
background(0);
}

void mousePressed() {
//reset when mouse is pressed!
circleSize = 0;
circleX = width/2;
circleY = 3*height/4;
circleColor = 255;
}

void draw() {
background(0);

// Use the variables!
noStroke();
fill(255);
circle(circleX, circleY, circleSize);

/*1: Gradually move circle up while 2: circle increases in size and
3: circleColor decreases to 0 (fade out)*/
circleY = circleY - 1;
circleColor = circleColor - 1;

// Add a candle stick!
rectMode(CENTER);
fill(240);

/*Adding a 4th parameter in rect rounds the corners.
Check out the reference page for more detail!*/
// rect(width/2, height, 15, height/2, 5);
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// Paintbrush: random color when mouse pressed
// The Coding Train / Daniel Shiffman
// Processing Intro Series
float r, g, b;
void setup() {
size(640, 320);
background(240);
r = 255;
g = 250;
b = 150;
}
void draw() {
fill(r, g, b);
noStroke();
circle(mouseX, mouseY, 50);
}
void mousePressed() {
background(240);
r = random(255);
g = random(255);
b = random(255);
}
// Paintbrush: random color when mouse pressed
// The Coding Train / Daniel Shiffman
// Processing Intro Series

float r, g, b;

void setup() {
size(640, 320);
background(240);

r = 255;
g = 250;
b = 150;
}

void draw() {
fill(r, g, b);
noStroke();
circle(mouseX, mouseY, 24);
}

void mousePressed() {
// background(240);
r = random(255);
g = random(255);
b = random(255);
}
14 changes: 14 additions & 0 deletions 04_Variables/paintbrush_plain/paintbrush_plain.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Paintbrush: plain
// The Coding Train / Daniel Shiffman
// Processing Intro Series

void setup() {
size(640, 320);
background(240);
}

void draw() {
noStroke();
fill(0);
circle(mouseX, mouseY, 24);
}
125 changes: 62 additions & 63 deletions 04_Variables/random_house/random_house.pde
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
// The random() function (Random House Exercise)
// The Coding Train / Daniel Shiffman
// Processing Intro Series

void setup() {
size(640, 460);
frameRate(5); //sketch will refresh 5 times per second
}

void draw() {
//Random sky color
background(random(0, 50), random(0, 50), random(150, 255));
rectMode(CORNER);

//Random grass color
fill(random(0, 50), random(150, 255), random(0, 50));
rect(0, height / 2, width, height / 2); //Draw grass


float x = width / 2;
float y = height / 2;
float w = random(150, 400);
float r = random(0.2, 1); //scale ratio
float h = w * r;
float sw = random(2, 4); //thickness of line
strokeWeight(sw);
stroke(0);

// House
rectMode(CENTER);
fill(random(100, 255), 0, random(100, 255));
rect(x, y, w, w * r);

// Roof
float randomHeight = random(h / 2 + 50, 200);
fill(random(50, 255), random(0, 50), random(0, 50));
triangle(x - w / 2, y - (w * r) / 2, x + w / 2, y - (w * r) / 2, x, y - randomHeight);

// Windows
float windowWidth = random(10, h / 3);
float windowPosX = random(windowWidth, w / 2 - windowWidth);
strokeWeight(2);
stroke(0);
fill(random(100, 255), random(100, 255), random(100, 255));
rect(x - windowPosX, y - (w * r) / 4, windowWidth, windowWidth);
rect(x + windowPosX, y - (w * r) / 4, windowWidth, windowWidth);
line(x - windowPosX, y - (w * r) / 4 - windowWidth / 2, x - windowPosX, y - (w * r) / 4 + windowWidth / 2);
line(x - windowPosX - windowWidth / 2, y - (w * r) / 4, x - windowPosX + windowWidth / 2, y - (w * r) / 4);
line(x + windowPosX, y - (w * r) / 4 - windowWidth / 2, x + windowPosX, y - (w * r) / 4 + windowWidth / 2);
line(x + windowPosX - windowWidth / 2, y - (w * r) / 4, x + windowPosX + windowWidth / 2, y - (w * r) / 4);

//Door
noStroke();
fill(random(100, 255), random(100, 255), random(100, 255));
rect(x, y + h / 4, h / 4, h / 2 - sw * 2);
fill(random(0, 50), random(0, 50), random(0, 50));
circle(x - h / 24, y + h / 4, h / 12);

}

void mousePressed() {
background(0);
}
// The random() function (Random House Exercise)
// The Coding Train / Daniel Shiffman
// Processing Intro Series

void setup() {
size(640, 460);
frameRate(5); //sketch will refresh 5 times per second
}

void draw() {
// Sky
background(50, 50, 250);
rectMode(CORNER);

// Grass
fill(25, 200, 25);
rect(0, height / 2, width, height / 2); //Draw grass


float x = width / 2;
float y = height / 2;
float w = random(150, 400);
float r = random(0.2, 1); //scale ratio
float h = w * r;
float sw = random(2, 4); //thickness of line
strokeWeight(sw);
stroke(0);

// House
rectMode(CENTER);
fill(random(100, 255), 0, random(100, 255));
rect(x, y, w, w * r);

// Roof
float randomHeight = random(h / 2 + 50, 200);
fill(random(50, 255), random(0, 50), random(0, 50));
triangle(x - w / 2, y - (w * r) / 2, x + w / 2, y - (w * r) / 2, x, y - randomHeight);

// Windows
float windowWidth = random(10, h / 3);
float windowPosX = random(windowWidth, w / 2 - windowWidth);
strokeWeight(2);
stroke(0);
fill(random(100, 255), random(100, 255), random(100, 255));
rect(x - windowPosX, y - (w * r) / 4, windowWidth, windowWidth);
rect(x + windowPosX, y - (w * r) / 4, windowWidth, windowWidth);
line(x - windowPosX, y - (w * r) / 4 - windowWidth / 2, x - windowPosX, y - (w * r) / 4 + windowWidth / 2);
line(x - windowPosX - windowWidth / 2, y - (w * r) / 4, x - windowPosX + windowWidth / 2, y - (w * r) / 4);
line(x + windowPosX, y - (w * r) / 4 - windowWidth / 2, x + windowPosX, y - (w * r) / 4 + windowWidth / 2);
line(x + windowPosX - windowWidth / 2, y - (w * r) / 4, x + windowPosX + windowWidth / 2, y - (w * r) / 4);

//Door
noStroke();
fill(random(100, 255), random(100, 255), random(100, 255));
rect(x, y + h / 4, h / 4, h / 2 - sw * 2);
fill(random(0, 50), random(0, 50), random(0, 50));
circle(x - h / 24, y + h / 4, h / 12);
}

void mousePressed() {
background(0);
}
38 changes: 20 additions & 18 deletions 04_Variables/random_lines/random_lines.pde
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// Random Lines
// The Coding Train / Daniel Shiffman
// Processing Intro Series
void setup() {
size(640, 360);
background(240);
}

void draw() {
stroke(random(150, 240), 0, 0, 30);
strokeWeight(random(10)); //random line thickness
float size = 20;
line(width/2 - size, height/2 - size, mouseX + size, mouseY + size);
}

void mousePressed() {
background(240);
}
// Random Lines
// The Coding Train / Daniel Shiffman
// Processing Intro Series

float x1, y1, x2, y2;

void setup() {
size(640, 360);
background(0);
}

void draw() {
stroke(random(150, 255), random(100, 250), 0, 200);
strokeWeight(random(1, 4));
x1 = random(width);
y1 = random(height);
x2 = x1 + random(-50, 50);
y2 = y1 + random(-50, 50);
line(x1, y1, x2, y2);
}