add week 8
@@ -1,6 +1,6 @@
 | 
			
		||||
---
 | 
			
		||||
title: "Code and Design 2023 class 7 Slides"
 | 
			
		||||
date: 2023-05-19
 | 
			
		||||
date: 2023-05-26
 | 
			
		||||
bookHidden: true
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
---
 | 
			
		||||
title: "コードとデザイン 2023年 第7回 スライド"
 | 
			
		||||
date: 2023-05-19
 | 
			
		||||
date: 2023-05-26
 | 
			
		||||
bookHidden: true
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								content/docs/2023/code-design/8/2023-code-and-design-8.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										152
									
								
								content/docs/2023/code-design/8/_index.en.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,152 @@
 | 
			
		||||
---
 | 
			
		||||
title: Week 7
 | 
			
		||||
date: 2023-05-26
 | 
			
		||||
weight: 7
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
# 2023 Tokyo University of the Arts Art media Center「Code and Design」
 | 
			
		||||
 | 
			
		||||
## Slides (in Japanese)
 | 
			
		||||
 | 
			
		||||
{{< button href="2023-code-and-design-7.pdf">}}Slides(PDF){{< /button >}}
 | 
			
		||||
 | 
			
		||||
{{< button href="./slides">}}Slides(HTML){{< /button >}}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Python Scripts for Mouse Automation
 | 
			
		||||
 | 
			
		||||
https://github.com/tomoyanonymous/py-serial-automouse
 | 
			
		||||
 | 
			
		||||
{{< button href="https://github.com/tomoyanonymous/py-serial-automouse/archive/refs/heads/main.zip">}} DL Zip {{< /button >}}
 | 
			
		||||
 | 
			
		||||
## Arduino Example Codes
 | 
			
		||||
 | 
			
		||||
### ADCTouch_monitor.ino
 | 
			
		||||
 | 
			
		||||
{{< button href="./ADCTouch_monitor/ADCTouch_monitor.ino">}}DL{{< /button >}}
 | 
			
		||||
 | 
			
		||||
```cpp
 | 
			
		||||
#include <ADCTouch.h>
 | 
			
		||||
void setup() {
 | 
			
		||||
  pinMode(A0, INPUT);
 | 
			
		||||
  pinMode(LED_BUILTIN, OUTPUT);
 | 
			
		||||
  Serial.begin(9600);
 | 
			
		||||
}
 | 
			
		||||
void loop() {
 | 
			
		||||
  int val = ADCTouch.read(A0, 100);
 | 
			
		||||
  Serial.println(val);
 | 
			
		||||
  delay(40);
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### ADCTouch_minimal.ino
 | 
			
		||||
 | 
			
		||||
{{< button href="./ADCTouch_minimal/ADCTouch_minimal.ino">}}DL{{< /button >}}
 | 
			
		||||
 | 
			
		||||
```cpp
 | 
			
		||||
#include <ADCTouch.h>
 | 
			
		||||
//setup()とloop()で共通して使う値はグローバル変数(関数の外側)で定義しておく
 | 
			
		||||
int ref = 0;
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  pinMode(A0, INPUT);
 | 
			
		||||
  pinMode(LED_BUILTIN, OUTPUT);
 | 
			
		||||
  Serial.begin(9600);
 | 
			
		||||
  //繋げた導体の状態で初期値が変わるので、それを保存しておく必要がある
 | 
			
		||||
  ref = ADCTouch.read(A0, 100);  //(使用するピン番号,平均を取るサンプル数)
 | 
			
		||||
}
 | 
			
		||||
void loop() {
 | 
			
		||||
  int val = ADCTouch.read(A0, 100) - ref;
 | 
			
		||||
  if (val > 40) {
 | 
			
		||||
    digitalWrite(LED_BUILTIN, HIGH);
 | 
			
		||||
  } else {
 | 
			
		||||
    digitalWrite(LED_BUILTIN, LOW);
 | 
			
		||||
  }
 | 
			
		||||
  Serial.println(val);
 | 
			
		||||
  delay(40);
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### ADCTouch_Mouse
 | 
			
		||||
 | 
			
		||||
{{< button href="./ADCTouch_Mouse/ADCTouch_Mouse.ino">}}DL{{< /button >}}
 | 
			
		||||
 | 
			
		||||
```cpp
 | 
			
		||||
#include <ADCTouch.h>
 | 
			
		||||
 | 
			
		||||
const int upButton = A0;
 | 
			
		||||
const int downButton = A1;
 | 
			
		||||
const int leftButton = A2;
 | 
			
		||||
const int rightButton = A3;
 | 
			
		||||
const int mouseButton = A4;
 | 
			
		||||
int ref_up = 0;
 | 
			
		||||
int ref_down = 0;
 | 
			
		||||
int ref_left = 0;
 | 
			
		||||
int ref_right = 0;
 | 
			
		||||
int ref_mouse = 0;
 | 
			
		||||
 | 
			
		||||
int range = 10;         // マウスカーソルの移動幅
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  pinMode(upButton, INPUT);
 | 
			
		||||
  pinMode(downButton, INPUT);
 | 
			
		||||
  pinMode(leftButton, INPUT);
 | 
			
		||||
  pinMode(rightButton, INPUT);
 | 
			
		||||
  pinMode(mouseButton, INPUT);
 | 
			
		||||
 | 
			
		||||
  ref_up = ADCTouch.read(upButton, 100);
 | 
			
		||||
  ref_down = ADCTouch.read(downButton, 100);
 | 
			
		||||
  ref_left = ADCTouch.read(leftButton, 100);
 | 
			
		||||
  ref_right = ADCTouch.read(rightButton, 100);
 | 
			
		||||
  ref_mouse = ADCTouch.read(mouseButton, 100);
 | 
			
		||||
 | 
			
		||||
  Serial.begin(9600);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//マウス移動に関する処理をひとまとめに
 | 
			
		||||
void moveMouse(int x, int y, int mouse_state) {
 | 
			
		||||
  Serial.print(x);
 | 
			
		||||
  Serial.print(" ");
 | 
			
		||||
  Serial.print(y);
 | 
			
		||||
  Serial.print(" ");
 | 
			
		||||
  Serial.println(mouse_state);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
  // ボタンの検出
 | 
			
		||||
  int v1 = ADCTouch.read(upButton, 100) - ref_up;
 | 
			
		||||
  int v2 = ADCTouch.read(downButton, 100) - ref_down;
 | 
			
		||||
  int v3 = ADCTouch.read(leftButton, 100) - ref_left;
 | 
			
		||||
  int v4 = ADCTouch.read(rightButton, 100) - ref_right;
 | 
			
		||||
  int v5 = ADCTouch.read(mouseButton, 100) - ref_mouse;
 | 
			
		||||
  //40以上ならクリックしたとみなし、1を、40以下なら0を
 | 
			
		||||
  // A ? B : C;はif (A) { return B;} else {return C;} の略記(三項演算子)
 | 
			
		||||
  int upState = v1 > 40 ? 1 : 0;
 | 
			
		||||
  int downState = v2 > 40 ? 1 : 0;
 | 
			
		||||
  int rightState = v3 > 40 ? 1 : 0;
 | 
			
		||||
  int leftState = v4 > 40 ? 1 : 0;
 | 
			
		||||
  int clickState = v5 > 40 ? 1 : 0;
 | 
			
		||||
  // 移動距離を算出(左右同時押しも考慮)
 | 
			
		||||
  int xDistance = (leftState - rightState) * range;
 | 
			
		||||
  int yDistance = (upState - downState) * range;
 | 
			
		||||
 | 
			
		||||
  //移動もクリックもしてないならシリアル送信は冗長なので、しない
 | 
			
		||||
  // && は AND、!はNOT
 | 
			
		||||
  if (!(xDistance == 0 && yDistance == 0 && clickState == 0)) {
 | 
			
		||||
    moveMouse(xDistance, yDistance, clickState);
 | 
			
		||||
  }
 | 
			
		||||
  delay(5);
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### DrunkMouse(Add Randomness)
 | 
			
		||||
 | 
			
		||||
{{< button href="./DrunkMouse/DrunkMouse.ino">}}DL{{< /button >}}
 | 
			
		||||
 | 
			
		||||
### ADCTouch_Mouse_HID.ino (Only works for Leonardo and Pro Micro)
 | 
			
		||||
 | 
			
		||||
{{< button href="./ADCTouch_Mouse_HID/ADCTouch_Mouse_HID.ino">}}DL{{< /button >}}
 | 
			
		||||
 | 
			
		||||
### ADCTouch_Mouse_scroll.ino(works only with `move_relative_scroll.command`)
 | 
			
		||||
 | 
			
		||||
{{< button href="./ADCTouch_Mouse_scroll/ADCTouch_Mouse_scroll.ino">}}DL{{< /button >}}
 | 
			
		||||
							
								
								
									
										183
									
								
								content/docs/2023/code-design/8/_index.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,183 @@
 | 
			
		||||
---
 | 
			
		||||
title: 第8週
 | 
			
		||||
date: 2023-06-02
 | 
			
		||||
weight: 8
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
# 2023年 東京藝術大学 芸術情報センター開設科目 「コードとデザイン」 第8回
 | 
			
		||||
 | 
			
		||||
## スライド
 | 
			
		||||
 | 
			
		||||
{{< button href="2023-code-and-design-8.pdf">}}スライド(PDF){{< /button >}}
 | 
			
		||||
 | 
			
		||||
{{< button href="slides">}}スライド(HTML){{< /button >}}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Processingサンプルコード
 | 
			
		||||
 | 
			
		||||
### minimal_pong.pde
 | 
			
		||||
 | 
			
		||||
{{< button href="examples/minimal_pong/minimal_pong.pde">}}DL{{< /button >}}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
```java
 | 
			
		||||
class Ball {
 | 
			
		||||
  float x;
 | 
			
		||||
  float y;
 | 
			
		||||
  float vel_x;
 | 
			
		||||
  float vel_y;
 | 
			
		||||
  Ball() {
 | 
			
		||||
    this.x = width/2;
 | 
			
		||||
    this.y = height/2;
 | 
			
		||||
    this.vel_x = random(0, 1.0) > 0.5 ? -3 : 3;
 | 
			
		||||
    this.vel_y = random(0, 1.0) > 0.5 ? -3 : 3;
 | 
			
		||||
  }
 | 
			
		||||
  public void update_pos() {
 | 
			
		||||
    this.x +=  this.vel_x;
 | 
			
		||||
    this.y +=  this.vel_y;
 | 
			
		||||
    if (this.x <0 || this.x > width) {
 | 
			
		||||
      this.reflect_horizontal();
 | 
			
		||||
    }
 | 
			
		||||
    if (this.y < 0 ) {
 | 
			
		||||
      this.reflect_vertical();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  void reflect_horizontal() {
 | 
			
		||||
    this.vel_x = -this.vel_x*1.1;
 | 
			
		||||
  }
 | 
			
		||||
  public void reflect_vertical() {
 | 
			
		||||
    this.vel_y = -this.vel_y*1.1;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
final float bar_width = 100;
 | 
			
		||||
final float bar_y = 550;
 | 
			
		||||
float bar_pos = 0.;
 | 
			
		||||
boolean gameover = false;
 | 
			
		||||
Ball ball = new Ball();
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  size(600, 600);
 | 
			
		||||
  textMode(CENTER);
 | 
			
		||||
  rectMode(CENTER);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void draw() {
 | 
			
		||||
  ball.update_pos();
 | 
			
		||||
  if (ball.y>height) {
 | 
			
		||||
    gameover = true;
 | 
			
		||||
  }
 | 
			
		||||
  if (gameover) {
 | 
			
		||||
    textSize(24);
 | 
			
		||||
    text("game over", width/2, height/2);
 | 
			
		||||
  } else {
 | 
			
		||||
    bar_pos = mouseX;
 | 
			
		||||
    if (ball.y > bar_y && 
 | 
			
		||||
        ball.x > bar_pos - bar_width/2 && 
 | 
			
		||||
        ball.x < bar_pos + bar_width/2) {
 | 
			
		||||
      ball.reflect_vertical();
 | 
			
		||||
    }
 | 
			
		||||
    background(255);
 | 
			
		||||
    fill(0);
 | 
			
		||||
    rect(bar_pos, bar_y, bar_width, 30);
 | 
			
		||||
    ellipse(ball.x, ball.y, 10, 10);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void mousePressed() {
 | 
			
		||||
  if (gameover) {
 | 
			
		||||
    gameover  =false;
 | 
			
		||||
    ball = new Ball();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
### minimal_pong_firmata.pde
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
{{< button href="examples/minimal_pong_firmata/minimal_pong_firmata.pde">}}DL{{< /button >}}
 | 
			
		||||
 | 
			
		||||
```java
 | 
			
		||||
import processing.serial.*;
 | 
			
		||||
import cc.arduino.*;
 | 
			
		||||
import org.firmata.*;
 | 
			
		||||
 | 
			
		||||
class Ball {
 | 
			
		||||
  float x;
 | 
			
		||||
  float y;
 | 
			
		||||
  float vel_x;
 | 
			
		||||
  float vel_y;
 | 
			
		||||
  Ball() {
 | 
			
		||||
    this.x = width/2;
 | 
			
		||||
    this.y = height/2;
 | 
			
		||||
    this.vel_x = random(0, 1.0)> 0.5 ? -5:5;
 | 
			
		||||
    this.vel_y = random(0, 1.0)> 0.5 ? -5:5;
 | 
			
		||||
  }
 | 
			
		||||
  public void update_pos() {
 | 
			
		||||
    this.x +=  this.vel_x;
 | 
			
		||||
    this.y +=  this.vel_y;
 | 
			
		||||
    if (this.x <0 || this.x > width) {
 | 
			
		||||
      this.reflect_horizontal();
 | 
			
		||||
    }
 | 
			
		||||
    if (this.y < 0 ) {
 | 
			
		||||
      this.reflect_vertical();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  void reflect_horizontal() {
 | 
			
		||||
    this.vel_x = -this.vel_x*1.1;
 | 
			
		||||
  }
 | 
			
		||||
  public void reflect_vertical() {
 | 
			
		||||
    this.vel_y = -this.vel_y*1.1;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
final float bar_width = 100;
 | 
			
		||||
final float bar_y = 550;
 | 
			
		||||
float bar_pos = 0.;
 | 
			
		||||
boolean gameover = false;
 | 
			
		||||
 | 
			
		||||
Ball ball = new Ball();
 | 
			
		||||
Arduino arduino;
 | 
			
		||||
void setup() {
 | 
			
		||||
  size(600, 600);
 | 
			
		||||
  rectMode(CENTER);
 | 
			
		||||
  textAlign(CENTER);
 | 
			
		||||
  println(Arduino.list());
 | 
			
		||||
  //リストアップされたもののうち、"tty.usbmodem"を含む番号を選択(not cu.usbmodem)
 | 
			
		||||
  arduino = new Arduino(this, Arduino.list()[5], 57600);
 | 
			
		||||
  arduino.pinMode(2,Arduino.INPUT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void draw() {
 | 
			
		||||
 | 
			
		||||
  bar_pos = map(arduino.analogRead(0), 0., 1024., 0., width);
 | 
			
		||||
  if (arduino.digitalRead(2) == Arduino.HIGH){
 | 
			
		||||
    buttonPressed();
 | 
			
		||||
  }
 | 
			
		||||
  ball.update_pos();
 | 
			
		||||
  if (ball.y>height) {
 | 
			
		||||
    gameover = true;
 | 
			
		||||
  }
 | 
			
		||||
  if (gameover) {
 | 
			
		||||
    textSize(24);
 | 
			
		||||
    text("game over", width/2, height/2);
 | 
			
		||||
  } else {
 | 
			
		||||
    if (ball.y > bar_y && 
 | 
			
		||||
        ball.x > bar_pos - bar_width/2 && 
 | 
			
		||||
        ball.x < bar_pos + bar_width/2) {
 | 
			
		||||
      ball.reflect_vertical();
 | 
			
		||||
    }
 | 
			
		||||
    background(255);
 | 
			
		||||
    fill(0);
 | 
			
		||||
    rect(bar_pos, bar_y, bar_width, 30);
 | 
			
		||||
    ellipse(ball.x, ball.y, 10, 10);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void buttonPressed() {
 | 
			
		||||
  if (gameover) {
 | 
			
		||||
    gameover = false;
 | 
			
		||||
    ball = new Ball();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
@@ -0,0 +1,68 @@
 | 
			
		||||
class Ball {
 | 
			
		||||
  float x;
 | 
			
		||||
  float y;
 | 
			
		||||
  float vel_x;
 | 
			
		||||
  float vel_y;
 | 
			
		||||
  Ball() {
 | 
			
		||||
    this.x = width/2;
 | 
			
		||||
    this.y = height/2;
 | 
			
		||||
    this.vel_x = random(0, 1.0) > 0.5 ? -3 : 3;
 | 
			
		||||
    this.vel_y = random(0, 1.0) > 0.5 ? -3 : 3;
 | 
			
		||||
  }
 | 
			
		||||
  public void update_pos() {
 | 
			
		||||
    this.x +=  this.vel_x;
 | 
			
		||||
    this.y +=  this.vel_y;
 | 
			
		||||
    if (this.x <0 || this.x > width) {
 | 
			
		||||
      this.reflect_horizontal();
 | 
			
		||||
    }
 | 
			
		||||
    if (this.y < 0 ) {
 | 
			
		||||
      this.reflect_vertical();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  void reflect_horizontal() {
 | 
			
		||||
    this.vel_x = -this.vel_x*1.1;
 | 
			
		||||
  }
 | 
			
		||||
  public void reflect_vertical() {
 | 
			
		||||
    this.vel_y = -this.vel_y*1.1;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
final float bar_width = 100;
 | 
			
		||||
final float bar_y = 550;
 | 
			
		||||
float bar_pos = 0.;
 | 
			
		||||
boolean gameover = false;
 | 
			
		||||
Ball ball = new Ball();
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  size(600, 600);
 | 
			
		||||
  textMode(CENTER);
 | 
			
		||||
  rectMode(CENTER);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void draw() {
 | 
			
		||||
  ball.update_pos();
 | 
			
		||||
  if (ball.y>height) {
 | 
			
		||||
    gameover = true;
 | 
			
		||||
  }
 | 
			
		||||
  if (gameover) {
 | 
			
		||||
    textSize(24);
 | 
			
		||||
    text("game over", width/2, height/2);
 | 
			
		||||
  } else {
 | 
			
		||||
    bar_pos = mouseX;
 | 
			
		||||
    if (ball.y > bar_y && 
 | 
			
		||||
        ball.x > bar_pos - bar_width/2 && 
 | 
			
		||||
        ball.x < bar_pos + bar_width/2) {
 | 
			
		||||
      ball.reflect_vertical();
 | 
			
		||||
    }
 | 
			
		||||
    background(255);
 | 
			
		||||
    fill(0);
 | 
			
		||||
    rect(bar_pos, bar_y, bar_width, 30);
 | 
			
		||||
    ellipse(ball.x, ball.y, 10, 10);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void mousePressed() {
 | 
			
		||||
  if (gameover) {
 | 
			
		||||
    gameover  =false;
 | 
			
		||||
    ball = new Ball();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,81 @@
 | 
			
		||||
import processing.serial.*;
 | 
			
		||||
import cc.arduino.*;
 | 
			
		||||
import org.firmata.*;
 | 
			
		||||
 | 
			
		||||
class Ball {
 | 
			
		||||
  float x;
 | 
			
		||||
  float y;
 | 
			
		||||
  float vel_x;
 | 
			
		||||
  float vel_y;
 | 
			
		||||
  Ball() {
 | 
			
		||||
    this.x = width/2;
 | 
			
		||||
    this.y = height/2;
 | 
			
		||||
    this.vel_x = random(0, 1.0)> 0.5 ? -5:5;
 | 
			
		||||
    this.vel_y = random(0, 1.0)> 0.5 ? -5:5;
 | 
			
		||||
  }
 | 
			
		||||
  public void update_pos() {
 | 
			
		||||
    this.x +=  this.vel_x;
 | 
			
		||||
    this.y +=  this.vel_y;
 | 
			
		||||
    if (this.x <0 || this.x > width) {
 | 
			
		||||
      this.reflect_horizontal();
 | 
			
		||||
    }
 | 
			
		||||
    if (this.y < 0 ) {
 | 
			
		||||
      this.reflect_vertical();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  void reflect_horizontal() {
 | 
			
		||||
    this.vel_x = -this.vel_x*1.1;
 | 
			
		||||
  }
 | 
			
		||||
  public void reflect_vertical() {
 | 
			
		||||
    this.vel_y = -this.vel_y*1.1;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
final float bar_width = 100;
 | 
			
		||||
final float bar_y = 550;
 | 
			
		||||
float bar_pos = 0.;
 | 
			
		||||
boolean gameover = false;
 | 
			
		||||
 | 
			
		||||
Ball ball = new Ball();
 | 
			
		||||
Arduino arduino;
 | 
			
		||||
void setup() {
 | 
			
		||||
  size(600, 600);
 | 
			
		||||
  rectMode(CENTER);
 | 
			
		||||
  textAlign(CENTER);
 | 
			
		||||
  println(Arduino.list());
 | 
			
		||||
  //リストアップされたもののうち、"tty.usbmodem"を含む番号を選択(not cu.usbmodem)
 | 
			
		||||
  arduino = new Arduino(this, Arduino.list()[5], 57600);
 | 
			
		||||
  arduino.pinMode(2,Arduino.INPUT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void draw() {
 | 
			
		||||
 | 
			
		||||
  bar_pos = map(arduino.analogRead(0), 0., 1024., 0., width);
 | 
			
		||||
  if (arduino.digitalRead(2) == Arduino.HIGH){
 | 
			
		||||
    buttonPressed();
 | 
			
		||||
  }
 | 
			
		||||
  ball.update_pos();
 | 
			
		||||
  if (ball.y>height) {
 | 
			
		||||
    gameover = true;
 | 
			
		||||
  }
 | 
			
		||||
  if (gameover) {
 | 
			
		||||
    textSize(24);
 | 
			
		||||
    text("game over", width/2, height/2);
 | 
			
		||||
  } else {
 | 
			
		||||
    if (ball.y > bar_y && 
 | 
			
		||||
        ball.x > bar_pos - bar_width/2 && 
 | 
			
		||||
        ball.x < bar_pos + bar_width/2) {
 | 
			
		||||
      ball.reflect_vertical();
 | 
			
		||||
    }
 | 
			
		||||
    background(255);
 | 
			
		||||
    fill(0);
 | 
			
		||||
    rect(bar_pos, bar_y, bar_width, 30);
 | 
			
		||||
    ellipse(ball.x, ball.y, 10, 10);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void buttonPressed() {
 | 
			
		||||
  if (gameover) {
 | 
			
		||||
    gameover = false;
 | 
			
		||||
    ball = new Ball();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
		 After Width: | Height: | Size: 318 KiB  | 
| 
		 After Width: | Height: | Size: 299 KiB  | 
| 
		 After Width: | Height: | Size: 222 KiB  | 
| 
		 After Width: | Height: | Size: 443 KiB  | 
| 
		 After Width: | Height: | Size: 494 KiB  | 
| 
		 After Width: | Height: | Size: 748 KiB  | 
| 
		 After Width: | Height: | Size: 852 KiB  | 
| 
		 After Width: | Height: | Size: 1.1 MiB  | 
| 
		 After Width: | Height: | Size: 240 KiB  | 
| 
		 After Width: | Height: | Size: 1013 KiB  | 
| 
		 After Width: | Height: | Size: 263 KiB  | 
| 
		 After Width: | Height: | Size: 177 KiB  | 
| 
		 After Width: | Height: | Size: 441 KiB  | 
| 
		 After Width: | Height: | Size: 423 KiB  | 
| 
		 After Width: | Height: | Size: 329 KiB  | 
| 
		 After Width: | Height: | Size: 361 KiB  | 
| 
		 After Width: | Height: | Size: 444 KiB  | 
| 
		 After Width: | Height: | Size: 340 KiB  | 
| 
		 After Width: | Height: | Size: 165 KiB  | 
| 
		 After Width: | Height: | Size: 437 KiB  | 
| 
		 After Width: | Height: | Size: 465 KiB  | 
| 
		 After Width: | Height: | Size: 556 KiB  | 
| 
		 After Width: | Height: | Size: 164 KiB  | 
| 
		 After Width: | Height: | Size: 286 KiB  | 
| 
		 After Width: | Height: | Size: 298 KiB  | 
| 
		 After Width: | Height: | Size: 460 KiB  | 
| 
		 After Width: | Height: | Size: 497 KiB  | 
| 
		 After Width: | Height: | Size: 386 KiB  | 
| 
		 After Width: | Height: | Size: 449 KiB  | 
| 
		 After Width: | Height: | Size: 496 KiB  | 
| 
		 After Width: | Height: | Size: 296 KiB  | 
| 
		 After Width: | Height: | Size: 561 KiB  | 
| 
		 After Width: | Height: | Size: 168 KiB  | 
| 
		 After Width: | Height: | Size: 344 KiB  | 
| 
		 After Width: | Height: | Size: 583 KiB  | 
| 
		 After Width: | Height: | Size: 250 KiB  | 
| 
		 After Width: | Height: | Size: 412 KiB  | 
| 
		 After Width: | Height: | Size: 1.4 MiB  | 
| 
		 After Width: | Height: | Size: 1.4 MiB  | 
| 
		 After Width: | Height: | Size: 968 KiB  | 
| 
		 After Width: | Height: | Size: 604 KiB  | 
| 
		 After Width: | Height: | Size: 269 KiB  | 
| 
		 After Width: | Height: | Size: 219 KiB  | 
| 
		 After Width: | Height: | Size: 296 KiB  | 
| 
		 After Width: | Height: | Size: 347 KiB  | 
| 
		 After Width: | Height: | Size: 1.2 MiB  | 
| 
		 After Width: | Height: | Size: 965 KiB  | 
| 
		 After Width: | Height: | Size: 247 KiB  | 
| 
		 After Width: | Height: | Size: 337 KiB  | 
| 
		 After Width: | Height: | Size: 310 KiB  | 
| 
		 After Width: | Height: | Size: 508 KiB  | 
| 
		 After Width: | Height: | Size: 500 KiB  | 
| 
		 After Width: | Height: | Size: 822 KiB  | 
| 
		 After Width: | Height: | Size: 368 KiB  | 
| 
		 After Width: | Height: | Size: 598 KiB  | 
| 
		 After Width: | Height: | Size: 718 KiB  | 
| 
		 After Width: | Height: | Size: 361 KiB  | 
| 
		 After Width: | Height: | Size: 479 KiB  | 
							
								
								
									
										10
									
								
								content/docs/2023/code-design/8/slides/index.en.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,10 @@
 | 
			
		||||
---
 | 
			
		||||
title: "Code and Design 2023 class 8 Slides"
 | 
			
		||||
date: 2023-06-02
 | 
			
		||||
bookHidden: true
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Slides
 | 
			
		||||
 | 
			
		||||
{{< slides_jpg >}}
 | 
			
		||||
							
								
								
									
										10
									
								
								content/docs/2023/code-design/8/slides/index.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,10 @@
 | 
			
		||||
---
 | 
			
		||||
title: "コードとデザイン 2023年 第8回 スライド"
 | 
			
		||||
date: 2023-06-02
 | 
			
		||||
bookHidden: true
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# スライド
 | 
			
		||||
 | 
			
		||||
{{< slides_jpg >}}
 | 
			
		||||
@@ -40,7 +40,7 @@ In addition, by learning how to convert data and materials into each other throu
 | 
			
		||||
5. [(5/12) Handmade Computer(DIWO Full Adder)](./5)
 | 
			
		||||
6. [(5/19) Software and Algorithm - Let's try using Arduino](./6)
 | 
			
		||||
7. [(5/26) Considering Inputs (Make Unreasonable Mouse)](./7)
 | 
			
		||||
8. (6/2) Considering Output (motor, solenoid, relay)
 | 
			
		||||
8. [(6/2) Considering Inputs 2 - Combining Processing and Arduino, OOP (PONG for One)](./8)
 | 
			
		||||
9. (6/9) Cartesian Robot and Digital Fabrication (Plotter, Laser Cutter)
 | 
			
		||||
10. (6/16) Cartesian Robot and Digital Fabrication (3D Printer and G-code Hack)
 | 
			
		||||
11. (6/23) Studio Work 1. Consultation
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ bookCollapseSection: true
 | 
			
		||||
5. [(5/12) Handmade Computer(みんなでつくる全加算器)](./5)
 | 
			
		||||
6. [(5/19) ソフトウェアとアルゴリズムーArduinoを使ってみよう](./6)
 | 
			
		||||
7. [(5/26) 入力を考える(不条理なマウスを作る)](./7)
 | 
			
		||||
8. (6/2) 出力を考える(モーター、ソレノイド、リレー)
 | 
			
		||||
8. [(6/2) 入力を考える2 - ProcessingとArduinoの連携、オブジェクト指向プログラミング(一人用PONG)](./8)
 | 
			
		||||
9. (6/9) Cartesian Robotとデジタルファブリケーション(プロッター、レーザーカッター)
 | 
			
		||||
10. (6/16) Cartesian Robotとデジタルファブリケーション (3DプリンターとGコードハック)
 | 
			
		||||
11. (6/23) 制作①相談
 | 
			
		||||
 
 | 
			
		||||