update
@ -1,22 +1,24 @@
|
|||||||
// let width = 800;
|
const canvasWidth = 800;
|
||||||
// let height = 800;
|
const canvasHeight = 800;
|
||||||
|
const backgroundColor = "#333333";
|
||||||
let vehicle;
|
let vehicle;
|
||||||
let target;
|
let target;
|
||||||
let demo = "wander";
|
let demo = "wander";
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
createCanvas(width, height);
|
createCanvas(canvasWidth, canvasHeight);
|
||||||
vehicle = new Vehicle();
|
cursor(CROSS);
|
||||||
target = new Target();
|
vehicle = new Vehicle(0, 0);
|
||||||
|
target = new Target(canvasWidth / 2, canvasHeight / 2);
|
||||||
if (demo == "wander") {
|
if (demo == "wander") {
|
||||||
vehicle.maxVelocity = 10;
|
vehicle.maxVelocity = 5;
|
||||||
vehicle.maxSteering = 5;
|
vehicle.maxSteering = 3;
|
||||||
vehicle.velocity = p5.Vector.random2D().mult(vehicle.maxVelocity);
|
vehicle.velocity = createVector(1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
background("#333333");
|
background(backgroundColor);
|
||||||
switch (demo) {
|
switch (demo) {
|
||||||
case "seek2":
|
case "seek2":
|
||||||
demoSeek2();
|
demoSeek2();
|
||||||
@ -33,15 +35,16 @@ function draw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Vehicle {
|
class Vehicle {
|
||||||
constructor() {
|
constructor(x, y) {
|
||||||
this.position = createVector(0, 0);
|
this.position = createVector(x, y);
|
||||||
this.velocity = createVector(0, 0);
|
this.velocity = createVector(0, 0);
|
||||||
this.acceleration = createVector(0, 0);
|
this.acceleration = createVector(0, 0);
|
||||||
this.size = 32;
|
|
||||||
this.color = "#FFFFFF";
|
this.color = "#FFFFFF";
|
||||||
this.maxVelocity = 8;
|
this.size = 32;
|
||||||
this.maxSteering = 0.5;
|
this.maxVelocity = 6;
|
||||||
|
this.maxSteering = 0.25;
|
||||||
this.path = [];
|
this.path = [];
|
||||||
|
this.drawPath = true;
|
||||||
this.pathes = [];
|
this.pathes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,16 +145,16 @@ class Vehicle {
|
|||||||
|
|
||||||
edges() {
|
edges() {
|
||||||
if (this.position.x < 0) {
|
if (this.position.x < 0) {
|
||||||
this.position.x = width;
|
this.position.x = canvasWidth;
|
||||||
return true;
|
return true;
|
||||||
} else if (this.position.x >= width) {
|
} else if (this.position.x >= canvasWidth) {
|
||||||
this.position.x = 0;
|
this.position.x = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (this.position.y < 0) {
|
if (this.position.y < 0) {
|
||||||
this.position.y = height;
|
this.position.y = canvasHeight;
|
||||||
return true;
|
return true;
|
||||||
} else if (this.position.y >= height) {
|
} else if (this.position.y >= canvasHeight) {
|
||||||
this.position.y = 0;
|
this.position.y = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -162,24 +165,29 @@ class Vehicle {
|
|||||||
if (this.position.x <= this.size / 2) {
|
if (this.position.x <= this.size / 2) {
|
||||||
this.position.x = this.size / 2;
|
this.position.x = this.size / 2;
|
||||||
this.velocity.x *= -1;
|
this.velocity.x *= -1;
|
||||||
} else if (this.position.x > width - this.size / 2) {
|
return true;
|
||||||
this.position.x = width - this.size / 2;
|
} else if (this.position.x > canvasWidth - this.size / 2) {
|
||||||
|
this.position.x = canvasWidth - this.size / 2;
|
||||||
this.velocity.x *= -1;
|
this.velocity.x *= -1;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (this.position.y <= this.size / 2) {
|
if (this.position.y <= this.size / 2) {
|
||||||
this.position.y = this.size / 2;
|
this.position.y = this.size / 2;
|
||||||
this.velocity.y *= -1;
|
this.velocity.y *= -1;
|
||||||
} else if (this.position.y >= height - this.size / 2) {
|
return true;
|
||||||
this.position.y = height - this.size / 2;
|
} else if (this.position.y >= canvasHeight - this.size / 2) {
|
||||||
|
this.position.y = canvasHeight - this.size / 2;
|
||||||
this.velocity.y *= -1;
|
this.velocity.y *= -1;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Target extends Vehicle {
|
class Target extends Vehicle {
|
||||||
constructor() {
|
constructor(x, y) {
|
||||||
super();
|
super(x, y);
|
||||||
this.position = createVector(random(width), random(height));
|
this.position = createVector(random(canvasWidth), random(canvasHeight));
|
||||||
this.color = "#F063A4";
|
this.color = "#F063A4";
|
||||||
this.size = 32;
|
this.size = 32;
|
||||||
this.maxVelocity = 6;
|
this.maxVelocity = 6;
|
||||||
@ -219,7 +227,10 @@ function demoWander() {
|
|||||||
function demoSeek2() {
|
function demoSeek2() {
|
||||||
let distance = p5.Vector.dist(vehicle.position, target.position);
|
let distance = p5.Vector.dist(vehicle.position, target.position);
|
||||||
if (distance < target.size / 2) {
|
if (distance < target.size / 2) {
|
||||||
target.position = createVector(random(width), random(height));
|
target.position = createVector(
|
||||||
|
random(canvasWidth),
|
||||||
|
random(canvasHeight)
|
||||||
|
);
|
||||||
target.acceleration = createVector(0, 0);
|
target.acceleration = createVector(0, 0);
|
||||||
target.velocity = createVector(0, 0);
|
target.velocity = createVector(0, 0);
|
||||||
}
|
}
|
||||||
@ -232,3 +243,14 @@ function demoSeek2() {
|
|||||||
target.show();
|
target.show();
|
||||||
vehicle.show();
|
vehicle.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取随机向量,可指定大小
|
||||||
|
* @param {number} magnitude 向量大小
|
||||||
|
* @return {p5.Vector} vector 随机向量
|
||||||
|
*/
|
||||||
|
function randomVector(magnitude) {
|
||||||
|
let vector = p5.Vector.random2D();
|
||||||
|
if (magnitude) vector.mult(magnitude);
|
||||||
|
return vector;
|
||||||
|
}
|
||||||
|
35
1001.RandomWalker.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
let walker;
|
||||||
|
|
||||||
|
function setup() {
|
||||||
|
createCanvas(400, 400);
|
||||||
|
background(255);
|
||||||
|
strokeWeight(2);
|
||||||
|
stroke("rgba(0,0,0,0.4)");
|
||||||
|
walker = new Walker(200, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw() {
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
|
walker.move();
|
||||||
|
walker.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Walker {
|
||||||
|
constructor(x, y) {
|
||||||
|
this.pos = createVector(x, y);
|
||||||
|
this.count = 0;
|
||||||
|
}
|
||||||
|
move() {
|
||||||
|
let step = p5.Vector.random2D().mult(2);
|
||||||
|
this.pos.add(step);
|
||||||
|
if (this.count++ > 10000) {
|
||||||
|
this.pos = createVector(200, 200);
|
||||||
|
background(255);
|
||||||
|
this.count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
show() {
|
||||||
|
point(this.pos.x, this.pos.y);
|
||||||
|
}
|
||||||
|
}
|
97
1002.吸引.js
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
const planets = [];
|
||||||
|
const plantsNumber = 100;
|
||||||
|
// const width = 3840;
|
||||||
|
// const height = 600;
|
||||||
|
let sun;
|
||||||
|
|
||||||
|
function setup() {
|
||||||
|
createCanvas(displayWidth, displayHeight);
|
||||||
|
print(height);
|
||||||
|
noStroke();
|
||||||
|
colorMode(HSB);
|
||||||
|
sun = createVector(width / 2, height / 2);
|
||||||
|
for (let i = 0; i < plantsNumber; i++) {
|
||||||
|
const planet = new Planet(random(0, width), random(0, height));
|
||||||
|
planet.vel = p5.Vector.random2D();
|
||||||
|
planets.push(planet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw() {
|
||||||
|
background(0);
|
||||||
|
for (let i = 0; i < plantsNumber; i++) {
|
||||||
|
planets[i].update();
|
||||||
|
planets[i].drawPath();
|
||||||
|
}
|
||||||
|
for (let i = 0; i < plantsNumber; i++) {
|
||||||
|
planets[i].show();
|
||||||
|
}
|
||||||
|
fill("#FFFF77");
|
||||||
|
circle(sun.x, sun.y, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Planet {
|
||||||
|
constructor(x, y) {
|
||||||
|
this.pos = createVector(x, y);
|
||||||
|
this.vel = createVector(0, 0);
|
||||||
|
this.acc = createVector(0, 0);
|
||||||
|
this.color = color(random(0, 255), 255, 255);
|
||||||
|
this.path = [];
|
||||||
|
}
|
||||||
|
update() {
|
||||||
|
this.acc = p5.Vector.sub(sun, this.pos);
|
||||||
|
const dist = this.acc.mag() / 10;
|
||||||
|
this.acc.normalize().div(dist * dist);
|
||||||
|
this.vel.add(this.acc);
|
||||||
|
this.pos.add(this.vel);
|
||||||
|
this.path.push(this.pos.copy());
|
||||||
|
if (this.path.length > 255) this.path.shift();
|
||||||
|
}
|
||||||
|
drawPath() {
|
||||||
|
push();
|
||||||
|
noFill();
|
||||||
|
let h = hue(this.color);
|
||||||
|
stroke(color(h, 255, 32));
|
||||||
|
strokeWeight(1);
|
||||||
|
beginShape();
|
||||||
|
this.path.forEach((v, i) => {
|
||||||
|
vertex(v.x, v.y);
|
||||||
|
});
|
||||||
|
endShape();
|
||||||
|
pop();
|
||||||
|
}
|
||||||
|
show() {
|
||||||
|
push();
|
||||||
|
translate(this.pos.x, this.pos.y);
|
||||||
|
|
||||||
|
push();
|
||||||
|
rotate(this.vel.heading());
|
||||||
|
const vel = this.vel.copy().mult(10);
|
||||||
|
vel.limit(50);
|
||||||
|
stroke("#007700");
|
||||||
|
line(0, 0, vel.mag(), 0);
|
||||||
|
line(vel.mag(), 0, vel.mag() - 2, 2);
|
||||||
|
line(vel.mag(), 0, vel.mag() - 2, -2);
|
||||||
|
pop();
|
||||||
|
|
||||||
|
push();
|
||||||
|
rotate(this.acc.heading());
|
||||||
|
const dir = this.acc.copy().mult(1000);
|
||||||
|
dir.limit(50);
|
||||||
|
stroke("#770000");
|
||||||
|
line(0, 0, dir.mag(), 0);
|
||||||
|
line(dir.mag(), 0, dir.mag() - 2, 2);
|
||||||
|
line(dir.mag(), 0, dir.mag() - 2, -2);
|
||||||
|
pop();
|
||||||
|
|
||||||
|
noStroke();
|
||||||
|
fill(this.color);
|
||||||
|
circle(0, 0, 4);
|
||||||
|
pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mouseClicked() {
|
||||||
|
let fs = fullscreen();
|
||||||
|
fullscreen(!fs);
|
||||||
|
}
|
@ -3,3 +3,9 @@
|
|||||||
## 链接
|
## 链接
|
||||||
|
|
||||||
- [p5js官方网站](https://p5js.org/zh-Hans/)
|
- [p5js官方网站](https://p5js.org/zh-Hans/)
|
||||||
|
|
||||||
|
## 临时笔记
|
||||||
|
|
||||||
|
Visual Studio Code Order In AutoCompletion
|
||||||
|
|
||||||
|
`"editor.snippetSuggestions": "top"`
|
||||||
|
22
index.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>p5.js example</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
background-color: #1b1b1b;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script src="p5/p5.min.js"></script>
|
||||||
|
<!-- <script src="p5/addons/p5.sound.js"></script> -->
|
||||||
|
<script src="1002.吸引.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<main></main>
|
||||||
|
</body>
|
||||||
|
</html>
|
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
3
p5/addons/p5.sound.min.js
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
1
参考/Steering Behaviors For Autonomous Characters.pdf
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
/home/xin/桌面/Steering Behaviors For Autonomous Characters.pdf
|
BIN
参考/The-Nature-of-Code/The-Nature-of-Code-Examples.zip
Normal file
108382
参考/The-Nature-of-Code/noc.1.0_12.6.12.pdf
Normal file
BIN
参考/The-Nature-of-Code/noc_1.0_12.6.12.epub
Normal file
BIN
参考/The-Nature-of-Code/noc_1.0_12.6.12.mobi
Normal file
9531
参考/The-Nature-of-Code/noc_cover_03.pdf
Normal file
BIN
参考/p5-reference.zip
Normal file
BIN
参考/p5-reference/assets/Bold.ttf
Normal file
BIN
参考/p5-reference/assets/Damscray.mp3
Normal file
BIN
参考/p5-reference/assets/Damscray.ogg
Normal file
BIN
参考/p5-reference/assets/Damscray_-_Dancing_Tiger_01.ogg
Normal file
BIN
参考/p5-reference/assets/Damscray_-_Dancing_Tiger_02.mp3
Normal file
BIN
参考/p5-reference/assets/Damscray_01.mp3
Normal file
BIN
参考/p5-reference/assets/Damscray_01.ogg
Normal file
BIN
参考/p5-reference/assets/Damscray_02.mp3
Normal file
BIN
参考/p5-reference/assets/Damscray_02.ogg
Normal file
BIN
参考/p5-reference/assets/Damscray_DancingTiger.mp3
Normal file
BIN
参考/p5-reference/assets/Italic.ttf
Normal file
BIN
参考/p5-reference/assets/Regular.otf
Normal file
BIN
参考/p5-reference/assets/arnott-wallace-eye-loop-forever.gif
Normal file
After Width: | Height: | Size: 101 KiB |
BIN
参考/p5-reference/assets/arnott-wallace-wink-loop-once.gif
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
参考/p5-reference/assets/beat.mp3
Normal file
BIN
参考/p5-reference/assets/beat.ogg
Normal file
BIN
参考/p5-reference/assets/beatbox.mp3
Normal file
BIN
参考/p5-reference/assets/beatbox.ogg
Normal file
3
参考/p5-reference/assets/blobs.csv
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ID,Name,Flavor,Shape,Color
|
||||||
|
Blob1,Blobby,Sweet,Blob,Pink
|
||||||
|
Blob2,Saddy,Savory,Blob,Blue
|
|
BIN
参考/p5-reference/assets/bricks.jpg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
参考/p5-reference/assets/bricks_third.jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
参考/p5-reference/assets/bx-spring.mp3
Normal file
BIN
参考/p5-reference/assets/bx-spring.ogg
Normal file
BIN
参考/p5-reference/assets/concrete-tunnel.mp3
Normal file
BIN
参考/p5-reference/assets/concrete-tunnel.ogg
Normal file
BIN
参考/p5-reference/assets/doorbell.mp3
Normal file
BIN
参考/p5-reference/assets/doorbell.ogg
Normal file
BIN
参考/p5-reference/assets/drawImage.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
参考/p5-reference/assets/drum.mp3
Normal file
BIN
参考/p5-reference/assets/drum.ogg
Normal file
BIN
参考/p5-reference/assets/favicon.ico
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
参考/p5-reference/assets/fingers.mov
Normal file
BIN
参考/p5-reference/assets/gradient.png
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
参考/p5-reference/assets/inconsolata.otf
Normal file
10
参考/p5-reference/assets/index.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Redirector</title>
|
||||||
|
<meta http-equiv="refresh" content="0;url=../">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a href="../">Click here to redirect</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
BIN
参考/p5-reference/assets/laDefense.jpg
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
参考/p5-reference/assets/large-dark-plate.mp3
Normal file
BIN
参考/p5-reference/assets/large-dark-plate.ogg
Normal file
BIN
参考/p5-reference/assets/lucky_dragons.mp3
Normal file
BIN
参考/p5-reference/assets/lucky_dragons.ogg
Normal file
4
参考/p5-reference/assets/mammals.csv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
id,species,name
|
||||||
|
0,Capra hircus,Goat
|
||||||
|
1,Panthera pardus,Leopard
|
||||||
|
2,Equus zebra,Zebra
|
|
6
参考/p5-reference/assets/mammals.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<mammals>
|
||||||
|
<animal id="0" species="Capra hircus">Goat</animal>
|
||||||
|
<animal id="1" species="Panthera pardus">Leopard</animal>
|
||||||
|
<animal id="2" species="Equus zebra">Zebra</animal>
|
||||||
|
</mammals>
|
BIN
参考/p5-reference/assets/mask.png
Normal file
After Width: | Height: | Size: 79 KiB |
BIN
参考/p5-reference/assets/mask2.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
参考/p5-reference/assets/moonwalk.jpg
Normal file
After Width: | Height: | Size: 263 KiB |
BIN
参考/p5-reference/assets/nancy-liang-wind-loop-forever.gif
Normal file
After Width: | Height: | Size: 36 KiB |
15
参考/p5-reference/assets/octahedron.obj
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
v 0.000000E+00 0.000000E+00 40.0000
|
||||||
|
v 22.5000 22.5000 0.000000E+00
|
||||||
|
v 22.5000 -22.5000 0.000000E+00
|
||||||
|
v -22.5000 -22.5000 0.000000E+00
|
||||||
|
v -22.5000 22.5000 0.000000E+00
|
||||||
|
v 0.000000E+00 0.000000E+00 -40.0000
|
||||||
|
|
||||||
|
f 1 2 3
|
||||||
|
f 1 3 4
|
||||||
|
f 1 4 5
|
||||||
|
f 1 5 2
|
||||||
|
f 6 5 4
|
||||||
|
f 6 4 3
|
||||||
|
f 6 3 2
|
||||||
|
f 6 2 5
|
BIN
参考/p5-reference/assets/rockies.jpg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
参考/p5-reference/assets/rockies128.jpg
Normal file
After Width: | Height: | Size: 19 KiB |
22
参考/p5-reference/assets/shader-gradient.frag
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Code adopted from "Creating a Gradient Color in Fragment Shader"
|
||||||
|
// by Bahadır on stackoverflow.com
|
||||||
|
// https://stackoverflow.com/questions/47376499/creating-a-gradient-color-in-fragment-shader
|
||||||
|
|
||||||
|
|
||||||
|
precision highp float; varying vec2 vPos;
|
||||||
|
uniform vec2 offset;
|
||||||
|
uniform vec3 colorCenter;
|
||||||
|
uniform vec3 colorBackground;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
vec2 st = vPos.xy + offset.xy;
|
||||||
|
|
||||||
|
// color1 = vec3(1.0,0.55,0);
|
||||||
|
// color2 = vec3(0.226,0.000,0.615);
|
||||||
|
|
||||||
|
float mixValue = distance(st,vec2(0,1));
|
||||||
|
vec3 color = mix(colorCenter,colorBackground,mixValue);
|
||||||
|
|
||||||
|
gl_FragColor = vec4(color,mixValue);
|
||||||
|
}
|
16
参考/p5-reference/assets/shader.frag
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
precision highp float; varying vec2 vPos;
|
||||||
|
uniform vec2 p;
|
||||||
|
uniform float r;
|
||||||
|
const int I = 500;
|
||||||
|
void main() {
|
||||||
|
vec2 c = p + vPos * r, z = c;
|
||||||
|
float n = 0.0;
|
||||||
|
for (int i = I; i > 0; i --) {
|
||||||
|
if(z.x*z.x+z.y*z.y > 4.0) {
|
||||||
|
n = float(i)/float(I);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
z = vec2(z.x*z.x-z.y*z.y, 2.0*z.x*z.y) + c;
|
||||||
|
}
|
||||||
|
gl_FragColor = vec4(0.5-cos(n*17.0)/2.0,0.5-cos(n*13.0)/2.0,0.5-cos(n*23.0)/2.0,1.0);
|
||||||
|
}
|
3
参考/p5-reference/assets/shader.vert
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
precision highp float; varying vec2 vPos;
|
||||||
|
attribute vec3 aPosition;
|
||||||
|
void main() { vPos = (gl_Position = vec4(aPosition,1.0)).xy; }
|
BIN
参考/p5-reference/assets/small-plate.mp3
Normal file
BIN
参考/p5-reference/assets/small-plate.ogg
Normal file
BIN
参考/p5-reference/assets/small.mp4
Normal file
BIN
参考/p5-reference/assets/small.ogv
Normal file
BIN
参考/p5-reference/assets/small.webm
Normal file
BIN
参考/p5-reference/assets/studio-b.mp3
Normal file
BIN
参考/p5-reference/assets/studio-b.ogg
Normal file
4663
参考/p5-reference/assets/teapot.obj
Normal file
6
参考/p5-reference/assets/test.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
I am a cat
|
||||||
|
I like apples
|
||||||
|
I have three feet
|
||||||
|
I like my nose
|
||||||
|
I smell like butter
|
||||||
|
I talk like an orange
|
BIN
参考/p5-reference/assets/transformation-matrix-4-4.png
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
参考/p5-reference/assets/transformation-matrix.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
3532
参考/p5-reference/css/all.css
Normal file
54
参考/p5-reference/img/p5js-beta.svg
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
width="250px" height="114px" viewBox="0 0 250 114" enable-background="new 0 0 250 114" xml:space="preserve">
|
||||||
|
<path fill="#EC245E" d="M16.254,27.631v7.998h0.359c0.715-1.113,1.65-2.248,2.805-3.402c1.155-1.154,2.568-2.188,4.24-3.105
|
||||||
|
c1.67-0.912,3.561-1.67,5.67-2.268c2.107-0.596,4.477-0.896,7.104-0.896c4.059,0,7.799,0.777,11.223,2.328
|
||||||
|
c3.422,1.555,6.367,3.684,8.836,6.389c2.465,2.707,4.375,5.891,5.73,9.551c1.352,3.662,2.029,7.602,2.029,11.82
|
||||||
|
s-0.656,8.179-1.971,11.879c-1.312,3.701-3.184,6.925-5.611,9.67c-2.427,2.746-5.371,4.938-8.834,6.566
|
||||||
|
c-3.463,1.631-7.385,2.446-11.76,2.446c-4.061,0-7.781-0.836-11.164-2.506c-3.385-1.672-5.99-3.938-7.82-6.807h-0.238v36.295H2.525
|
||||||
|
V27.631H16.254z M49.684,56.045c0-2.229-0.338-4.438-1.014-6.627c-0.678-2.188-1.693-4.158-3.045-5.91
|
||||||
|
c-1.354-1.748-3.064-3.162-5.135-4.238c-2.07-1.074-4.496-1.611-7.281-1.611c-2.627,0-4.977,0.557-7.045,1.672
|
||||||
|
c-2.07,1.115-3.842,2.549-5.312,4.297c-1.475,1.752-2.588,3.742-3.344,5.971c-0.758,2.229-1.133,4.459-1.133,6.686
|
||||||
|
c0,2.229,0.375,4.438,1.133,6.625c0.756,2.191,1.869,4.16,3.344,5.912c1.471,1.75,3.242,3.164,5.312,4.236
|
||||||
|
c2.068,1.075,4.418,1.61,7.045,1.61c2.785,0,5.211-0.555,7.281-1.67c2.07-1.115,3.781-2.547,5.135-4.299
|
||||||
|
c1.352-1.75,2.367-3.74,3.045-5.97C49.346,60.502,49.684,58.273,49.684,56.045z M189.332,24.893v63.505
|
||||||
|
c0,3.422-0.279,6.666-0.836,9.73c-0.559,3.064-1.611,5.73-3.164,8c-1.551,2.27-3.662,4.078-6.328,5.432
|
||||||
|
c-2.668,1.354-6.146,2.029-10.445,2.029c-1.193,0-2.389-0.08-3.582-0.238c-1.193-0.16-2.148-0.319-2.865-0.479l1.195-12.178
|
||||||
|
c0.637,0.16,1.311,0.279,2.027,0.359c0.717,0.077,1.354,0.118,1.91,0.118c1.67,0,3.023-0.317,4.059-0.955
|
||||||
|
c1.033-0.639,1.83-1.514,2.391-2.627c0.555-1.114,0.914-2.407,1.074-3.881c0.156-1.474,0.236-3.043,0.236-4.715V24.893H189.332z
|
||||||
|
M238.162,42.912c-1.275-1.672-3.025-3.123-5.254-4.357c-2.229-1.234-4.656-1.852-7.283-1.852c-2.309,0-4.416,0.479-6.326,1.434
|
||||||
|
c-1.912,0.953-2.863,2.547-2.863,4.775s1.053,3.803,3.16,4.715c2.109,0.916,5.195,1.852,9.256,2.807
|
||||||
|
c2.146,0.479,4.314,1.115,6.506,1.91c2.189,0.795,4.18,1.85,5.971,3.164c1.789,1.312,3.242,2.945,4.357,4.895
|
||||||
|
c1.111,1.951,1.672,4.318,1.672,7.104c0,3.504-0.658,6.47-1.973,8.896c-1.311,2.428-3.062,4.397-5.254,5.91
|
||||||
|
c-2.189,1.512-4.734,2.606-7.641,3.283c-2.906,0.676-5.908,1.014-9.014,1.014c-4.459,0-8.795-0.816-13.014-2.447
|
||||||
|
c-4.219-1.629-7.721-3.959-10.506-6.982l9.432-8.836c1.592,2.07,3.66,3.781,6.209,5.133c2.547,1.354,5.371,2.029,8.477,2.029
|
||||||
|
c1.033,0,2.088-0.117,3.164-0.357c1.074-0.237,2.068-0.614,2.984-1.133c0.914-0.518,1.65-1.213,2.209-2.09
|
||||||
|
c0.555-0.877,0.834-1.949,0.834-3.225c0-2.389-1.094-4.098-3.281-5.133c-2.191-1.035-5.475-2.07-9.85-3.104
|
||||||
|
c-2.15-0.479-4.24-1.094-6.27-1.853c-2.029-0.756-3.84-1.75-5.432-2.983c-1.596-1.234-2.865-2.764-3.82-4.598
|
||||||
|
c-0.955-1.83-1.436-4.098-1.436-6.805c0-3.184,0.656-5.928,1.973-8.236c1.311-2.312,3.045-4.197,5.191-5.674
|
||||||
|
c2.148-1.471,4.576-2.566,7.283-3.281c2.705-0.717,5.492-1.076,8.357-1.076c4.137,0,8.178,0.717,12.117,2.148
|
||||||
|
c3.939,1.434,7.062,3.625,9.373,6.568L238.162,42.912z M153.559,72.816l8.533-2.576l1.676,5.156l-8.498,2.897l5.275,7.479
|
||||||
|
l-4.447,3.226l-5.553-7.349l-5.408,7.154l-4.318-3.289l5.275-7.223l-8.564-3.09l1.678-5.16l8.6,2.771v-8.896h5.754v8.897H153.559z
|
||||||
|
M124.086,45.836c-1.473-3.301-3.52-6.088-6.148-8.357c-2.625-2.268-5.711-4-9.252-5.193c-3.543-1.193-7.383-1.791-11.521-1.791
|
||||||
|
c-1.512,0-3.203,0.082-5.074,0.238c-1.871,0.162-3.482,0.439-4.834,0.838l0.834-18.268h34.503V0.41H74.481l-1.432,46.201
|
||||||
|
c1.271-0.635,2.725-1.232,4.357-1.791c1.631-0.555,3.301-1.053,5.014-1.49c1.711-0.438,3.463-0.775,5.254-1.016
|
||||||
|
c1.791-0.238,3.48-0.357,5.074-0.357c2.307,0,4.576,0.258,6.805,0.775c2.227,0.518,4.238,1.434,6.029,2.746s3.242,3.045,4.357,5.193
|
||||||
|
c1.113,2.148,1.672,4.855,1.672,8.119c0,2.547-0.418,4.836-1.254,6.865c-0.836,2.026-1.971,3.721-3.402,5.071
|
||||||
|
c-1.434,1.355-3.104,2.39-5.016,3.104c-1.91,0.719-3.939,1.076-6.088,1.076c-3.82,0-7.125-1.017-9.91-3.046
|
||||||
|
c-2.787-2.028-4.775-4.715-5.969-8.059l-0.16,0.059l-10.367,9.716c2.096,3.42,4.799,6.28,8.139,8.553
|
||||||
|
c4.854,3.302,10.824,4.955,17.91,4.955c4.217,0,8.197-0.678,11.938-2.028c3.741-1.352,7.004-3.304,9.791-5.853
|
||||||
|
c2.786-2.545,4.994-5.67,6.627-9.371c1.629-3.701,2.445-7.897,2.445-12.597C126.295,52.939,125.559,49.141,124.086,45.836z
|
||||||
|
M131.07,6.842h2.521c0.244,0,0.484,0.029,0.723,0.086c0.236,0.059,0.447,0.152,0.635,0.283c0.186,0.131,0.336,0.301,0.453,0.508
|
||||||
|
c0.115,0.207,0.172,0.457,0.172,0.749c0,0.365-0.104,0.667-0.311,0.904c-0.207,0.237-0.479,0.407-0.812,0.511v0.02
|
||||||
|
c0.408,0.055,0.742,0.213,1.006,0.475c0.262,0.262,0.393,0.611,0.393,1.051c0,0.354-0.07,0.65-0.209,0.891
|
||||||
|
c-0.143,0.24-0.324,0.434-0.555,0.58c-0.229,0.146-0.488,0.251-0.785,0.314c-0.295,0.064-0.596,0.096-0.898,0.096h-2.33V6.842
|
||||||
|
H131.07z M132.221,9.473h1.023c0.383,0,0.676-0.076,0.877-0.229c0.201-0.153,0.301-0.369,0.301-0.648c0-0.293-0.104-0.5-0.311-0.621
|
||||||
|
c-0.207-0.122-0.529-0.184-0.969-0.184h-0.924v1.682H132.221z M132.221,12.341h1.031c0.146,0,0.307-0.011,0.477-0.032
|
||||||
|
s0.328-0.064,0.471-0.133c0.143-0.066,0.262-0.164,0.355-0.292c0.096-0.128,0.143-0.298,0.143-0.511
|
||||||
|
c0-0.342-0.115-0.579-0.348-0.713c-0.23-0.135-0.582-0.201-1.051-0.201h-1.078V12.341z M136.936,6.842h4.283v1.004h-3.135v1.645
|
||||||
|
h2.969v0.969h-2.969v1.827h3.299v1.022h-4.447V6.842z M144.088,7.846h-1.982V6.842h5.117v1.004h-1.982v5.463h-1.152V7.846
|
||||||
|
L144.088,7.846z M149.449,6.842h0.996l2.787,6.467h-1.316l-0.602-1.479h-2.807l-0.584,1.479h-1.289L149.449,6.842z M150.912,10.843
|
||||||
|
l-0.996-2.631l-1.014,2.631H150.912z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 5.7 KiB |
8
参考/p5-reference/img/thick-asterisk-alone.svg
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
width="28px" height="28px" viewBox="0 0 28 28" enable-background="new 0 0 28 28" xml:space="preserve">
|
||||||
|
<path fill="#ED225D" stroke="#ED225D" stroke-miterlimit="10" d="M16.909,10.259l8.533-2.576l1.676,5.156l-8.498,2.899l5.275,7.48
|
||||||
|
l-4.447,3.225l-5.553-7.348L8.487,26.25l-4.318-3.289l5.275-7.223L0.88,12.647l1.678-5.16l8.598,2.771V1.364h5.754V10.259z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 727 B |
84
参考/p5-reference/index.html
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||||
|
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||||
|
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||||
|
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||||
|
<title tabindex="1">reference | p5.js</title>
|
||||||
|
<meta name="description" content="p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.">
|
||||||
|
<meta name="viewport" content="width=device-width">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="./css/all.css">
|
||||||
|
|
||||||
|
<script src="./js/vendor/jquery-1.12.4.min.js"></script>
|
||||||
|
<script src="./js/vendor/underscore-min.js"></script>
|
||||||
|
<script src="./js/vendor/backbone-min.js"></script>
|
||||||
|
<script src="./js/vendor/ace-nc/ace.js"></script>
|
||||||
|
<script src="./js/vendor/ace-nc/mode-javascript.js"></script>
|
||||||
|
<script src="./js/vendor/prism.js"></script>
|
||||||
|
<script src="./js/init.js"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body id="reference-page">
|
||||||
|
<div id="container">
|
||||||
|
<!-- identity -->
|
||||||
|
<div id="lockup">
|
||||||
|
<img type="image/svg+xml" src="./img/p5js-beta.svg" id="logo_image" class="logo" />
|
||||||
|
<div id='p5_logo'></div>
|
||||||
|
</a>
|
||||||
|
<p>Processing intuition times JavaScript power</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column-span">
|
||||||
|
<section id="reference">
|
||||||
|
|
||||||
|
<a href="./index.html" id="home-button" class="anchor"><h2>Reference</h2></a>
|
||||||
|
|
||||||
|
<div id="search" class="search-wrapper"></div>
|
||||||
|
<div id="collection-list-nav">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--class="container-fluid"-->
|
||||||
|
<div id="list" class="list-wrapper allItems-collection"></div>
|
||||||
|
<div id="item" class="item-wrapper apidocs"></div>
|
||||||
|
<div id="file" class="file-wrapper"></div>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<p>p5.js was created by <a href='https://lauren-mccarthy.com' target="_blank">Lauren McCarthy</a> and is developed by a community of collaborators,
|
||||||
|
with support from the <a href="https://processing.org/foundation/" target="_blank">Processing Foundation</a>
|
||||||
|
and <a href="https://itp.nyu.edu/itp/" target="_blank">NYU ITP</a>.
|
||||||
|
<a href="https://p5js.org/copyright.php">© Info.</a></p>
|
||||||
|
</footer>
|
||||||
|
</div><!-- end column-span -->
|
||||||
|
|
||||||
|
<!-- outside of column for footer to go across both -->
|
||||||
|
|
||||||
|
<p class="clearfix"> </p>
|
||||||
|
|
||||||
|
<object type="image/svg+xml" data="./img/thick-asterisk-alone.svg" id="asterisk-design-element">
|
||||||
|
*<!-- to do: add fallback image in CSS -->
|
||||||
|
</object>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="./js/p5.min.js"></script>
|
||||||
|
<script src="./js/p5.sound.min.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
window.requireNode = window.require;
|
||||||
|
window.require = undefined;
|
||||||
|
</script>
|
||||||
|
<script src="./js/vendor/require.min.js"></script>
|
||||||
|
<script src="./js/render.js"></script>
|
||||||
|
<script src="./js/data.js"></script>
|
||||||
|
<script src="./js/reference.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
30229
参考/p5-reference/js/data.js
Normal file
200
参考/p5-reference/js/examples.js
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
var examples = {
|
||||||
|
init: function(file) {
|
||||||
|
|
||||||
|
// Editor
|
||||||
|
|
||||||
|
examples.editor = ace.edit('exampleEditor');
|
||||||
|
//examples.editor.setTheme('ace/theme/monokai');
|
||||||
|
examples.editor.getSession().setMode('ace/mode/javascript');
|
||||||
|
examples.editor.getSession().setTabSize(2);
|
||||||
|
|
||||||
|
examples.dims = [];
|
||||||
|
|
||||||
|
// Button
|
||||||
|
|
||||||
|
$('#runButton').click( function() {
|
||||||
|
examples.runExample();
|
||||||
|
});
|
||||||
|
$('#resetButton').click( function() {
|
||||||
|
examples.resetExample();
|
||||||
|
});
|
||||||
|
$('#copyButton').click( function() {
|
||||||
|
// don't know why we need this twice, or the setTimeout
|
||||||
|
// guessing it's some interaction with the editor..
|
||||||
|
document.querySelector('textarea').select();
|
||||||
|
$('textarea')[0].select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
setTimeout(function() { document.execCommand('copy'); }, 200);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Example Frame
|
||||||
|
if($('#isMobile-displayButton').length !== 0) {
|
||||||
|
//it mobile
|
||||||
|
|
||||||
|
$('#isMobile-displayButton').click( function() {
|
||||||
|
|
||||||
|
$('#exampleFrame').show();
|
||||||
|
$('#exampleFrame').ready(function() {
|
||||||
|
// alert('exampleFrame load')
|
||||||
|
examples.loadExample(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$('#exampleFrame').load(function() {
|
||||||
|
examples.loadExample(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Capture clicks
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: file,
|
||||||
|
dataType: 'text'
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
$('#exampleSelector').hide();
|
||||||
|
|
||||||
|
// parse and set frame size
|
||||||
|
var frameReg = /@frame (.*),(.*)/g;
|
||||||
|
var arr = data.split(frameReg);
|
||||||
|
if (arr.length > 2) {
|
||||||
|
examples.dims[0] = arr[1];
|
||||||
|
examples.dims[1] = arr[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// render?
|
||||||
|
var norender = data.indexOf('@norender') !== -1;
|
||||||
|
|
||||||
|
// parse and set name, aria label, and description
|
||||||
|
var metaReg = new RegExp('\\* ', 'g');
|
||||||
|
var spaceReg = new RegExp(' ', 'g');
|
||||||
|
|
||||||
|
var startName = data.indexOf("@name")+6;
|
||||||
|
var endName = data.indexOf("\n", startName);
|
||||||
|
|
||||||
|
var name = startName !== 5 ? data.substring(startName, endName) : '';
|
||||||
|
|
||||||
|
var startAriaLabel = data.indexOf("@arialabel")+11;
|
||||||
|
var endAriaLabel = data.indexOf("\n", startAriaLabel);
|
||||||
|
|
||||||
|
var ariaLabel = startAriaLabel !== 10 ? data.substring(startAriaLabel, endAriaLabel) : '';
|
||||||
|
|
||||||
|
var startDesc = data.indexOf("@description")+13;
|
||||||
|
var endDesc = data.indexOf("*/", startDesc);
|
||||||
|
|
||||||
|
var desc = startDesc !== 12 ? data.substring(startDesc, endDesc) : '';
|
||||||
|
desc = desc.replace(metaReg, '');
|
||||||
|
|
||||||
|
$('#example-name').html(name);
|
||||||
|
$('#example-desc').html(desc);
|
||||||
|
$('#exampleFrame').attr("aria-label", ariaLabel);
|
||||||
|
|
||||||
|
// strip description and set code
|
||||||
|
var ind = data.indexOf('*/');
|
||||||
|
data = data.substring(ind+3);
|
||||||
|
examples.resetData = data;
|
||||||
|
|
||||||
|
examples.showExample(norender);
|
||||||
|
})
|
||||||
|
},
|
||||||
|
showExample: function(norender) {
|
||||||
|
examples.editor.getSession().setValue(examples.resetData);
|
||||||
|
|
||||||
|
//resize height of editor
|
||||||
|
var rows = examples.editor.getSession().$rowLengthCache.length;
|
||||||
|
var lineH = examples.editor.renderer.lineHeight;
|
||||||
|
$('#exampleEditor').height(rows*lineH+'px');
|
||||||
|
|
||||||
|
if (examples.resetData.indexOf('<!DOCTYPE html>') !== -1) {
|
||||||
|
examples.editor.getSession().setMode('ace/mode/html');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (norender) {
|
||||||
|
$('iframe').hide();
|
||||||
|
$('#resetButton').hide();
|
||||||
|
$('#runButton').hide();
|
||||||
|
$('#copyButton').hide();
|
||||||
|
} else {
|
||||||
|
examples.runExample();
|
||||||
|
$('#exampleDisplay').show();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// display iframe
|
||||||
|
runExample: function() {
|
||||||
|
$('#exampleFrame').attr('src', $('#exampleFrame').attr('src'));
|
||||||
|
},
|
||||||
|
resetExample: function() {
|
||||||
|
examples.showExample();
|
||||||
|
},
|
||||||
|
// load script into iframe
|
||||||
|
loadExample: function(isMobile) {
|
||||||
|
|
||||||
|
var exampleCode = examples.editor.getSession().getValue();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (exampleCode.indexOf('new p5()') === -1) {
|
||||||
|
exampleCode += '\nnew p5();';
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isMobile) {
|
||||||
|
|
||||||
|
$('#exampleFrame').css('position', 'fixed');
|
||||||
|
$('#exampleFrame').css('top', '0px');
|
||||||
|
$('#exampleFrame').css('left', '0px');
|
||||||
|
$('#exampleFrame').css('right', '0px');
|
||||||
|
$('#exampleFrame').css('bottom', '0px');
|
||||||
|
$('#exampleFrame').css('z-index', '999');
|
||||||
|
// var re = /createCanvas\((.*),(.*)\)/g;
|
||||||
|
// var arr = exampleCode.split(re);
|
||||||
|
// var height = $(screen).height();
|
||||||
|
// var width = $(screen).width()
|
||||||
|
// $('#exampleFrame').css('height', height+'px');
|
||||||
|
// $('#exampleFrame').css('width', width+'px');
|
||||||
|
// console.log(height + ' ,' + width);
|
||||||
|
//exampleCode = exampleCode.replace(/windowWidth/, winWidth).replace(/windowHeight/, winHeight);
|
||||||
|
|
||||||
|
// var userCSS = $('#exampleFrame')[0].contentWindow.document.createElement('style');
|
||||||
|
// userCSS.type = 'text/css';
|
||||||
|
// userCSS.innerHTML = 'html, body, canvas { width: 100% !important; height: 100% !important;}';
|
||||||
|
//$('#exampleFrame')[0].contentWindow.document.head.appendChild(userCSS);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (examples.dims.length < 2) {
|
||||||
|
var re = /createCanvas\((.*),(.*)\)/g;
|
||||||
|
var arr = exampleCode.split(re);
|
||||||
|
$('#exampleFrame').height(arr[2]+'px');
|
||||||
|
} else {
|
||||||
|
$('#exampleFrame').height(examples.dims[1]+'px');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var userScript = $('#exampleFrame')[0].contentWindow.document.createElement('script');
|
||||||
|
userScript.type = 'text/javascript';
|
||||||
|
userScript.text = exampleCode;
|
||||||
|
userScript.async = false;
|
||||||
|
$('#exampleFrame')[0].contentWindow.document.body.appendChild(userScript);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (typeof(window._p5jsExample) !== 'undefined') {
|
||||||
|
examples.init(window._p5jsExample);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (typeof(window._p5jsLanguage) !== 'undefined') {
|
||||||
|
// $('.example-link').each(function() {
|
||||||
|
// var name = $(this).data(window._p5jsLanguage);
|
||||||
|
// console.log(window._p5jsLanguage, name)
|
||||||
|
// $(this).text(name);
|
||||||
|
// });
|
||||||
|
// } else {
|
||||||
|
// console.log('no language')
|
||||||
|
// }
|
31
参考/p5-reference/js/get-started.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
const copyToClipboard = (element)=> {
|
||||||
|
const value = document.getElementById(element).innerText;
|
||||||
|
const el = document.createElement('textarea');
|
||||||
|
el.value = value;
|
||||||
|
el.setAttribute('readonly', '');
|
||||||
|
el.style.position = 'absolute';
|
||||||
|
el.style.left = '-9999px';
|
||||||
|
el.setAttribute('aria-hidden','true');
|
||||||
|
document.body.appendChild(el);
|
||||||
|
el.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(el);
|
||||||
|
}
|
||||||
|
$("#copy_sketch1").click(()=>{
|
||||||
|
copyToClipboard("first-sketch1");
|
||||||
|
})
|
||||||
|
$("#copy_sketch2").click(()=>{
|
||||||
|
copyToClipboard("first-sketch2");
|
||||||
|
});
|
||||||
|
$("#copy_sketch3").click(()=>{
|
||||||
|
copyToClipboard("first-sketch3");
|
||||||
|
});
|
||||||
|
$("#copy_p5_script").click(()=>{
|
||||||
|
copyToClipboard("markup1");
|
||||||
|
});
|
||||||
|
$("#copy_p5_link").click(()=>{
|
||||||
|
copyToClipboard("cdn-link");
|
||||||
|
});
|
||||||
|
$("#copy_p5_html").click(()=>{
|
||||||
|
copyToClipboard("sample-html");
|
||||||
|
});
|
220
参考/p5-reference/js/init.js
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
// =================================================
|
||||||
|
// Family bar:
|
||||||
|
window.onload = function() {
|
||||||
|
|
||||||
|
var test_js = function() {
|
||||||
|
// http://stackoverflow.com/a/12410668/1293700
|
||||||
|
document.documentElement.className = document.documentElement.className.replace(/\bno-js\b/,'') + ' js';
|
||||||
|
}();
|
||||||
|
var test_pointerevents = function() {
|
||||||
|
// https://github.com/ausi/Feature-detection-technique-for-pointer-events/blob/master/modernizr-pointerevents.js
|
||||||
|
var el = document.createElement('x');
|
||||||
|
el.style.cssText = 'pointer-events:auto';
|
||||||
|
return el.style.pointerEvents === 'auto';
|
||||||
|
};
|
||||||
|
if (test_pointerevents()) {
|
||||||
|
document.documentElement.className += ' pointerevents';
|
||||||
|
}
|
||||||
|
|
||||||
|
var search_form = document.getElementById('search_form'),
|
||||||
|
search_field = document.getElementById('search_field');
|
||||||
|
if (search_form) {
|
||||||
|
var open_field = function() {
|
||||||
|
search_form.className = 'form__open';
|
||||||
|
search_field.focus();
|
||||||
|
};
|
||||||
|
var close_field = function(e) {
|
||||||
|
if (e.type === 'focusout') {
|
||||||
|
search_form.className = '';
|
||||||
|
} else {
|
||||||
|
if (search_field.value === '') {
|
||||||
|
search_form.className = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (search_form.addEventListener) {
|
||||||
|
search_form.addEventListener('mouseover', open_field, false);
|
||||||
|
search_form.addEventListener('mouseout', close_field, false);
|
||||||
|
search_form.addEventListener('focusout', close_field, false);
|
||||||
|
} else { // IE
|
||||||
|
search_form.attachEvent('onmouseover', open_field);
|
||||||
|
search_form.attachEvent('onmouseout', close_field);
|
||||||
|
search_form.attachEvent('onfocusout', close_field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================================================
|
||||||
|
// set language and tagline
|
||||||
|
var path = window.location.pathname;
|
||||||
|
var parts = path.split('/');
|
||||||
|
for (var i=0; i<parts.length; i++) {
|
||||||
|
if (parts[i].length) {
|
||||||
|
var langMatch = 0;
|
||||||
|
for (var j=0; j<langs.length; j++) {
|
||||||
|
if (parts[i] === langs[j]) {
|
||||||
|
langMatch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!langMatch) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var taglines = document.getElementsByClassName('tagline'); //divsToHide is an array
|
||||||
|
if (taglines.length) {
|
||||||
|
var taglineInd = Math.floor(taglines.length * Math.random());
|
||||||
|
taglines[taglineInd].style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ===============================================
|
||||||
|
// Language detection:
|
||||||
|
|
||||||
|
var test_local_storage = function(w) {
|
||||||
|
var tmp = 'p5js';
|
||||||
|
try {
|
||||||
|
w.localStorage.setItem(tmp, tmp);
|
||||||
|
w.localStorage.removeItem(tmp);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var can_store = test_local_storage(window);
|
||||||
|
|
||||||
|
var get_browser_lang = function(w) {
|
||||||
|
var tmp = w.navigator.languages && w.navigator.languages[0]
|
||||||
|
|| w.navigator.language || w.navigator.userLanguage;
|
||||||
|
tmp = tmp.split('-')[0];
|
||||||
|
for (var i = 0; i < langs.length; i++) {
|
||||||
|
if (tmp == langs[i]) {
|
||||||
|
return langs[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'en';
|
||||||
|
};
|
||||||
|
var browser_lang = get_browser_lang(window);
|
||||||
|
|
||||||
|
var get_loc_lang = function(w) {
|
||||||
|
if ((w.location.pathname == '/') === false) {
|
||||||
|
for (var i = 0; i < langs.length; i++) {
|
||||||
|
if (w.location.pathname.indexOf('/' + langs[i] + '/') !== -1) {
|
||||||
|
if (can_store) {
|
||||||
|
window.localStorage.setItem('lang', langs[i]);
|
||||||
|
}
|
||||||
|
return langs[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'en';
|
||||||
|
};
|
||||||
|
var loc = String(window.location.pathname);
|
||||||
|
var loc_lang = get_loc_lang(window);
|
||||||
|
var is_root = (loc == '/');
|
||||||
|
|
||||||
|
// Default lang:
|
||||||
|
var lang = 'en';
|
||||||
|
if (can_store) {
|
||||||
|
if (window.localStorage.getItem('lang') !== null) {
|
||||||
|
var saved_lang = window.localStorage.getItem('lang');
|
||||||
|
if (saved_lang !== loc_lang) {
|
||||||
|
if (saved_lang == 'en') {
|
||||||
|
loc = '/' + loc.replace('\/' + loc_lang + '\/', '');
|
||||||
|
} else {
|
||||||
|
loc = '/' + saved_lang + loc;
|
||||||
|
}
|
||||||
|
window.location = loc;
|
||||||
|
} else {
|
||||||
|
lang = saved_lang;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (is_root && browser_lang != loc_lang) {
|
||||||
|
// if (lang !== 'pangu' || isStaging()) { // temp until chinese launch
|
||||||
|
loc = '/' + browser_lang;
|
||||||
|
window.location = loc;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lang = get_loc_lang();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.lang = lang;
|
||||||
|
|
||||||
|
// ===============================================
|
||||||
|
// Language change:
|
||||||
|
|
||||||
|
var els = document.getElementsByClassName('js-lang');
|
||||||
|
var el = null;
|
||||||
|
if (window.lang != 'en') {
|
||||||
|
for (var i = 0; i < els.length; i++) {
|
||||||
|
el = els[i];
|
||||||
|
el.innerHTML = el.getAttribute('data-' + window.lang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ===============================================
|
||||||
|
// Language buttons:
|
||||||
|
|
||||||
|
var btns = document.getElementById('i18n-btn').getElementsByTagName('a');
|
||||||
|
var evt_type = typeof document.addEventListener !== 'undefined' ? 'click' : 'onclick';
|
||||||
|
var click_action = function(e) {
|
||||||
|
var new_lang = this.getAttribute('data-lang');
|
||||||
|
//loc is defined second time below because while navigating from /reference/ to /reference/#/p5/displayWidth
|
||||||
|
//the page is not refreshing, so even if the page navigates properly to /reference/#/p5/displayWidth
|
||||||
|
//the window.location.hash remains empty
|
||||||
|
loc = String(window.location.pathname + window.location.hash);
|
||||||
|
if (new_lang == 'en') {
|
||||||
|
for (var j = 0; j < langs.length; j++) {
|
||||||
|
if (langs[j] != 'en') {
|
||||||
|
loc = loc.replace('\/' + langs[j] + '\/', '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var j = 0; j < langs.length; j++) {
|
||||||
|
loc = loc.replace('\/' + langs[j] + '\/', '/');
|
||||||
|
}
|
||||||
|
loc = '/' + new_lang + loc;
|
||||||
|
}
|
||||||
|
if (can_store) {
|
||||||
|
window.localStorage.setItem('lang', new_lang);
|
||||||
|
}
|
||||||
|
window.location = loc;
|
||||||
|
};
|
||||||
|
for (var i = 0; i < btns.length; i++) {
|
||||||
|
var btn_lang = btns[i].getAttribute('data-lang');
|
||||||
|
if (loc_lang == btn_lang) {
|
||||||
|
$(btns[i]).addClass('disabled');
|
||||||
|
} else {
|
||||||
|
$(btns[i]).removeClass('disabled');
|
||||||
|
if (evt_type === 'click') {
|
||||||
|
btns[i].addEventListener(evt_type, click_action, false);
|
||||||
|
} else { // IE
|
||||||
|
btns[i].attachEvent(evt_type, click_action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================================================
|
||||||
|
// Checking hash in URL
|
||||||
|
// this function runs when the DOM is ready, i.e. when the document has been parsed
|
||||||
|
setTimeout(function() {
|
||||||
|
if (location.hash) {
|
||||||
|
location.href = location.hash;
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
// =================================================
|
||||||
|
// Chinese spacing
|
||||||
|
if (window.pangu) {
|
||||||
|
pangu.spacingPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
function isStaging() {
|
||||||
|
return window.location.href.indexOf('staging') !== -1 || window.location.href.indexOf('localhost') !== -1;
|
||||||
|
}
|
||||||
|
}
|
2
参考/p5-reference/js/p5.min.js
vendored
Normal file
3
参考/p5-reference/js/p5.sound.min.js
vendored
Normal file
4947
参考/p5-reference/js/reference.js
Normal file
280
参考/p5-reference/js/render.js
Normal file
@ -0,0 +1,280 @@
|
|||||||
|
var renderCode = function(exampleName) {
|
||||||
|
var _p5 = p5;
|
||||||
|
var instances = [];
|
||||||
|
var selector = 'example';
|
||||||
|
var examples = document.getElementsByClassName(selector);
|
||||||
|
|
||||||
|
if (examples.length > 0) {
|
||||||
|
var sketches = examples[0].getElementsByTagName('code');
|
||||||
|
var sketches_array = Array.prototype.slice.call(sketches);
|
||||||
|
var i = 0;
|
||||||
|
sketches_array.forEach(function(s) {
|
||||||
|
var rc = s.parentNode.className.indexOf('norender') === -1;
|
||||||
|
setupCode(s, rc, i);
|
||||||
|
runCode(s, rc, i);
|
||||||
|
i++;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function enableTab(el) {
|
||||||
|
el.onkeydown = function(e) {
|
||||||
|
if (e.keyCode === 9) {
|
||||||
|
// tab was pressed
|
||||||
|
// get caret position/selection
|
||||||
|
var val = this.value,
|
||||||
|
start = this.selectionStart,
|
||||||
|
end = this.selectionEnd;
|
||||||
|
// set textarea value to: text before caret + tab + text after caret
|
||||||
|
this.value = val.substring(0, start) + ' ' + val.substring(end);
|
||||||
|
// put caret at right position again
|
||||||
|
this.selectionStart = this.selectionEnd = start + 2;
|
||||||
|
// prevent the focus lose
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupCode(sketch, rc, i) {
|
||||||
|
var isRef = sketch.parentNode.tagName !== 'PRE';
|
||||||
|
var sketchNode = isRef ? sketch : sketch.parentNode;
|
||||||
|
var sketchContainer = sketchNode.parentNode;
|
||||||
|
|
||||||
|
if (isRef) {
|
||||||
|
$(sketchContainer).prepend('<h4 id="example'+i+'" class="sr-only">'+exampleName+' example '+i+'</h4>');
|
||||||
|
var pre = document.createElement('pre');
|
||||||
|
pre.classList.add('ref');
|
||||||
|
pre.classList.add('example_code');
|
||||||
|
pre.appendChild(sketchNode);
|
||||||
|
sketchContainer.appendChild(pre);
|
||||||
|
sketchContainer.className = 'example_container';
|
||||||
|
sketch.className = 'language-javascript';
|
||||||
|
if (!rc) {
|
||||||
|
pre.className += ' norender';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove start and end lines
|
||||||
|
var runnable = sketch.textContent.replace(/^\s+|\s+$/g, '');
|
||||||
|
var rows = sketch.textContent.split('\n').length;
|
||||||
|
|
||||||
|
// store original sketch
|
||||||
|
var orig_sketch = document.createElement('div');
|
||||||
|
orig_sketch.innerHTML = sketch.innerHTML;
|
||||||
|
|
||||||
|
// create canvas
|
||||||
|
if (rc) {
|
||||||
|
var cnv = document.createElement('div');
|
||||||
|
cnv.className = 'cnv_div';
|
||||||
|
if (isRef) {
|
||||||
|
sketchContainer.prepend(cnv);
|
||||||
|
} else {
|
||||||
|
sketchContainer.parentNode.insertBefore(cnv, sketchContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// create edit space
|
||||||
|
let edit_space = document.createElement('div');
|
||||||
|
edit_space.className = 'edit_space';
|
||||||
|
sketchContainer.appendChild(edit_space);
|
||||||
|
$(edit_space).append('<h5 class="sr-only" id="buttons"'+i+' aria-labelledby="buttons'+i+' example'+i+'">buttons</h5>');
|
||||||
|
|
||||||
|
var edit_area = document.createElement('textarea');
|
||||||
|
edit_area.value = runnable;
|
||||||
|
edit_area.rows = rows;
|
||||||
|
edit_area.cols = 62;
|
||||||
|
edit_area.classList.add('edit_area');
|
||||||
|
edit_space.appendChild(edit_area);
|
||||||
|
enableTab(edit_area);
|
||||||
|
|
||||||
|
//add buttons
|
||||||
|
let button_space = document.createElement('ul');
|
||||||
|
edit_space.appendChild(button_space);
|
||||||
|
|
||||||
|
let copy_button = document.createElement('button');
|
||||||
|
copy_button.value = 'copy';
|
||||||
|
copy_button.innerHTML = 'copy';
|
||||||
|
copy_button.id = 'copy' + i;
|
||||||
|
copy_button.setAttribute('aria-labelledby', copy_button.id + ' example' + i);
|
||||||
|
copy_button.className = 'copy_button';
|
||||||
|
copy_button.onclick = function() {
|
||||||
|
setMode(sketch, 'edit');
|
||||||
|
edit_area.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
};
|
||||||
|
let copy_li = button_space.appendChild(document.createElement('li'));
|
||||||
|
copy_li.appendChild(copy_button);
|
||||||
|
|
||||||
|
let reset_button = document.createElement('button');
|
||||||
|
reset_button.value = 'reset';
|
||||||
|
reset_button.innerHTML = 'reset';
|
||||||
|
reset_button.id = 'reset' + i;
|
||||||
|
reset_button.setAttribute('aria-labelledby', reset_button.id + ' example' + i);
|
||||||
|
reset_button.className = 'reset_button';
|
||||||
|
reset_button.onclick = function() {
|
||||||
|
edit_area.value = orig_sketch.textContent;
|
||||||
|
setMode(sketch, 'run');
|
||||||
|
};
|
||||||
|
let reset_li = button_space.appendChild(document.createElement('li'));
|
||||||
|
reset_li.appendChild(reset_button);
|
||||||
|
|
||||||
|
let edit_button = document.createElement('button');
|
||||||
|
edit_button.value = 'edit';
|
||||||
|
edit_button.innerHTML = 'edit';
|
||||||
|
edit_button.id = 'edit' + i;
|
||||||
|
edit_button.setAttribute('aria-labelledby', edit_button.id + ' example' + i);
|
||||||
|
edit_button.className = 'edit_button';
|
||||||
|
edit_button.onclick = function(e) {
|
||||||
|
if (edit_button.innerHTML === 'edit') {
|
||||||
|
// edit
|
||||||
|
setMode(sketch, 'edit');
|
||||||
|
} else {
|
||||||
|
// run
|
||||||
|
setMode(sketch, 'run');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let edit_li = button_space.appendChild(document.createElement('li'));
|
||||||
|
edit_li.appendChild(edit_button);
|
||||||
|
|
||||||
|
function setMode(sketch, m) {
|
||||||
|
if (m === 'edit') {
|
||||||
|
$('.example_container').each(function(ind, con) {
|
||||||
|
if (ind !== i) {
|
||||||
|
$(con).css('opacity', 0.25);
|
||||||
|
} else {
|
||||||
|
$(con).addClass('editing');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
edit_button.innerHTML = 'run';
|
||||||
|
edit_area.style.display = 'block';
|
||||||
|
edit_area.focus();
|
||||||
|
} else {
|
||||||
|
edit_button.innerHTML = 'edit';
|
||||||
|
edit_area.style.display = 'none';
|
||||||
|
sketch.textContent = edit_area.value;
|
||||||
|
$('.example_container').each(function(ind, con) {
|
||||||
|
$(con).css('opacity', 1.0);
|
||||||
|
$(con).removeClass('editing');
|
||||||
|
});
|
||||||
|
runCode(sketch, true, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function runCode(sketch, rc, i) {
|
||||||
|
if (instances[i]) {
|
||||||
|
instances[i].remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
var sketchNode = sketch.parentNode;
|
||||||
|
var isRef = sketchNode.className.indexOf('ref') !== -1;
|
||||||
|
var sketchContainer = sketchNode.parentNode;
|
||||||
|
var parent = sketchContainer.parentNode;
|
||||||
|
|
||||||
|
var runnable = sketch.textContent.replace(/^\s+|\s+$/g, '');
|
||||||
|
var cnv;
|
||||||
|
|
||||||
|
if (rc) {
|
||||||
|
if (isRef) {
|
||||||
|
cnv = sketchContainer.getElementsByClassName('cnv_div')[0];
|
||||||
|
} else {
|
||||||
|
cnv = parent.parentNode.getElementsByClassName('cnv_div')[0];
|
||||||
|
}
|
||||||
|
cnv.innerHTML = '';
|
||||||
|
|
||||||
|
var s = function(p) {
|
||||||
|
var fxns = [
|
||||||
|
'setup', 'draw', 'preload', 'mousePressed', 'mouseReleased',
|
||||||
|
'mouseMoved', 'mouseDragged', 'mouseClicked', 'doubleClicked',
|
||||||
|
'mouseWheel', 'touchStarted', 'touchMoved', 'touchEnded',
|
||||||
|
'keyPressed', 'keyReleased', 'keyTyped'
|
||||||
|
];
|
||||||
|
var _found = [];
|
||||||
|
// p.preload is an empty function created by the p5.sound library in order to use the p5.js preload system
|
||||||
|
// to load AudioWorklet modules before a sketch runs, even if that sketch doesn't have its own preload function.
|
||||||
|
// However, this causes an error in the eval code below because the _found array will always contain "preload",
|
||||||
|
// even if the sketch in question doesn't have a preload function. To get around this, we delete p.preload before
|
||||||
|
// eval-ing the sketch and add it back afterwards if the sketch doesn't contain its own preload function.
|
||||||
|
// For more info, see: https://github.com/processing/p5.js-sound/blob/master/src/audioWorklet/index.js#L22
|
||||||
|
if (p.preload) {
|
||||||
|
delete p.preload;
|
||||||
|
}
|
||||||
|
with (p) {
|
||||||
|
// Builds a function to detect declared functions via
|
||||||
|
// them being hoisted past the return statement. Does
|
||||||
|
// not execute runnable. Two returns with different
|
||||||
|
// conditions guarantee a return but suppress unreachable
|
||||||
|
// code warnings.
|
||||||
|
eval([
|
||||||
|
'(function() {',
|
||||||
|
fxns.map(function (_name) {
|
||||||
|
return [
|
||||||
|
'try {',
|
||||||
|
' eval(' + _name + ');',
|
||||||
|
' _found.push(\'' + _name + '\');',
|
||||||
|
'} catch(e) {',
|
||||||
|
' if(!(e instanceof ReferenceError)) {',
|
||||||
|
' throw e;',
|
||||||
|
' }',
|
||||||
|
'}'
|
||||||
|
].join('');
|
||||||
|
}).join(''),
|
||||||
|
'if(_found.length) return;',
|
||||||
|
'if(!_found.length) return;',
|
||||||
|
runnable,
|
||||||
|
'})();'
|
||||||
|
].join('\n'));
|
||||||
|
}
|
||||||
|
// If we haven't found any functions we'll assume it's
|
||||||
|
// just a setup body with an empty preload.
|
||||||
|
if (!_found.length) {
|
||||||
|
p.preload = function() {};
|
||||||
|
p.setup = function() {
|
||||||
|
p.createCanvas(100, 100);
|
||||||
|
p.background(200);
|
||||||
|
with (p) {
|
||||||
|
eval(runnable);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// Actually runs the code to get functions into scope.
|
||||||
|
with (p) {
|
||||||
|
eval(runnable);
|
||||||
|
}
|
||||||
|
_found.forEach(function(name) {
|
||||||
|
p[name] = eval(name);
|
||||||
|
});
|
||||||
|
// Ensure p.preload exists even if the sketch doesn't have a preload function.
|
||||||
|
p.preload = p.preload || function() {};
|
||||||
|
p.setup = p.setup || function() {
|
||||||
|
p.createCanvas(100, 100);
|
||||||
|
p.background(200);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//if (typeof prettyPrint !== 'undefined') prettyPrint();
|
||||||
|
if (typeof Prism !== 'undefined') {
|
||||||
|
Prism.highlightAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// when a hash is changed, remove all the sounds,
|
||||||
|
// even tho the p5 sketch has been disposed.
|
||||||
|
function registerHashChange() {
|
||||||
|
window.onhashchange = function(e) {
|
||||||
|
for (var i = 0; i < instances.length; i++) {
|
||||||
|
instances[i].remove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
registerHashChange();
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
var myp5 = new _p5(s, cnv);
|
||||||
|
instances[i] = myp5;
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
13
参考/p5-reference/js/slideshow.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
var slideIndex = 0;
|
||||||
|
carousel();
|
||||||
|
|
||||||
|
function carousel() {
|
||||||
|
var x = $("#slideshow").children();
|
||||||
|
for (var i = 0; i < x.length; i++) {
|
||||||
|
x[i].style.display = "none";
|
||||||
|
}
|
||||||
|
slideIndex++;
|
||||||
|
if (slideIndex > x.length) {slideIndex = 1}
|
||||||
|
x[slideIndex-1].style.display = "block";
|
||||||
|
setTimeout(carousel, 4000);
|
||||||
|
}
|
15
参考/p5-reference/js/teach.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
$("#filter-options :checkbox").click(function()
|
||||||
|
{
|
||||||
|
$("#filter-list li").hide();
|
||||||
|
$("#filter-options :checkbox:checked").each(function()
|
||||||
|
{
|
||||||
|
$("." + $(this).val()).fadeIn();
|
||||||
|
});
|
||||||
|
|
||||||
|
if($('#filter-options :checkbox').filter(':checked').length < 1)
|
||||||
|
{
|
||||||
|
$("#filter-list li").fadeIn();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
11
参考/p5-reference/js/vendor/ace-nc/ace.js
vendored
Normal file
5
参考/p5-reference/js/vendor/ace-nc/ext-beautify.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
ace.define("ace/ext/beautify/php_rules",["require","exports","module","ace/token_iterator"],function(e,t,n){"use strict";var r=e("ace/token_iterator").TokenIterator;t.newLines=[{type:"support.php_tag",value:"<?php"},{type:"support.php_tag",value:"<?"},{type:"support.php_tag",value:"?>"},{type:"paren.lparen",value:"{",indent:!0},{type:"paren.rparen",breakBefore:!0,value:"}",indent:!1},{type:"paren.rparen",breakBefore:!0,value:"})",indent:!1,dontBreak:!0},{type:"comment"},{type:"text",value:";"},{type:"text",value:":",context:"php"},{type:"keyword",value:"case",indent:!0,dontBreak:!0},{type:"keyword",value:"default",indent:!0,dontBreak:!0},{type:"keyword",value:"break",indent:!1,dontBreak:!0},{type:"punctuation.doctype.end",value:">"},{type:"meta.tag.punctuation.end",value:">"},{type:"meta.tag.punctuation.begin",value:"<",blockTag:!0,indent:!0,dontBreak:!0},{type:"meta.tag.punctuation.begin",value:"</",indent:!1,breakBefore:!0,dontBreak:!0},{type:"punctuation.operator",value:";"}],t.spaces=[{type:"xml-pe",prepend:!0},{type:"entity.other.attribute-name",prepend:!0},{type:"storage.type",value:"var",append:!0},{type:"storage.type",value:"function",append:!0},{type:"keyword.operator",value:"="},{type:"keyword",value:"as",prepend:!0,append:!0},{type:"keyword",value:"function",append:!0},{type:"support.function",next:/[^\(]/,append:!0},{type:"keyword",value:"or",append:!0,prepend:!0},{type:"keyword",value:"and",append:!0,prepend:!0},{type:"keyword",value:"case",append:!0},{type:"keyword.operator",value:"||",append:!0,prepend:!0},{type:"keyword.operator",value:"&&",append:!0,prepend:!0}],t.singleTags=["!doctype","area","base","br","hr","input","img","link","meta"],t.transform=function(e,n,r){var i=e.getCurrentToken(),s=t.newLines,o=t.spaces,u=t.singleTags,a="",f=0,l=!1,c,h,p={},d,v={},m=!1,g="";while(i!==null){console.log(i);if(!i){i=e.stepForward();continue}i.type=="support.php_tag"&&i.value!="?>"?r="php":i.type=="support.php_tag"&&i.value=="?>"?r="html":i.type=="meta.tag.name.style"&&r!="css"?r="css":i.type=="meta.tag.name.style"&&r=="css"?r="html":i.type=="meta.tag.name.script"&&r!="js"?r="js":i.type=="meta.tag.name.script"&&r=="js"&&(r="html"),v=e.stepForward(),v&&v.type.indexOf("meta.tag.name")==0&&(d=v.value),p.type=="support.php_tag"&&p.value=="<?="&&(l=!0),i.type=="meta.tag.name"&&(i.value=i.value.toLowerCase()),i.type=="text"&&(i.value=i.value.trim());if(!i.value){i=v;continue}g=i.value;for(var y in o)i.type==o[y].type&&(!o[y].value||i.value==o[y].value)&&v&&(!o[y].next||o[y].next.test(v.value))&&(o[y].prepend&&(g=" "+i.value),o[y].append&&(g+=" "));i.type.indexOf("meta.tag.name")==0&&(c=i.value),m=!1;for(y in s)if(i.type==s[y].type&&(!s[y].value||i.value==s[y].value)&&(!s[y].blockTag||u.indexOf(d)===-1)&&(!s[y].context||s[y].context===r)){s[y].indent===!1&&f--;if(s[y].breakBefore&&(!s[y].prev||s[y].prev.test(p.value))){a+="\n",m=!0;for(y=0;y<f;y++)a+=" "}break}if(l===!1)for(y in s)if(p.type==s[y].type&&(!s[y].value||p.value==s[y].value)&&(!s[y].blockTag||u.indexOf(c)===-1)&&(!s[y].context||s[y].context===r)){s[y].indent===!0&&f++;if(!s[y].dontBreak&&!m){a+="\n";for(y=0;y<f;y++)a+=" "}break}a+=g,p.type=="support.php_tag"&&p.value=="?>"&&(l=!1),h=c,p=i,i=v;if(i===null)break}return a}}),ace.define("ace/ext/beautify",["require","exports","module","ace/token_iterator","ace/ext/beautify/php_rules"],function(e,t,n){"use strict";var r=e("ace/token_iterator").TokenIterator,i=e("./beautify/php_rules").transform;t.beautify=function(e){var t=new r(e,0,0),n=t.getCurrentToken(),s=e.$modeId.split("/").pop(),o=i(t,s);e.doc.setValue(o)},t.commands=[{name:"beautify",exec:function(e){t.beautify(e.session)},bindKey:"Ctrl-Shift-B"}]});
|
||||||
|
(function() {
|
||||||
|
ace.require(["ace/ext/beautify"], function() {});
|
||||||
|
})();
|
||||||
|
|
5
参考/p5-reference/js/vendor/ace-nc/ext-chromevox.js
vendored
Normal file
5
参考/p5-reference/js/vendor/ace-nc/ext-elastic_tabstops_lite.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
ace.define("ace/ext/elastic_tabstops_lite",["require","exports","module","ace/editor","ace/config"],function(e,t,n){"use strict";var r=function(e){this.$editor=e;var t=this,n=[],r=!1;this.onAfterExec=function(){r=!1,t.processRows(n),n=[]},this.onExec=function(){r=!0},this.onChange=function(e){var t=e.data.range;r&&(n.indexOf(t.start.row)==-1&&n.push(t.start.row),t.end.row!=t.start.row&&n.push(t.end.row))}};(function(){this.processRows=function(e){this.$inChange=!0;var t=[];for(var n=0,r=e.length;n<r;n++){var i=e[n];if(t.indexOf(i)>-1)continue;var s=this.$findCellWidthsForBlock(i),o=this.$setBlockCellWidthsToMax(s.cellWidths),u=s.firstRow;for(var a=0,f=o.length;a<f;a++){var l=o[a];t.push(u),this.$adjustRow(u,l),u++}}this.$inChange=!1},this.$findCellWidthsForBlock=function(e){var t=[],n,r=e;while(r>=0){n=this.$cellWidthsForRow(r);if(n.length==0)break;t.unshift(n),r--}var i=r+1;r=e;var s=this.$editor.session.getLength();while(r<s-1){r++,n=this.$cellWidthsForRow(r);if(n.length==0)break;t.push(n)}return{cellWidths:t,firstRow:i}},this.$cellWidthsForRow=function(e){var t=this.$selectionColumnsForRow(e),n=[-1].concat(this.$tabsForRow(e)),r=n.map(function(e){return 0}).slice(1),i=this.$editor.session.getLine(e);for(var s=0,o=n.length-1;s<o;s++){var u=n[s]+1,a=n[s+1],f=this.$rightmostSelectionInCell(t,a),l=i.substring(u,a);r[s]=Math.max(l.replace(/\s+$/g,"").length,f-u)}return r},this.$selectionColumnsForRow=function(e){var t=[],n=this.$editor.getCursorPosition();return this.$editor.session.getSelection().isEmpty()&&e==n.row&&t.push(n.column),t},this.$setBlockCellWidthsToMax=function(e){var t=!0,n,r,i,s=this.$izip_longest(e);for(var o=0,u=s.length;o<u;o++){var a=s[o];if(!a.push){console.error(a);continue}a.push(NaN);for(var f=0,l=a.length;f<l;f++){var c=a[f];t&&(n=f,i=0,t=!1);if(isNaN(c)){r=f;for(var h=n;h<r;h++)e[h][o]=i;t=!0}i=Math.max(i,c)}}return e},this.$rightmostSelectionInCell=function(e,t){var n=0;if(e.length){var r=[];for(var i=0,s=e.length;i<s;i++)e[i]<=t?r.push(i):r.push(0);n=Math.max.apply(Math,r)}return n},this.$tabsForRow=function(e){var t=[],n=this.$editor.session.getLine(e),r=/\t/g,i;while((i=r.exec(n))!=null)t.push(i.index);return t},this.$adjustRow=function(e,t){var n=this.$tabsForRow(e);if(n.length==0)return;var r=0,i=-1,s=this.$izip(t,n);for(var o=0,u=s.length;o<u;o++){var a=s[o][0],f=s[o][1];i+=1+a,f+=r;var l=i-f;if(l==0)continue;var c=this.$editor.session.getLine(e).substr(0,f),h=c.replace(/\s*$/g,""),p=c.length-h.length;l>0&&(this.$editor.session.getDocument().insertInLine({row:e,column:f+1},Array(l+1).join(" ")+" "),this.$editor.session.getDocument().removeInLine(e,f,f+1),r+=l),l<0&&p>=-l&&(this.$editor.session.getDocument().removeInLine(e,f+l,f),r+=l)}},this.$izip_longest=function(e){if(!e[0])return[];var t=e[0].length,n=e.length;for(var r=1;r<n;r++){var i=e[r].length;i>t&&(t=i)}var s=[];for(var o=0;o<t;o++){var u=[];for(var r=0;r<n;r++)e[r][o]===""?u.push(NaN):u.push(e[r][o]);s.push(u)}return s},this.$izip=function(e,t){var n=e.length>=t.length?t.length:e.length,r=[];for(var i=0;i<n;i++){var s=[e[i],t[i]];r.push(s)}return r}}).call(r.prototype),t.ElasticTabstopsLite=r;var i=e("../editor").Editor;e("../config").defineOptions(i.prototype,"editor",{useElasticTabstops:{set:function(e){e?(this.elasticTabstops||(this.elasticTabstops=new r(this)),this.commands.on("afterExec",this.elasticTabstops.onAfterExec),this.commands.on("exec",this.elasticTabstops.onExec),this.on("change",this.elasticTabstops.onChange)):this.elasticTabstops&&(this.commands.removeListener("afterExec",this.elasticTabstops.onAfterExec),this.commands.removeListener("exec",this.elasticTabstops.onExec),this.removeListener("change",this.elasticTabstops.onChange))}}})});
|
||||||
|
(function() {
|
||||||
|
ace.require(["ace/ext/elastic_tabstops_lite"], function() {});
|
||||||
|
})();
|
||||||
|
|