Skip to content

Commit

Permalink
Add new sketches
Browse files Browse the repository at this point in the history
  • Loading branch information
cocopon committed Feb 19, 2019
1 parent 6167e99 commit a67be1c
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 04-conditional/patterns/checker/checker.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 条件式の練習(市松模様)

void setup() {
size(600, 600);
background(200, 200, 200);
noStroke();
}

void mouseMoved() {
// もし
// mouseX が 300 未満かつ mouseY が 300 未満(キャンバス左上)
// または
// mouseX が 300 より大きいかつ mouseY が 300 より大きい(キャンバス右下)
// とき
if (mouseX < 300 && mouseY < 300
|| mouseX > 300 && mouseY > 300) {
// 塗りを黒色に
fill(0, 0, 0);
}
else {
// それ以外は白色
fill(255, 255, 255);
}

ellipse(mouseX, mouseY, 100, 100);
}

void draw() {
}
31 changes: 31 additions & 0 deletions 04-conditional/patterns/cross/cross.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 条件式の練習(十字)

void setup() {
size(600, 600);
background(200, 200, 200);
noStroke();
}

void mouseMoved() {
// もし
// mouseX が 100 より大きいかつ 200 未満
// または
// mouseX が 300 より大きいかつ 400 未満
// または
// mouseX が 500 より大きいかつ 600 未満
// のとき
if (mouseX > 200 && mouseX < 400
|| mouseY > 200 && mouseY < 400) {
// 塗りを黒色に
fill(0, 0, 0);
}
else {
// それ以外は白色
fill(255, 255, 255);
}

ellipse(mouseX, mouseY, 100, 100);
}

void draw() {
}
26 changes: 26 additions & 0 deletions 04-conditional/patterns/djungarian/djungarian.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 条件式の練習(ジャンガリアンハムスターの背中の筋)

void setup() {
size(600, 600);
background(200, 200, 200);
noStroke();
}

void mouseMoved() {
// もし
// mouseX が 200 より大きいかつ 400 未満
// のとき
if (mouseX > 200 && mouseX < 400) {
// 塗りを黒色に
fill(0, 0, 0);
}
else {
// それ以外は白色
fill(255, 255, 255);
}

ellipse(mouseX, mouseY, 100, 100);
}

void draw() {
}
26 changes: 26 additions & 0 deletions 04-conditional/patterns/half/half.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 条件式の練習(ハーフ&ハーフ)

void setup() {
size(600, 600);
background(200, 200, 200);
noStroke();
}

void mouseMoved() {
// もし
// mouseX が 300 未満
// のとき
if (mouseX < 300) {
// 塗りを黒色に
fill(0, 0, 0);
}
else {
// それ以外は白色
fill(255, 255, 255);
}

ellipse(mouseX, mouseY, 100, 100);
}

void draw() {
}
26 changes: 26 additions & 0 deletions 04-conditional/patterns/slope/slope.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 条件式の練習(斜め)

void setup() {
size(600, 600);
background(200, 200, 200);
noStroke();
}

void mouseMoved() {
// もし
// mouseX + mouseY が 600 未満
// のとき
if (mouseX + mouseY < 600) {
// 塗りを黒色に
fill(0, 0, 0);
}
else {
// それ以外は白色
fill(255, 255, 255);
}

ellipse(mouseX, mouseY, 100, 100);
}

void draw() {
}
35 changes: 35 additions & 0 deletions 04-conditional/patterns/umeboshi/umeboshi.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 条件式の練習(梅干し弁当)

void setup() {
size(600, 600);
background(200, 200, 200);
noStroke();
}

void mouseMoved() {
// もし
// mouseX が 200 より大きい
// かつ
// mouseX が 400 未満
// かつ
// mouseY が 200 より大きい
// かつ
// mouseY が 400 未満
// のとき
if (mouseX > 200
&& mouseX < 400
&& mouseY > 200
&& mouseY < 400) {
// 塗りを黒色に
fill(0, 0, 0);
}
else {
// それ以外は白色
fill(255, 255, 255);
}

ellipse(mouseX, mouseY, 100, 100);
}

void draw() {
}
32 changes: 32 additions & 0 deletions 04-conditional/patterns/zebra/zebra.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 条件式の練習(シマウマ模様)

void setup() {
size(600, 600);
background(200, 200, 200);
noStroke();
}

void mouseMoved() {
// もし
// mouseX が 100 より大きいかつ 200 未満
// または
// mouseX が 300 より大きいかつ 400 未満
// または
// mouseX が 500 より大きいかつ 600 未満
// のとき
if (mouseX > 100 && mouseX < 200
|| mouseX > 300 && mouseX < 400
|| mouseX > 500 && mouseX < 600) {
// 塗りを黒色に
fill(0, 0, 0);
}
else {
// それ以外は白色
fill(255, 255, 255);
}

ellipse(mouseX, mouseY, 100, 100);
}

void draw() {
}
27 changes: 27 additions & 0 deletions 04-conditional/pens/button_pen/button_pen.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 2色ペン(右ボタンで別の色)

void setup() {
size(600, 600);
background(255, 255, 255);

strokeWeight(3);
}

void mouseDragged() {
// もし押されたボタンが左なら
if (mouseButton == LEFT) {
// 線の色を黒色に
stroke(0, 0, 0);
}
// もしそれ以外で、押されたボタンが右なら
else if (mouseButton == RIGHT) {
// 線の色を赤色に
stroke(255, 0, 0);
}

// 線を引く
line(pmouseX, pmouseY, mouseX, mouseY);
}

void draw() {
}
22 changes: 22 additions & 0 deletions 04-conditional/pens/millis_pen/millis_pen.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
void setup() {
size(600, 600);
background(200, 200, 200);
}

void mouseDragged() {
// 現在のミリ秒が2で割り切れるとき
if (millis() % 2 == 0) {
// 塗りを赤色に
fill(255, 0, 0);
}
// そうでないとき
else {
// 塗りを白色に
fill(255, 255, 255);
}

ellipse(mouseX, mouseY, 100, 100);
}

void draw() {
}
34 changes: 34 additions & 0 deletions 04-conditional/pens/second_pen/second_pen.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 秒数によって色が変わるペン

void setup() {
size(600, 600);
background(255, 255, 255);

noStroke();
}

void mouseDragged() {
// もし秒数を3で割った余りが0なら
// 例:0, 3, 6, 9, ...
if (second() % 3 == 0) {
// 塗りを黒色に
fill(0, 0, 0);
}
// もしそれ以外で、秒数を3で割った余りが1なら
// 例:1, 4, 7, 10, ...
else if (second() % 3 == 1) {
// 塗りを赤色に
fill(255, 0, 0);
}
// もしそれ以外なら
else {
// 塗りを青色に
fill(0, 0, 255);
}

// 円を描く
ellipse(mouseX, mouseY, 20, 20);
}

void draw() {
}

0 comments on commit a67be1c

Please sign in to comment.