测试一下
This commit is contained in:
parent
facbbbe5df
commit
7b18a0dfc3
@ -1,3 +1,5 @@
|
|||||||
# p5js
|
# p5js 学习仓库
|
||||||
|
|
||||||
p5js 学习仓库
|
## 链接
|
||||||
|
|
||||||
|
- [p5js官方网站](https://p5js.org/zh-Hans/)
|
||||||
|
66
p5/README.txt
Normal file
66
p5/README.txt
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# Welcome to p5.js
|
||||||
|
|
||||||
|
You have downloaded the complete p5.js library ZIP file, yay!
|
||||||
|
|
||||||
|
# Contents of the p5 folder
|
||||||
|
|
||||||
|
* p5.js file
|
||||||
|
* p5.min.js file
|
||||||
|
* addons folder
|
||||||
|
* p5.sound.js
|
||||||
|
* p5.sound.min.js
|
||||||
|
* empty-example folder
|
||||||
|
* index.html
|
||||||
|
* p5.js
|
||||||
|
* p5.sound.js
|
||||||
|
* sketch.js
|
||||||
|
|
||||||
|
## p5.js
|
||||||
|
|
||||||
|
This file stores the complete p5.js library. It is easy to read by humans, so feel free to open it and explore its contents. It also has a friendly error system, which helps new programmers with common user errors.
|
||||||
|
|
||||||
|
## p5.min.js
|
||||||
|
|
||||||
|
This file is a minified version of the p5.js file. It is a lighter version, with the same functionalities, but smaller file size. This minified version is harder to read for humans, and does not include the friendly error system.
|
||||||
|
|
||||||
|
## addons folder
|
||||||
|
|
||||||
|
The addons folder includes additional p5.js related libraries, in both original versions and minified versions.
|
||||||
|
|
||||||
|
### p5.sound.js, p5.sound.min.js
|
||||||
|
|
||||||
|
p5.sound extends p5.js with Web Audio functionality including audio input, playback, analysis, and synthesis.
|
||||||
|
|
||||||
|
## empty-example folder
|
||||||
|
|
||||||
|
This is an empty example of a website. The folder includes the file for the website, index.html, the p5.js library, other related p5.js libraries, and a template starting point for your p5.js sketch, called sketch.js.
|
||||||
|
|
||||||
|
### index.html
|
||||||
|
|
||||||
|
index.html is a template for an HTML file. This index.html first imports the libraries included in the folder (p5.js, p5.sound.js) then loads and executes the file sketch.js which is where you can write your own code.
|
||||||
|
|
||||||
|
### sketch.js
|
||||||
|
|
||||||
|
The sketch.js is a template for the p5.js sketch, with the functions setup() and draw() that you can complete.
|
||||||
|
|
||||||
|
## README.txt
|
||||||
|
|
||||||
|
This README file formatted with Markdown :)
|
||||||
|
|
||||||
|
# What's next?
|
||||||
|
|
||||||
|
If you need more information to help get you started, please refer to our website:
|
||||||
|
https://p5js.org/get-started/ and https://p5js.org/learn/
|
||||||
|
|
||||||
|
An online reference to the p5.js library is available here:
|
||||||
|
https://p5js.org/reference/
|
||||||
|
|
||||||
|
In order to run your website (including the empty-example), you need to enable a local server, please see this tutorial in our wiki:
|
||||||
|
https://github.com/processing/p5.js/wiki/Local-server
|
||||||
|
|
||||||
|
p5.js is a community and p5.js is built by contributions. If you want to learn more about us, visit:
|
||||||
|
https://p5js.org/community/
|
||||||
|
|
||||||
|
# License
|
||||||
|
|
||||||
|
The p5.js library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 2.1.
|
12268
p5/addons/p5.sound.js
Normal file
12268
p5/addons/p5.sound.js
Normal file
File diff suppressed because one or more lines are too long
3
p5/addons/p5.sound.min.js
vendored
Normal file
3
p5/addons/p5.sound.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
p5/empty-example/.gitignore
vendored
Normal file
2
p5/empty-example/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.html
|
||||||
|
*.js
|
2
p5/p5.min.js
vendored
Normal file
2
p5/p5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
46
呼吸球.js
Normal file
46
呼吸球.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
const ball = {
|
||||||
|
x: 200,
|
||||||
|
y: 200,
|
||||||
|
size: 0,
|
||||||
|
speed: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
function setup() {
|
||||||
|
createCanvas(400, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw() {
|
||||||
|
background(255);
|
||||||
|
strokeWeight(4);
|
||||||
|
stroke("yellow");
|
||||||
|
fill(ball.size, 0, 0);
|
||||||
|
star(ball.x, ball.y, 100, ball.size, 6);
|
||||||
|
|
||||||
|
ball.size += ball.speed;
|
||||||
|
ball.speed *= 1.1;
|
||||||
|
|
||||||
|
if (ball.size >= 200) {
|
||||||
|
ball.size = 200;
|
||||||
|
ball.speed = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ball.size <= 0) {
|
||||||
|
ball.size = 0;
|
||||||
|
ball.speed = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function star(x, y, radius1, radius2, npoints) {
|
||||||
|
let angle = TWO_PI / npoints;
|
||||||
|
let halfAngle = angle / 2.0;
|
||||||
|
beginShape();
|
||||||
|
for (let a = 0; a < TWO_PI; a += angle) {
|
||||||
|
let sx = x + cos(a) * radius2;
|
||||||
|
let sy = y + sin(a) * radius2;
|
||||||
|
vertex(sx, sy);
|
||||||
|
sx = x + cos(a + halfAngle) * radius1;
|
||||||
|
sy = y + sin(a + halfAngle) * radius1;
|
||||||
|
vertex(sx, sy);
|
||||||
|
}
|
||||||
|
endShape(CLOSE);
|
||||||
|
}
|
22
对象和数组的作用.html
Normal file
22
对象和数组的作用.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>对象和数组的作用</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
background-color: #1b1b1b;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script src="../p5/p5.min.js"></script>
|
||||||
|
<!-- <script src="../addons/p5.sound.js"></script> -->
|
||||||
|
<script src="对象和数组的作用.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<main></main>
|
||||||
|
</body>
|
||||||
|
</html>
|
22
对象和数组的作用.js
Normal file
22
对象和数组的作用.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
const circles = [
|
||||||
|
{ x: 100, y: 100, color: "red", size: 40 },
|
||||||
|
{ x: 200, y: 100, color: "orange", size: 40 },
|
||||||
|
{ x: 300, y: 100, color: "yellow", size: 40 },
|
||||||
|
{ x: 100, y: 200, color: "green", size: 40 },
|
||||||
|
{ x: 200, y: 200, color: "cyan", size: 40 },
|
||||||
|
{ x: 300, y: 200, color: "blue", size: 40 },
|
||||||
|
{ x: 100, y: 300, color: "purple", size: 40 },
|
||||||
|
{ x: 200, y: 300, color: "gray", size: 40 },
|
||||||
|
{ x: 300, y: 300, color: "black", size: 40 },
|
||||||
|
];
|
||||||
|
|
||||||
|
function setup() {
|
||||||
|
createCanvas(400, 400);
|
||||||
|
background(255);
|
||||||
|
circles.forEach((c) => {
|
||||||
|
strokeWeight(2);
|
||||||
|
stroke(0);
|
||||||
|
fill(c.color);
|
||||||
|
circle(c.x, c.y, c.size);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user