• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • about this course
  • syllabus
  • rubric
  • labs
  • blog

HCI | TechX

August 12, 2020

Homework day 6_YiChen

Description Whenever the circle hits the boundary of the window, the program plays a keyboard note and switch to a random background color for less than a second.

import processing.sound.*;

SoundFile a;
SoundFile b;
SoundFile hihat;
int u;
int v;
int speedU = 1;
int speedV = 6;

void setup(){
  background(0);
  size(800,800);
  a = new SoundFile (this, "1.aif");
  b = new SoundFile (this, "2.aif");
  hihat = new SoundFile (this, "hihat.aif");
  
}

void drawFace (float u, float v, color c, float size){
  fill(c);
  ellipse(u,v,size,size);

}

void draw(){
   background(0);
  drawFace (u, v, color(#FFC9DE),100);
  u=u+speedU;
  v=v+speedV;
  if (u>width||u<0){
    speedU=-speedU;
    a.play();
    background(random(255),random(255),random(255));
        delay(1);
  }if(v>height||v<0){
    speedV=-speedV;
    b.play();
    background(random(255),random(255),random(255));
  }
}

void keyPressed(){
  if(key=='h');
  hihat.play();
}
Screen recording: better visual quality but mute

Filed Under: blog

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Recent Posts

  • Homework Day 8 – Simon Hsieh
  • homework day 8 – Michael
  • Homework-day8-Sophie
  • Harry Hao HW DAY8
  • homework day 8 – dora

Copyright © 2025 HCI | TechX on the Brunch Pro Theme