Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
<html> <head> <script> var Template = {}; var requestAnimationFrame = window.requestAnimationFrame|| window.webkitRequestAnimationFrame|| window.mozRequestAnimationFrame|| window.oRequestAnimationFrame|| window.msRequestAnimationFrame; var cancelAnimationFrame = window.cancelAnimationFrame|| window.webkitCancelRequestAnimationFrame|| window.webkitCancelAnimationFrame|| window.mozCancelRequestAnimationFrame|| window.mozCancelAnimationFrame|| window.oCancelRequestAnimationFrame|| window.oCancelAnimationFrame|| window.msCancelRequestAnimationFrame|| window.msCancelAnimationFrame; Template.newTime = Date.now(); Template.time = 0; Template.animation = function() { if(!Template.stopped) { Template.oldTime = Template.newTime; if(!Template.paused) { Template.calculate(); } Template.draw(); Template.newTime = Date.now(); Template.time=Template.newTime-Template.oldTime; Template.animationFrame = requestAnimationFrame(Template.animation); } } Template.start = function(d,c) { Template.draw = d; Template.calculate = c; Template.paused = false; Template.animationFrame = requestAnimationFrame(Template.animation); } Template.stop = function() { cancelAnimationFrame(Template.animationFrame); } function Transition(start,end,period,loops,func) { this.start = start; this.end = end; this.period = period; if(!func)this.func = function(a){return a;}; else this.func = func; this.pos = 0; this.reversed; this.loop = loops; this.res = 0; this.calc=function() { if(this.reversed) this.pos -= Template.time/this.period; else this.pos += Template.time/this.period; if(this.loop===0) { this.pos = (this.pos+1)%1; } else { this.pos = Math.min(this.loop,Math.max(this.pos,0)); } this.res = this.func(this.pos)*(end-start)+start; } this.get = function() { return this.res; } this.reverse = function() { this.reversed = !this.reversed; } } </script> <script> function Point(x,y) { this.x = x; this.y = y; this.draw = function(G) { G.beginPath(); G.moveTo(this.x+10,this.y); G.arc(this.x,this.y,10,0,2*Math.PI); G.stroke(); } } function Line(xs,ys,xe,ye) { this.start = new Point(xs,ys); this.end = new Point(xe,ye); this.Intersects = function(line,x,y,x1,y1) { x = +x|0; y = +y|0; x1 = +x1|0; y1 = +y1|0; return get_line_intersection(this.start.x+x,this.start.y+y, this.end.x+x,this.end.y+y, line.start.x+x1,line.start.y+y1, line.end.x+x1,line.end.y+y1); } } function Mesh(x,y,strokeStyle,fillStyle) { this.prevPoint = null; this.lines = []; this.x = x; this.y = y; this.strokeStyle = strokeStyle; this.fillStyle = fillStyle; this.add = function(point,index) { if(this.prevPoint) { index = +index|this.lines.length; this.lines.splice(index,0,new Line(this.prevPoint.x,this.prevPoint.y,point.x,point.y)); } this.prevPoint = new Point(point.x,point.y); } this.collides = function(thing) { var collisions = []; if(thing.constructor == Mesh) { var mesh = thing; for(var a=0,aa=this.lines.length; a<aa; a++) { for(var b=0,bb=mesh.lines.length; b<bb; b++) { var collision = this.lines[a].Intersects(mesh.lines[b],this.x,this.y,mesh.x,mesh.y); if(collision)collisions[collisions.length] = collision; } } } else if(thing.constructor == Line) { var line = thing; for(var a=0,aa=this.lines.length; a<aa; a++) { var collision = this.lines[a].Intersects(line,this.x,this.y); if(collision)collisions[collisions.length] = collision; } } return collisions; } this.FinishMesh = function() { if(this.lines.length==0)return false; this.add(new Point(this.lines[0].start.x,this.lines[0].start.y)); this.finished = true; return true; } this.draw = function(G) { G.strokeStyle = this.strokeStyle; G.fillStyle = this.fillStyle; if(this.lines.length==0)return false; G.beginPath(); G.moveTo(this.lines[0].start.x+this.x,this.lines[0].start.y+this.y); for(var a=0; a<this.lines.length; a++) { G.lineTo(this.lines[a].end.x+this.x,this.lines[a].end.y+this.y); } if(this.finished)G.fill(); G.stroke(); return true; } } function get_line_intersection(p0_x,p0_y,p1_x,p1_y,p2_x,p2_y,p3_x,p3_y) { var s1_x, s1_y, s2_x, s2_y; s1_x = p1_x - p0_x; s1_y = p1_y - p0_y; s2_x = p3_x - p2_x; s2_y = p3_y - p2_y; var cache2=(-s2_x * s1_y + s1_x * s2_y); if(cache2===0) return false; // Parallel var s, t; var cache0=(p0_y - p2_y); var cache1=(p0_x - p2_x); s = (-s1_y * cache1 + s1_x * cache0) / cache2; t = ( s2_x * cache0 - s2_y * cache1) / cache2; if (s >= 0 && s <= 1 && t >= 0 && t <= 1) { // Collision detected return new Point(p0_x + (t * s1_x),p0_y + (t * s1_y)); } return false; // No collision } </script> <script> /****************************************************************************** * Created 2008-08-19. * * Dijkstra path-finding functions. Adapted from the Dijkstar Python project. * * Copyright (C) 2008 * Wyatt Baldwin <self@wyattbaldwin.com> * All rights reserved * * Licensed under the MIT license. * * http://www.opensource.org/licenses/mit-license.php * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. *****************************************************************************/ var dijkstra = { single_source_shortest_paths: function(graph, s, d) { // Predecessor map for each node that has been encountered. // node ID => predecessor node ID var predecessors = {}; // Costs of shortest paths from s to all nodes encountered. // node ID => cost var costs = {}; costs[s] = 0; // Costs of shortest paths from s to all nodes encountered; differs from // `costs` in that it provides easy access to the node that currently has // the known shortest path from s. // XXX: Do we actually need both `costs` and `open`? var open = dijkstra.PriorityQueue.make(); open.push(s, 0); var closest, u, v, cost_of_s_to_u, adjacent_nodes, cost_of_e, cost_of_s_to_u_plus_cost_of_e, cost_of_s_to_v, first_visit; while (!open.empty()) { // In the nodes remaining in graph that have a known cost from s, // find the node, u, that currently has the shortest path from s. closest = open.pop(); u = closest.value; cost_of_s_to_u = closest.cost; // Get nodes adjacent to u... adjacent_nodes = graph[u] || {}; // ...and explore the edges that connect u to those nodes, updating // the cost of the shortest paths to any or all of those nodes as // necessary. v is the node across the current edge from u. for (v in adjacent_nodes) { // Get the cost of the edge running from u to v. cost_of_e = adjacent_nodes[v]; // Cost of s to u plus the cost of u to v across e--this is *a* // cost from s to v that may or may not be less than the current // known cost to v. cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e; // If we haven't visited v yet OR if the current known cost from s to // v is greater than the new cost we just found (cost of s to u plus // cost of u to v across e), update v's cost in the cost list and // update v's predecessor in the predecessor list (it's now u). cost_of_s_to_v = costs[v]; first_visit = (typeof costs[v] === 'undefined'); if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) { costs[v] = cost_of_s_to_u_plus_cost_of_e; open.push(v, cost_of_s_to_u_plus_cost_of_e); predecessors[v] = u; } } } if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') { var msg = ['Could not find a path from ', s, ' to ', d, '.'].join(''); throw new Error(msg); } return predecessors; }, extract_shortest_path_from_predecessor_list: function(predecessors, d) { var nodes = []; var u = d; var predecessor; while (u) { nodes.push(u); predecessor = predecessors[u]; u = predecessors[u]; } nodes.reverse(); return nodes; }, find_path: function(graph, s, d) { var predecessors = dijkstra.single_source_shortest_paths(graph, s, d); return dijkstra.extract_shortest_path_from_predecessor_list( predecessors, d); }, /** * A very naive priority queue implementation. */ PriorityQueue: { make: function (opts) { var T = dijkstra.PriorityQueue, t = {}, opts = opts || {}, key; for (key in T) { t[key] = T[key]; } t.queue = []; t.sorter = opts.sorter || T.default_sorter; return t; }, default_sorter: function (a, b) { return a.cost - b.cost; }, /** * Add a new item to the queue and ensure the highest priority element * is at the front of the queue. */ push: function (value, cost) { var item = {value: value, cost: cost}; this.queue.push(item); this.queue.sort(this.sorter); }, /** * Return the highest priority element in the queue. */ pop: function () { return this.queue.shift(); }, empty: function () { return this.queue.length === 0; } } }; </script> <script> var find_path = dijkstra.find_path, graph, path, paths; var Map = {} var width = 50; var height = 50; var Map = []; for(var a=0; a<width; a++) { Map[a] = []; for(var b=0; b<height; b++) { var h = Map[a][b-1]|parseInt(Math.random()*256); if(a>0)h = h/2+Map[a-1][b]/2; Map[a][b] = h+(Math.random()*20)-10; } } var graph = {}; for(var a=0; a<width; a++) { for(var b=0; b<height; b++) { var index = a+","+b; graph[index] = {}; var dx = []; var dy = []; if(a>0) {dx[dx.length] = a-1;dy[dy.length] = b; } if(a<width-1) {dx[dx.length] = a+1;dy[dy.length] = b; } if(b>0) {dx[dx.length] = a; dy[dy.length] = b-1;} if(b<height-1){dx[dx.length] = a; dy[dy.length] = b+1;} for(var z=0; z<dx.length; z++) { var di = dx[z]+","+dy[z]; graph[index][di] = Map[dx[z]][dy[z]]-Map[a][b]+1; } } } </script> </head> <body> <canvas id="cvs" width="800" height="600" onmousemove="mouseMove(event)"></canvas> <script> var scale = 5,mouse={x:-1,y:-10}; function init() { Template.start(draw,calc); } function mouseMove(e) { mouse = {x:e.offsetX-0.5,y:e.offsetY-0.5}; } function draw() { var G = cvs.getContext("2d"); G.clearRect(0,0,cvs.width,cvs.height); for(var a=0; a<width; a++) { for(var b=0; b<height; b++) { G.fillStyle = "hsl("+Map[a][b]/5+",50%,50%)"; G.fillRect(a*scale,b*scale,10,10); } } G.beginPath(); for(var a=0; a<path.length; a++) { var coord = path[a].split(","); G.lineTo(coord[0]*scale+scale/2,coord[1]*scale+scale/2); } G.stroke(); } function calc() { if(Map[parseInt(mouse.x/scale).toString()]) Map[parseInt(mouse.x/scale).toString()][parseInt(mouse.y/scale).toString()]+=15; var graph = {}; for(var a=0; a<width; a++) { for(var b=0; b<height; b++) { var index = a+","+b; graph[index] = {}; var dx = []; var dy = []; if(a>0) {dx[dx.length] = a-1;dy[dy.length] = b; } if(a<width-1) {dx[dx.length] = a+1;dy[dy.length] = b; } if(b>0) {dx[dx.length] = a; dy[dy.length] = b-1;} if(b<height-1){dx[dx.length] = a; dy[dy.length] = b+1;} for(var z=0; z<dx.length; z++) { var di = dx[z]+","+dy[z]; graph[index][di] = Map[dx[z]][dy[z]]-Map[a][b]+1; } } } path = find_path(graph, '0,0', '49,49'); } init(); </script> </body> </html>
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
17 hours ago | 0.16 KB
settings
17 hours ago | 0.10 KB
IT & AI
1 day ago | 1.62 KB
Stationeers - Sign Tags from Power Distributi...
HTML | 1 day ago | 2.00 KB
PM: Shopify Client Edits
1 day ago | 0.19 KB
PM: Shopify Assigning Design Task 2
1 day ago | 0.14 KB
PM: Shopify Assigning Design Task 1
1 day ago | 0.32 KB
Commodore Callback 8020
2 days ago | 0.18 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!