Author Archives: Soohyun

Final Documentation : DJ BOX

I tried to make a DJ Box as a controller for the music beats game.  There are lots of games playing with music, but usually they can play with keyboard or touch screen.  While I was playing these games, I thought something physically shaped controller might help the players feel exciting and engaging with the game better. For playing with the dj box, the players can feel like they are DJ which I aimed for the project. Now the players can not just be a player but also be the cool DJ.

I used real record that fixed with 360 rotary encoder and the led buttons that look like beat engineer machine. I used Arduino to make the physical parts, and HTML, Javascript and JQuery to build a digital game website. For communication, I used Node.js.

Here is the video of playing the game.

 

Leave a comment

Filed under Uncategorized

Playing with oF

I try to explore openFrameworks which is very first time to use. From the example code, imageSubsectionExample, I changed image subsection function to video subsection function which is more fun!

Leave a comment

Filed under Homework

Soohyun Midterm !

I made a game that can play with arduino inputs which is a controller of the game. I wanted to explore more about node.js. I referenced Paweena’s example codes. Thank you master Paweena !

IMG_1413

/index.html/ CODE

<!DOCTYPE html>
<html>
<head>
<link rel=”stylesheet” href=”http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css&#8221; />
<style>
body {
margin: 0px;
padding: 0px;
}

h1{
margin-left: 20px;
font-family: Helvetica;
color:#ffffff;
}

h2{
margin-left: 20px;
font-family: Helvetica;
color:#ffffff;
}
</style>

</head>
<body style=”background: #252525″>
<h1>Let’s Play with Arduino !!</h1>
<h2 id=”score”> SCORE : 0</h2>
<canvas id=”awesomeCanvas” width=1000 height=550></canvas>
<script type=”text/javascript”>

</script>

<br><br>
<div id=”slider”></div>

<script src=”http://localhost:9001/socket.io/socket.io.js”></script&gt;
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js”></script&gt;
<script src=”http://code.jquery.com/ui/1.10.3/jquery-ui.js”></script&gt;
<script>

