Project 0

by Nara @ 1:53 am 12 January 2010

Part A

GDE Error: Unable to load profile settings
void draw()
{
  background(#FFFFFF);
  int waveHeight = 30;
  for (int i = 0; i < 90; i++)
  {
    int yOffset = waveHeight + 10 + (i * 8);
    beginShape();
    for (float x = 0; x < 360; x+=5)
    {
      float y = ((TWO_PI*4) * (radians(x)/TWO_PI)) + (PI*3/4);
      curveVertex(sq(x)/120, yOffset + (waveHeight * sin(y)));
    }
    endShape();
  }
}

Part B

I also for the life of me cannot get the iframes to work, so the applet can be found here.

Ball myBall;
Paddle myPaddle;
 
void setup()
{
  size(400, 400);
  rectMode(CENTER);
  ellipseMode(CENTER);
  noStroke();
  fill(#FFFFFF);
  myPaddle = new Paddle();
  myBall = new Ball();
  noCursor();
  smooth();
}
 
void draw()
{
  background(#000000);
  myBall.display();
  myPaddle.display();
  myBall.move();
  if (out()) { myBall.reset(); }
  if (boundaryCollision() || paddleCollision()) { myBall.changeDir(); }
}
 
void mouseMoved()
{
  float hOffset = myPaddle.h / 2;
  myPaddle.ypos = constrain(mouseY, 0 + hOffset, height - hOffset);
}
 
boolean out()
{
  if (myBall.xpos <= 0) { return true; }
  return false;
}
 
boolean boundaryCollision()
{
  if (myBall.xpos <= 0) { return false; }
  if (myBall.ypos <= 0 || myBall.ypos >= height) { return true; }
  if (myBall.xpos >= width) { return true; }
  return false;
}
 
boolean paddleCollision()
{
  float pTop = myPaddle.ypos - (myPaddle.h/2);
  float pBot = myPaddle.ypos + (myPaddle.h/2);
  if (myBall.ypos <= pTop || myBall.ypos >= pBot) { return false; }
  float bLeft = myBall.xpos - (myBall.w/2);
  float pLeft = myPaddle.xpos + (myPaddle.w/2);
  if (bLeft  (pLeft-3)) { return true; }
  return false;
}
 
final class Ball
{
  float xpos = width/2;
  float ypos = height/2;
  float[] dir = {-3, 2};
  int w = 20;
 
  void display()
  {
    ellipse(xpos, ypos, w, w);
  }
 
  void move()
  {
    xpos += dir[0];
    ypos += dir[1];
  }
 
  void changeDir()
  {
    if (ypos <= 0 || ypos >= height) { dir[1] *= -1; }
    else { dir[0] *= -1; }
  }
 
  void reset()
  {
    xpos = width/2;
    ypos = height/2;
    dir = new float[2];
    dir[0] = -3;
    dir[1] = 2;
  }
}
 
final class Paddle
{
  float xpos = 25;
  float ypos = height/2;
  int w = 15;
  int h = 60;
 
  void display()
  {
    rect(xpos, ypos, w, h);
  }
}

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2016 Special Topics in Interactive Art & Computational Design | powered by WordPress with Barecity