20-04 二次関数のグラフを描こう 

学習日

11月11日 / 18日 / 25日   火曜日

名前

中村 結

✅練習問題20-4-2

let scale = 20;
function toScreenX(x){ return width/2 + x*scale; }
function toScreenY(y){ return height/2 - y*scale; }

function setup(){
  createCanvas(400, 400);
  background(255);
  
  drawGrid();

  stroke(255, 0, 0);  // 赤色
  noFill();
  beginShape();
  for (let x = -10; x <= 10; x += 0.1){
    let y = 2*x*x;
    curveVertex(toScreenX(x), toScreenY(y));
  }
  stroke(0, 0, 255);  // 青色
  noFill();
  beginShape();
  for (let x = -10; x <= 10; x += 0.1){
    let y = -1*x*x ;
    curveVertex(toScreenX(x), toScreenY(y));
  }
  stroke(0, 255, 0);  // 緑色
  noFill();
  beginShape();
  for (let x = -10; x <= 10; x += 0.1){
    let y = 0.5*x*x;
    curveVertex(toScreenX(x), toScreenY(y));
  }
  endShape();
}

✅練習問題20-4-3

予想)変わらないと思う

結果)変わらなかった

✅練習問題20-4-5

let scale = 20;
function toScreenX(x){ return width/2 + x*scale; }
function toScreenY(y){ return height/2 - y*scale; }

function setup(){
  createCanvas(400, 400);
  background(255);
  
  drawGrid();

  stroke(255, 0, 0);  // 赤色
  noFill();
  beginShape();
  for (let x = -10; x <= 10; x += 0.5){
    let y = x*x+2*x+1;
    curveVertex(toScreenX(x), toScreenY(y));
  }
  stroke(0, 0, 255);  // 青色
  noFill();
  beginShape();
  for (let x = -10; x <= 10; x += 0.5){
    let y = x*x-4*x+3;
    curveVertex(toScreenX(x), toScreenY(y));
  }
  stroke(0, 255, 0);  // 緑色
  noFill();
  beginShape();
  for (let x = -10; x <= 10; x += 0.5){
    let y = -1*x*x+2*x-1;
    curveVertex(toScreenX(x), toScreenY(y));
  }
  endShape();
}

✅練習問題20-4-9

let scale = 20;
function toScreenX(x){ return width/2 + x*scale; }
function toScreenY(y){ return height/2 - y*scale; }

function setup(){
  createCanvas(400, 400);
  background(255);

  drawGrid();

  stroke(255, 0, 0);  // 赤色
  noFill();
  beginShape();
  for (let x = -10; x <= 10; x += 0.1){
    let y = x*x-5*x+6
    curveVertex(toScreenX(x), toScreenY(y));
  }
  endShape();
 
  let a = 1, b = -5, c = 6;
  let vertexX = -b / (2 * a);
  let vertexY = a * vertexX * vertexX + b * vertexX + c;

  fill(255, 0, 0);
  ellipse(toScreenX(vertexX), toScreenY(vertexY), 8, 8);
}

コメントする