var socket = io.connect(‘http://localhost:9001&#8217;);

var canvas = document.getElementById(“awesomeCanvas”);
var ctx = canvas.getContext(“2d”);
var canvasWidth = canvas.width;
var canvasHeight = canvas.height;
var color = ‘#FFFFFF’;
var ballColor;
var ballSize = 30;
var s = 0;
var start = false;

var numberOfBalls = 20;

window.requestAnimFrame = (function(callback) {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
function animate(playerBar, balls, canvas, context, startTime) {

// update
var time = (new Date()).getTime() – startTime;

var gravity = 30;

for(var i =0; i < numberOfBalls; i++){
balls[i].y = balls[i].y + 0.05 * gravity;

}

socket.on(‘pot’, function(data) {
playerBar.x = canvasWidth-80 -data;
});
for(var i =0; i < numberOfBalls; i++){
if(balls[i].color == color && balls[i].x >= playerBar.x -3 && balls[i].x + 30 <= playerBar.x + playerBar.width + 3 && balls[i].y >= 50){
balls[i].x = 5000;
console.log(“success!”);
s++;
$(‘#score’).append(s);

}

}
// clear
context.clearRect(0, 0, canvas.width, canvas.height);

drawPlayerBar(playerBar, ctx);

for(var i =0; i < numberOfBalls; i++)
drawBalls(balls[i], ctx);
// request new frame
requestAnimFrame(function() {
animate(playerBar, balls, canvas, context, startTime);
});
}

var playerBar = {
x: canvasWidth/2,
y: canvasHeight – 20,
opacity : 0.1,
width: 100,
height: 50
};

var balls = new Array(numberOfBalls);

for(var i = 0; i < numberOfBalls; i++){
var randomMaker = Math.random() * 10;

if(randomMaker >= 0 && randomMaker < 2){
ballColor =’white’;
}else if(randomMaker >= 2 && randomMaker < 4){
ballColor =’red’;
}else if(randomMaker >= 4 && randomMaker < 6){
ballColor =’yellow’;
}else if(randomMaker >= 6 && randomMaker < 8){
ballColor =’green’;
}else if(randomMaker >= 8 && randomMaker < 10){
ballColor =’blue’;
}

balls[i] = {
x: Math.random()*canvasWidth,
y: Math.random()* canvasHeight * i * -1,
opacity: 0.1,
color: ballColor
};
}

function drawPlayerBar(playerBar, context){
context.beginPath();
context.rect(playerBar.x, playerBar.y, playerBar.width, playerBar.height);
context.fillStyle = color;
context.fill();

if(start){
context.rect(playerBar.x, 0, playerBar.width, canvasWidth);

// add linear gradient
var grd = context.createLinearGradient(0, 0, 0, canvas.height);
grd.addColorStop(0, ‘#252525’);
grd.addColorStop(1, color);
context.fillStyle = grd;
context.fill();
}
}

 
function drawBalls(ball, context){
context.beginPath();
context.arc(ball.x, ball.y, ballSize, 0, 2 * Math.PI, false);
context.fillStyle = ball.color;
context.fill();
}

socket.on(‘pot’, function(data) {

playerBar.x = canvasWidth-80 -data;

// $(‘#pot’).animate({
// ‘height’: data,
// ‘width’ : data
// }, 100);
});
socket.on(‘button’, function(data) {

if(data == 25451){
color = ‘white’;
}else if(data == 25956){
color = ‘red’;
}else if(data == 28535){
color = ‘yellow’
}else if(data == 25966){
color = ‘green’
}else if(data == 30053){
color = ‘blue’
}

start = true;

});

 

// wait one second before starting animation
//setTimeout(function() {
var startTime = (new Date()).getTime();
animate(playerBar, balls, canvas, ctx, startTime);
//}, 10);
</script>
</body>
</html>

/ comm.js / CODE

// old stuff
var connect = require(‘connect’),
fs = require(‘fs’),
util = require(‘util’),
io = require(‘socket.io’).listen(9001), // WS port
port = 9000, // HTTP port

// new stuff
// define a class
SerialPort = require(“serialport”).SerialPort,
// ls /dev/tty.*
sPort=”/dev/tty.usbmodem1411″,
//sPort = “/dev/tty.usbserial-AM01PK24″,
// create an instance (object)
arduino = new SerialPort(sPort, {
baudrate: 9600
});

// create web server using connect
connect.createServer(
connect.static(__dirname + ‘/public’) // two underscores
).listen(port);
util.log(‘the server is running on port: ‘ + port);

// init socket.io
io.set(‘log level’, 1);
io.sockets.on(‘connection’, function(socket) {
util.log(‘Ooooooh, someone just poked me :)’);
socket.on(‘led’, function(data) {
// sending binary data
var ledOn = new Buffer(1), // Buffer is an array and Buffer(1) means 1 index array
ledOff = new Buffer(1);
ledOn[0] = 0x01; // 1
ledOff[0] = 0x00; // 0
// shorthand ledOn = new Buffer([0x01])

if(data === true) {
// turn on
arduino.write(ledOn);
util.log(‘LED ON’);
} else {
// turn off
arduino.write(ledOff);
util.log(‘LED OFF’);
}
});
socket.on(‘slider’, function(data) {
aHex = data.toString(16);
bHex = ‘0x’ + aHex;
cHex = new Buffer([bHex]);
// util.log(‘Z’ + cHex + ‘X’);
arduino.write(‘O’ + cHex + ‘P’);
});
});

// function that converts int to hexadecimal
// we communicate to Arduino using hex (binary)

// serial port
var receivedData, sendData;

arduino.on(‘open’, function() {
console.log(‘opening port’);
// console.log((11).toString(16));
// setInterval(toggle, 1000);
});

// receive data
arduino.on(‘data’, function(data) { // data comes in Buffer < >
// try removing toString()
// util.log(data);
receivedData += data;
// basically says if there’re ‘E’ and ‘B’ signals
if (receivedData.indexOf(‘E’) >= 0 && receivedData.indexOf(‘B’) >= 0) {
// save the data between ‘B’ and ‘E’
sendData = receivedData.substring(receivedData.indexOf(‘B’) + 1, receivedData.indexOf(‘E’));
receivedData = ”;
util.log(sendData);
// parse data to browser
io.sockets.emit(‘pot’, sendData);
// socket.io
// emit, on, broadcast.emit, io.sockets.emit
}

if (receivedData.indexOf(‘S’) >= 0 && receivedData.indexOf(‘F’) >= 0) {
// save the data between ‘B’ and ‘E’
sendData = receivedData.substring(receivedData.indexOf(‘S’) + 1, receivedData.indexOf(‘F’));
receivedData = ”;
util.log(sendData);
// parse data to browser
io.sockets.emit(‘button’, sendData);
// socket.io
// emit, on, broadcast.emit, io.sockets.emit

}
});

/ comm_app.ino / CODE

const int outputPin = 13;
int potPin = 0;
int sensorVal = 0;
int prevVal = 0;
String inputString = “”;

int soundPin = 12;
int buttons [] = {2,3,4,5,6};
int buttonState [5];

void setup()
{
pinMode(outputPin, OUTPUT);
Serial.begin(9600);

//pinMode(outputPin, OUTPUT);
for(int i=0; i<5; i++){
pinMode(buttons[i], INPUT);
}
pinMode(soundPin, OUTPUT);
}

void loop()
{
noTone(soundPin);
for(int i=0; i<5; i++)
buttonState[i] = digitalRead(buttons[i]);

//pot
sensorVal = analogRead(potPin);
if(prevVal != sensorVal) {
// if(prevVal < sensorVal+10){
// for(int i = 0; i <5; i++){
// tone(soundPin, 100+i*100);
// delay(50);
// //delay(80);
// }
// }else if(prevVal > sensorVal+10){
// for(int i = 5; i >= 0; i–){
// tone(soundPin, 100+i*100);
// delay(50);
// //delay(80);
// }
// }

Serial.print(‘B’);
Serial.print(sensorVal);
Serial.print(‘E’);
prevVal = sensorVal;
}
delay(100);

if(buttonState[0] == HIGH){ //black
Serial.print(‘S’);
Serial.print(‘black’);
Serial.print(‘F’);
toneEffect();
}else if(buttonState[1] == HIGH){ //red
Serial.print(‘S’);
Serial.print(‘red’);
Serial.print(‘F’);
toneEffect();
}else if(buttonState[2] == HIGH){ //yellow
Serial.print(‘S’);
Serial.print(‘yellow’);
Serial.print(‘F’);
toneEffect();
}else if(buttonState[3] == HIGH){ //green
Serial.print(‘S’);
Serial.print(‘green’);
Serial.print(‘F’);
toneEffect();
}else if(buttonState[4] == HIGH){ //blue
Serial.print(‘S’);
Serial.print(‘blue’);
Serial.print(‘F’);
toneEffect();
}

// arduino reads Serial
if (Serial.available() > 0) {
int incomingByte = Serial.read();

if (incomingByte == 1) { // 0x01 = char 1
for(int i = 0; i <5; i++){
tone(soundPin, 100+i*100);
delay(50);
}
noTone(soundPin);
}
}
}

void toneEffect(){

if(buttonState[0]){
tone(soundPin,300);
delay(100);
}else if(buttonState[1]){
tone(soundPin,600);
delay(100);
}else if(buttonState[2]){
tone(soundPin,900);
delay(100);
}else if(buttonState[3]){
tone(soundPin,1200);
delay(100);
}else if(buttonState[4]){
tone(soundPin,1500);
delay(100);
}

noTone(soundPin);

}

Screen Shot 2013-11-21 at 4.03.00 PM

Leave a comment

Filed under Uncategorized

Node with Arduino HW

Node.js / Terminal / Arduino HW

I made a random sequence of sounds and led lights. At the first time, I try to use input data from Arduino – thermometer – but I failed to use.. Therefore, I focus on using input datas from Node.js to produce outputs of Arduino. (Reference : examples code from the class Week 09.)

Arduino Code :

//define led pins
int led1 = 10;
int led2 = 11;
int led3 = 12;
int led4 = 13;
int buzzerPin = 8;

//initialize pinmode with OUTPUT mode and activate the serial port with baudrate 9600
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}

//wait for incoming data from the serial port
//if incoming data has value “1”, turn on LED1 and so forth

void loop() {

if (Serial.available() > 0) {
char inputData = Serial.read();
if(inputData==’1′){
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
tone(buzzerPin, 400);
}
if(inputData==’2′){
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
tone(buzzerPin, 600);
}
if(inputData==’3′){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
tone(buzzerPin, 800);
}
if(inputData==’4′){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
tone(buzzerPin, 1000);
}
}
}

Node.js Code :

//activate serial port module
var serialport = require(“serialport”);
var SerialPort = serialport.SerialPort;

//set led=1 as initial command
var led = 1;
// change serial port of Arduino
var myserial = new SerialPort(“/dev/tty.usbmodem1411”,{
baudrate: 9600
});

//open event from serial port module
myserial.on(‘open’,function(){
//timer set at 2000
setInterval(testLEDwithBuzzer,500);

});

function testLEDwithBuzzer(){

led = Math.round((Math.random(0,1)*10) %3 +1);
console.log(‘send command for led with buzzer=’ + led);
//write data into serial port

myserial.write(led.toString());
}

//catches errors from serial port
myserial.on(‘error’, function (err) {
console.log(‘Error = ‘ + err);
});

NodeArduino_bb

Leave a comment

Filed under Homework

Arduino HW: Sensors & Serial Inputs !

1. Sensors with LEDs !

I played with 2 sensors : a potentiometer and a photo resistor.  I used potentiometer to change the speed of lights going, and photo resistor for changing brightness. It was fun to explore analog inputs/sensors to make digital effects.

//CODE//

int speedPin = 1;
int ledPin [] = {3,9,10,11};
int photoPin = 0;
int brightness = 255;
int fadeAmount = 5;
int sensorValue;
int speedValue;
int mappedValue;
int time;

void setup(){
Serial.begin(9600);

for(int i=0; i<4; i++)
pinMode(ledPin[i], OUTPUT);

}

void loop(){

sensorValue = analogRead(photoPin);
mappedValue = map(sensorValue, 0, 1023, 0, 255);
speedValue = analogRead(speedPin);
time = map(speedValue, 0,1023, 10,1000);

Serial.println(mappedValue);

playLED();

}

void playLED(){

for(int i=0; i<4; i++){
analogWrite(ledPin[i], mappedValue);
delay(time);
analogWrite(ledPin[i], 0);
delay(time);
}

}

sensorHW_bb

2. serial input with Leds and a buzzer 

I made a program that can play sounds and led lights from the input, ‘r’, ‘g’, ‘y’, and ‘b’. The user put a sequence with r, g, y, and b. It will make sound and led light effects based on the user’s input sequence.  Playful !

//CODE//

int ledPin [] = {8,9,10,11};\
int buzzerPin = 2;
int incomingByte = 0;

void setup(){
Serial.begin(9600);

for(int i=0; i<4; i++)
pinMode(ledPin[i], OUTPUT);

pinMode(buzzerPin, OUTPUT);

}

void loop(){

if(Serial.available() >0){
incomingByte = Serial.read();

if(incomingByte ==’ ‘){
delay(500);
}else if(incomingByte == ‘r’){
digitalWrite(ledPin[0], HIGH);
tone(buzzerPin, 1000);
delay(500);
noTone(buzzerPin);
digitalWrite(ledPin[0], LOW);
}else if(incomingByte == ‘y’){
digitalWrite(ledPin[1], HIGH);
tone(buzzerPin, 1500);
delay(500);
noTone(buzzerPin);
digitalWrite(ledPin[1], LOW);
}else if(incomingByte == ‘g’){
digitalWrite(ledPin[2], HIGH);
tone(buzzerPin, 2000);
delay(500);
noTone(buzzerPin);
digitalWrite(ledPin[2], LOW);
}else if(incomingByte == ‘b’){
digitalWrite(ledPin[3], HIGH);
tone(buzzerPin, 2500);
delay(500);
noTone(buzzerPin);
digitalWrite(ledPin[3], LOW);
}
Serial.print(char(incomingByte));
}

}

inputHW_bb

Leave a comment

Filed under Uncategorized

Arduino Assignment#1: LEDs and Buttons

 

I could play with LEDs and Buttons ! I wanted to make cute 3 LED lights.  Also, I wanted to try boolean buttons for the LEDs and Buttons. When I push buttons, it stays ON and when I push once again, it turns OFF.

(1) 3 LEDs

int ledPin_red = 11;
int ledPin_yellow = 12;
int ledPin_blue = 13;

void setup(){
Serial.begin(9600);
pinMode(ledPin_red, OUTPUT);
pinMode(ledPin_yellow, OUTPUT);
pinMode(ledPin_blue, OUTPUT);

}

void loop(){

digitalWrite(ledPin_red, HIGH);
delay(100);
digitalWrite(ledPin_red, LOW);
delay(100);
digitalWrite(ledPin_yellow, HIGH);
delay(100);
digitalWrite(ledPin_yellow, LOW);
delay(100);
digitalWrite(ledPin_blue, HIGH);
delay(100);
digitalWrite(ledPin_blue, LOW);
delay(100);

digitalWrite(ledPin_red, HIGH);
digitalWrite(ledPin_yellow, HIGH);
digitalWrite(ledPin_blue, HIGH);
delay(1000);
digitalWrite(ledPin_red, LOW);
digitalWrite(ledPin_yellow, LOW);
digitalWrite(ledPin_blue, LOW);
delay(1000);

}

Image

(2) 3 LEDs and 3 Buttons

int ledPin_red = 11;
int ledPin_yellow = 12;
int ledPin_blue = 13;

int buttonPin_r = 4;
int buttonPin_y = 8;
int buttonPin_b = 10;

boolean pushed_R = false;
boolean pushed_Y = false;
boolean pushed_B = false;

void setup(){
Serial.begin(9600);
pinMode(ledPin_red, OUTPUT);
pinMode(ledPin_yellow, OUTPUT);
pinMode(ledPin_blue, OUTPUT);

pinMode(buttonPin_r, INPUT);
pinMode(buttonPin_y, INPUT);
pinMode(buttonPin_b, INPUT);

digitalWrite(buttonPin_r, HIGH);
digitalWrite(buttonPin_y, HIGH);
digitalWrite(buttonPin_b, HIGH);

}

void loop(){

static int buttonState_r;
static int buttonState_y;
static int buttonState_b;

buttonState_r = digitalRead(buttonPin_r);
buttonState_y = digitalRead(buttonPin_y);
buttonState_b = digitalRead(buttonPin_b);

if(!buttonState_r){
pushed_R = !pushed_R;
if(pushed_R){
digitalWrite(ledPin_red, HIGH);
delay(100);
}else if(!pushed_R){
digitalWrite(ledPin_red, LOW);
delay(100);
}
}
if(!buttonState_y){
pushed_Y = !pushed_Y;
if(pushed_Y){
digitalWrite(ledPin_yellow, HIGH);
delay(100);
}else if(!pushed_Y){
digitalWrite(ledPin_yellow, LOW);
delay(100);
}
}
if(!buttonState_b){
pushed_B = !pushed_B;
if(pushed_B){
digitalWrite(ledPin_blue, HIGH);
delay(100);
}else if(!pushed_B){
digitalWrite(ledPin_blue, LOW);
delay(100);
}
}

}

Image

Leave a comment

Filed under Uncategorized

Playing with Weather API // Assignment3

I had hard time to work with API, but finally I could figure out how to play with API ! Today’s review class was so much helpful to do this work. I’ve learned how to bring live information from API from Weather Underground by looking at its json datas and apply them to my website. Especially, bring live Radar+Satellite Map was so interesting ! I will definitely use API in my future project.

This is my website!

http://a.parsons.edu/~parks566/apiExplore/apiExplore.html

<!DOCTYPE html>

<html>
<head>
<meta charset=”UTF-8″>
<title>JSON WITH API</title>

<script type=”text/javascript” src=”js/jquery-1.10.2.min.js”></script>

<script type=”text/javascript”>

/*Standard request URL format =
http://api.wunderground.com/api/b79e3040f6431025/features/settings/q/query.format
where
features=> type of data, here astronomy
settings=> lang or personal data
query=> location of data
*/

$(document).ready(function(){
$.ajax({
url: “http://api.wunderground.com/api/3b6709cb1560b9d9/conditions/q/NY/New_York.json&#8221;,
dataType : “jsonp”, //jsonp for cross-origin files
success : function(parsed_json) {
console.log(‘success!!’);
//each nested object goes in []
var Odata = parsed_json[‘current_observation’][‘display_location’][‘full’];
var Otime = parsed_json[‘current_observation’][‘observation_time’];
var weatherD = parsed_json[‘current_observation’][‘weather’];
var temperatureS = parsed_json[‘current_observation’][‘temperature_string’];
var humidityD = parsed_json[‘current_observation’][‘relative_humidity’];
var forecastU = parsed_json[‘current_observation’][‘forecast_url’];
var imageR = “http://api.wunderground.com/api/3b6709cb1560b9d9/animatedradar/animatedsatellite/q/NY/New_York.gif?num=6&delay=50&interval=30&#8221;;

//var sunset = parsed_json[‘moon_phase’][‘sunset’][‘hour’];
console.log(“observation_location : “+ Odata);
console.log(“observation_time : “+ Otime);
console.log(“weather : “+ weatherD);
console.log(“temperature : “+ temperatureS);
console.log(“humidity : “+ humidityD);
console.log(“forecast url : “+ forecastU);
console.log(“image: “+ imageR);

//console.log(parsed_json); //great debugging tool here!
$(“#container”).append(“<h1> Weather in “+ Odata +” </h1>”);
$(“#container”).append(“<img src=\””+ imageR +”\” width=\”500\” height=\”500\” >”);
$(“#container”).append(“<p> Time : “+ Otime +” </p>”);
$(“#container”).append(“<p> Weather : “+ weatherD +” </p>”);
$(“#container”).append(“<p> Temperature : “+ temperatureS +” </p>”);
$(“#container”).append(“<p> Humidity : “+ humidityD +” </p>”);
$(“#container”).append(“<p> See More Detail : <a href = \””+ forecastU +”\”>”+forecastU+”</a></p>”);

} //end of success
}); //end of ajax
}); //end of doc ready{

</script>

</head>

<body>
<section id=”container”>
</section>
</body>
</html>

Leave a comment

Filed under Homework

Week2 Assignment _Soohyun Park

I could learn how to arrange images and sources on the web pages and simple animation.  I try to make more dynamic animation (like every stars will move whenever users click them.) But even one star movement took a lot of time to figure out. I will iterate this project to have more dynamic animation.

<!DOCTYPE html>
<html>
<head>

<style>
body {
margin: 0px;
padding: 0px;
}

h3.title{
margin-left: 10px;
font-family: Helvetica;
}
</style>
</head>
<body>
<h3 class=”title”> The Little Prince </h3>

<canvas id=”awesomeCanvas” width=1200 height=600></canvas>
<script type=”text/javascript”>
var canvas = document.getElementById(“awesomeCanvas”);
var ctx = canvas.getContext(“2d”);
var canvasWidth = canvas.width;
var canvasHeight = canvas.height;

var numberOfStars = 100;

var star = {
x: Math.random()*canvasWidth,
y: Math.random()*canvasHeight,
image: new Image(),
opacity: 0.5
};

var stars = new Array(numberOfStars);
for(var i = 0; i < numberOfStars; i++)
stars[i] = {
x: Math.random()*canvasWidth,
y: Math.random()*canvasHeight,
image: new Image(“star.png”),
opacity: 0.5
};

for(var i =0; i<numberOfStars; i++)
stars[i].image.src=”star.png”;

var littlePrince = {
x:canvasWidth/2-150,
y:canvasHeight/2,
image: new Image(),
};

// Image Reference designed by web designer Charles van Valkenburg:: http://www.thelittleprince.com/the-little-prince-coming-to-a-screen-near-you/
star.image.src =”star.png”;
littlePrince.image.src=”lepetitprince.png”;

drawBackground();
//ctx.translate(canvasWidth/2,canvasHeight/2);

window.requestAnimFrame = (function(callback) {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();

function animate(star, canvas, ctx, startTime){
var time = (new Date()).getTime() – startTime;

var gravity = 200;

star.x = star.x+ 0.5 * gravity * Math.pow(time/1000,2.5);
star.y = star.y + 0.5 * gravity * Math.pow(time/1000,2.5);

lastTime = time;

ctx.clearRect(0,0,canvasWidth,canvasHeight);

drawBackground();
drawStar(star, ctx);

requestAnimFrame(function(){

animate(star, canvas, ctx, startTime);
////drawBackground();
});
}

function drawBackground(){

var gradation = ctx.createRadialGradient(canvasWidth/2, canvasHeight/2,300, canvasWidth, canvasHeight, 900);
gradation.addColorStop(0,”#33587c”);
gradation.addColorStop(1,”#030507″);

ctx.beginPath();
ctx.fillStyle = gradation;
ctx.rect(0, 0, canvasWidth, canvasHeight);
ctx.fill();

ctx.fillStyle=”#020202″;
ctx.arc(canvasWidth/2, canvasHeight, 100,0,2*Math.PI,false);
ctx.fill();
drawStarB();
ctx.drawImage(littlePrince.image, littlePrince.x,littlePrince.y);

}

function drawStarB(){
for(var i = 0; i < numberOfStars; i++){

ctx.drawImage(stars[i].image, stars[i].x, stars[i].y);

}
}

function drawStar(star,ctx){
ctx.beginPath();
console.log(star.x);

ctx.drawImage(star.image, star.x, star.y);
}

setTimeout(function() {
var startTime = (new Date()).getTime();
animate(star, canvas, ctx, startTime);
//animate(star, canvas, ctx, startTime+10000);
},0);

setTimeout(function() {
var startTime = (new Date()).getTime();
animate(star, canvas, ctx, startTime);
//animate(star, canvas, ctx, startTime+10000);
},0);
</script>

</body>
</html>

Screen Shot 2013-09-09 at 1.02.22 AM

1 Comment

Filed under Uncategorized

madlib Homework

<!DOCTYPE html>
<html>
<head>
<title>My Basic HTML</title>
</head>
<body>
<div id=”display_sentence”></div>

<button onclick=”erase()”> Erase </button>
<button onclick=”restart()”> Restart </button>

<script type=”text/javascript”>
//this is where javascript lives
console.log(“This is javascripts println();”);
var display = “”;
var noun1 = “CCLab”;
var noun2 = “cat”;
var verb1 = “sleep”;
var verb2 = “eat”;
var adj1 = “hungry”;
var adj2 = “”;

var sentence = noun1 + ” want to ” + verb1 + ” with ” + noun2 + ” because ” + noun1 + ” is ” + adj1 + “. But ” + noun2 + ” can’t ” + verb1 + ” because ” + noun2 +” have to ” + verb2 + adj2 +”.”;

console.log(sentence);

// Reference : http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_getelementbyid
document.getElementById(“display_sentence”).innerHTML=sentence;

function erase(){
document.getElementById(“display_sentence”).innerHTML=””;
}
function restart(){
document.getElementById(“display_sentence”).innerHTML=sentence;
}

</script>
</body>
</html>

1 Comment

Filed under Homework