본문 바로가기
TIL/HTML5_CSS3

Canvas | Circle

by 홍차23 2020. 12. 16.

const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
document.body.appendChild(canvas);
canvas.width = window.innerWidth; //canvas크기를 정해줘야 깨지지 않고 나온다.
canvas.height = window.innerHeight;
canvas.style.backgroundColor = '#fff'

for (let i = 0; i < 50; i++) {
  let x = Math.random() * window.innerWidth;
  let y = Math.random() * window.innerHeight;

  let a = Math.floor(Math.random() * 1000) + 1;
  let b = Math.floor(Math.random() * 10) + 1;
  //let c = Math.floor(Math.random() * 1000) + 1;

  // arc, circle
  ctx.beginPath();
  ctx.arc(x, y, 30, 4, Math.PI * 2, false);
  ctx.rect(x, y, 10, 10)
  ctx.fillStyle = `rgba(${a}, ${b}, 60)`; //random color + crimson 컬러 근처값이 나오도록 설정
  ctx.fill();
  // ctx.strokeStyle = `rgba(${b}, 20, 60)`;
  ctx.strokeStyle = 'white';
  ctx.stroke();
}

 

'TIL > HTML5_CSS3' 카테고리의 다른 글

Circular Navbar UI  (0) 2020.12.18
[CSS] 초기 파일 참고  (0) 2020.12.03
[HTML5] Semantic Layout  (0) 2020.12.03

댓글