Skip to content

Commit

Permalink
add demo
Browse files Browse the repository at this point in the history
  • Loading branch information
pointworld committed Oct 10, 2018
1 parent d61e832 commit 39ed714
Show file tree
Hide file tree
Showing 46 changed files with 6,138 additions and 150 deletions.
2 changes: 1 addition & 1 deletion test/animate.html → demo/animate.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>animate</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
2 changes: 1 addition & 1 deletion test/animate_gif.html → demo/animate_gif.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>animate gif</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
48 changes: 24 additions & 24 deletions test/beautiful_sky.html → demo/beautiful_sky.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>beautiful sky</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down Expand Up @@ -35,50 +35,50 @@
const nodes = []

function create_node() {
const x = Math.random()*stage.width
const y = Math.random()*stage.height
const x = Math.random() * stage.width
const y = Math.random() * stage.height
const node = new Pw.CircleNode()
node.vx = Math.random()*6-3
node.vy = Math.random()*6 - 3
node.radius = Math.random()*10+2
node.vx = Math.random() * 6 - 3
node.vy = Math.random() * 6 - 3
node.radius = Math.random() * 10 + 2
node.mass = node.radius
node.fillColor = Pw.util.randomColor()
node.setLocation(x,y)
node.setLocation(x, y)
scene.add(node)
return node
}

for (let i=0;i<90;i++){
for (let i = 0; i < 90; i++) {
const node = create_node()
nodes.push(node)
}

function move(node) {
node.x += node.vx
node.y += node.vy
if (node.x>stage.width)node.x = 0
if (node.y>stage.height) node.y = 0
if (node.x-node.width<0) node.x = stage.width
if(node.y - node.height < 0) node.y = stage.height
if (node.x > stage.width) node.x = 0
if (node.y > stage.height) node.y = 0
if (node.x - node.width < 0) node.x = stage.width * Math.random()
if (node.y - node.height < 0) node.y = stage.height * Math.random()
}

const minDist =100
const minDist = 100
const springAmount = .0025

function spring(a, b){
function spring(a, b) {
const dx = b.x - a.x
const dy = b.y - a.y

const dist = Pw.util.getDistance(a, b)

if (dist<minDist){
if (dist < minDist) {
const g = stage.graphics
const alpha = 1 - dist/minDist
const alpha = 1 - dist / minDist
g.beginPath()
g.strokeStyle = 'rgba(255,255,255,'+alpha+')'
g.strokeStyle = 'rgba(255,255,255,' + alpha + ')'
g.lineWidth = 1
g.moveTo(a.x + a.width/2, a.y + a.height/2)
g.lineTo(b.x + b.width/2, b.y + b.height/2)
g.moveTo(a.x + a.width / 2, a.y + a.height / 2)
g.lineTo(b.x + b.width / 2, b.y + b.height / 2)
g.stroke()
g.closePath()
const ax = dx * springAmount
Expand All @@ -90,11 +90,11 @@
}
}

(function f(){
(function f() {
stage.paint()
for(var i=0; i<nodes.length; i++){
for(var j=0; j<nodes.length; j++){
if(j == i) continue
for (var i = 0; i < nodes.length; i++) {
for (var j = 0; j < nodes.length; j++) {
if (j == i) continue
spring(nodes[i], nodes[j])
}
move(nodes[i])
Expand All @@ -103,7 +103,7 @@
requestAnimationFrame(f)
})()

stage.addEventListener('mouseup', function(e){
stage.addEventListener('mouseup', function (e) {
var node = create_node()
node.setLocation(e.x, e.y)
nodes.push(node)
Expand Down
2 changes: 1 addition & 1 deletion test/chart_bar.html → demo/chart_bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>bar chart</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
2 changes: 1 addition & 1 deletion test/chart_pie.html → demo/chart_pie.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>pie chart</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
2 changes: 1 addition & 1 deletion test/containerGroup.html → demo/containerGroup.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>container group</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
2 changes: 1 addition & 1 deletion test/cut_fruit.html → demo/cut_fruit.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>cut fruit</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
2 changes: 1 addition & 1 deletion test/eagleEye.html → demo/eagleEye.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>eagle eye</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
2 changes: 1 addition & 1 deletion test/effect_gravity.html → demo/effect_gravity.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>gravity effect</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>spring chains effect</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>multi-nodes spring effect</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>multi-targets spring effect</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>simple spring effect</title>
<script src="../dist/pw.js"></script>
<script src="./js/pw.js"></script>
<style>
body {
padding: 0;
Expand Down
20 changes: 14 additions & 6 deletions test/index.html → demo/helloworld.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<script src="../dist/pw.js"></script>
<title>hello world</title>
<script src="./js/pw.js"></script>
<style>
#canvas {
margin-left: 50px;
margin-top: 50px;
border: 2px solid red;
body {
padding: 0;
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<canvas id="canvas" width="500" height="350"></canvas>

<script>
canvas.width = document.documentElement.clientWidth
canvas.height = document.documentElement.clientHeight

window.addEventListener('resize', function () {
canvas.width = document.documentElement.clientWidth
canvas.height = document.documentElement.clientHeight
})

const stage = new Pw.Stage(canvas)
const scene = new Pw.Scene(stage)
scene.background = './img/bg.jpg'

function newNode(x, y, w, h, text) {
const node = new Pw.Node(text)
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading

0 comments on commit 39ed714

Please sign in to comment.