View this code at http://livecoding.io/4192986
Created
December 3, 2012 05:39
-
-
Save rdhyee/4192986 to your computer and use it in GitHub Desktop.
created by http://livecoding.io/3411676
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"libraries": [ | |
"Processing" | |
], | |
"mode": "javascript", | |
"layout": "sketchpad mode" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#red { | |
width: 100px; | |
height: 100px; | |
background: #FF0000; | |
} | |
#blue { | |
width: 100px; | |
height: 100px; | |
background: #0000FF; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Processing.js</h1> | |
<h2>Simple processing.js via JavaScript</h2> | |
<p>Clock</p> | |
<p><canvas id="canvas1" width="200" height="200"></canvas></p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple way to attach js code to the canvas is by using a function | |
function sketchProc(processing) { | |
// Override draw function, by default it will be called 60 times per second | |
processing.draw = function() { | |
// determine center and max clock arm length | |
var centerX = processing.width / 2, centerY = processing.height / 2; | |
var maxArmLength = Math.min(centerX, centerY); | |
function drawArm(position, lengthScale, weight) { | |
processing.strokeWeight(weight); | |
processing.line(centerX, centerY, | |
centerX + Math.sin(position * 2 * Math.PI) * lengthScale * maxArmLength, | |
centerY - Math.cos(position * 2 * Math.PI) * lengthScale * maxArmLength); | |
} | |
// erase background | |
processing.background(224); | |
var now = new Date(); | |
// Moving hours arm by small increments | |
var hoursPosition = (now.getHours() % 12 + now.getMinutes() / 60) / 12; | |
drawArm(hoursPosition, 0.5, 5); | |
// Moving minutes arm by small increments | |
var minutesPosition = (now.getMinutes() + now.getSeconds() / 60) / 60; | |
drawArm(minutesPosition, 0.80, 3); | |
// Moving hour arm by second increments | |
var secondsPosition = now.getSeconds() / 60; | |
drawArm(secondsPosition, 0.90, 1); | |
}; | |
} | |
var canvas = document.getElementById("canvas1"); | |
// attaching the sketchProc function to the canvas | |
var p = new Processing(canvas, sketchProc); | |
// p.exit(); to detach it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment