p5实现π扇形进度拖拽显示效果代码

代码语言:html

所属分类:其他

代码描述:p5实现π扇形进度拖拽显示效果代码

代码标签: p5 π 扇形 进度 拖拽 显示

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
  
<style>
body {
  background-color: lightgray;
  display: flex;
  height: 100vh;
  overflow: hidden;
  align-items: center;
  justify-content: center;
}
</style>

  
</head>

<body translate="no">
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/p5-1.9.0.js"></script>
      <script  >

let pie;
let x;
let mobileflag = false;
function preload() {
  pie = loadImage("//repo.bfw.wiki/bfwrepo/icon/65f67e1fbdbae.png");
}

function setup() {
  createCanvas(400, 400);
  rectMode(CENTER);
  background(255);
  mobileflag = window.mobileAndTabletCheck();
  x = 0;
}

function draw() {
  background(255);
  image(pie, 0, -4, 410, 410);
  fill(255);
  noStroke();
  translate(width / 2, height / 2);
  a = map(x, -175, 175, 0.0001, 2 * PI - 0.001);
  arc(0, 0, 320, 320, 0, -a);
  strokeWeight(20);
  stroke(150);
  strokeCap(ROUND);
  line(-175, 175, 175, 175);
  fill(242, 153, 126);
  stroke(80);
  strokeWeight(2);
  ellipse(x, 175, 25, 25);
  if (mobileflag) {
    x = -175 * sin(frameCount / 100);
  } else {
    if (mouseX - width / 2 < -175) {
      x = -175;
    } else if (mouseX - width / 2 > 175) {
      x = 175;
    } else {
      x = mouseX - width / 2;
    }
  }
  fill(0);
  strokeWeight(1);
  text("0", -175, 155);
  text("π/2", -175 / 2, 155);
  text("π", 0, 155);
  text("3π/2", 175 / 2, 155);
  text("τ", 175, 155);
}

function mousePressed() {
  console.log(mouseX - width / 2);
  if (dist(mouseX - width / 2, x, mouseY - width / 2, 175) < 15) {
  }
}

function mousePressed() {
  x = mouseX - width / 2;
}

window.mobileAndTabletCheck = function () {
  let check = false;
  (function (a) {
    if (
    /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|i.........完整代码请登录后点击上方下载按钮下载查看

网友评论0