Sound Test
type 1 2 3 4 to sketch to play sounds
var one, two, three, four;
function preload() {
one = loadSound("https://courses.ideate.cmu.edu/15-104/f2017/wp-content/uploads/2017/12/one.wav");
two = loadSound("https://courses.ideate.cmu.edu/15-104/f2017/wp-content/uploads/2017/12/two.wav");
three = loadSound("https://courses.ideate.cmu.edu/15-104/f2017/wp-content/uploads/2017/12/three.wav");
four = loadSound("https://courses.ideate.cmu.edu/15-104/f2017/wp-content/uploads/2017/12/four.wav");
}
function setup() {
createCanvas(200, 200);
background(200);
}
function keyPressed() {
print("" + keyCode);
if (keyCode == 49) one.play();
else if (keyCode == 50) two.play();
else if (keyCode == 51) three.play();
else if (keyCode == 52) four.play();
}
]]>//Shariwa Sharada
//Section-A
//ssharada@andrew.cmu.edu
//Assignment-03-A
var ssw = 135;
var ssh = 160;
function setup(){
createCanvas (400, 300);
rectMode(CENTER);
}
function draw(){
//changing the background depending on the position of the cursor
background(mouseX, mouseY, 191);
push();
//limiting the colour change to certain types - dependent on the mouse placement within a 4x3 grid
//changing colours dependent on the x-axis placement
if (mouseX>0 & mouseX < ssw){
mouseX = 246
}
if (mouseX>ssw && mouseX < ssw*2){
mouseX = 236
}
if (mouseX>ssw*2 && mouseX < ssw*3){
mouseX = 226
}
if (mouseX>ssw*2 && mouseX < width){
mouseX = 216
}
//changing colours dependent on the y-axis placement
if (mouseY>0 && mouseY < ssh){
mouseX = 180
}
if (mouseY>ssh && mouseY < ssh*2){
mouseX = 170
}
if (mouseY>ssh*2 && mouseY < height){
mouseX = 160
}
pop();
push();
//creating the translating and moving squares
translate (width/2, height/2);
//stating the number of squares i want within the first level -
//using the increment command to have the squares rotated with equal distances.
for (var a = 0; a < 15; a++){
push();
//rotation and pasting
rotate(TWO_PI * a / 15);
//making the placement of the level dependent
//on the y-axis placement of the cursor
var X = mouseY;
translate(X, 0);
//the colour of this rectangles and randomising the transparancy
//of the white to make the quares appear to flicker
fill(255, random(20,90));
noStroke();
//the size of the first level of rectangles.
rect(0,0,60,60);
//stating the number of squares i want within the second level -
//using the increment command to have the squares rotated with equal distances.
for (var b = 0; b < 12; b++){
push();
//rotation and pasting
rotate(TWO_PI * b/12);
//making the placement of the level dependent
//on the x-axis placement of the cursor
var Y = mouseX;
//the size of the second level of rectangles.
rect (Y,0,30,30);
//the colour of this rectangles and randomising the
//transparancy of the white to make the quares appear to flicker
fill(255, random(10,80));
noStroke();
//stating the number of squares i want within the third level -
//using the increment command to have the squares rotated with equal distances.
for (var c = 0; c < 8; c++){
push();
//rotation and pasting
rotate(TWO_PI* c/8);
//making the placement of the level dependent
//on the y-axis placement of the cursor
var Z = mouseY;
//the size of the third level of rectangles.
rect (0,Z,10,10);
//the colour of this rectangles and randomising the
//transparancy of the white to make the quares appear to flicker
fill(255, random(10,50));
noStroke();
//preventing the code from affecting other factors of the program
pop();
}
//preventing the code from affecting other factors of the program
pop();
}
//preventing the code from affecting other factors of the program
pop();
}
pop();
}
]]>var mx = 0;
var my = 0;
function setup() {
createCanvas(240, 120);
}
function draw() {
background(204);
ellipse(mx, my, 50, 50);
}
function mouseMoved() {
mx = mouseX;
my = mouseY;
}
]]>