Project 0

by mghods @ 6:14 am 13 January 2010

PART A – Noll Sinusoids

The PDF file:

GDE Error: Unable to load profile settings

The code:

// Project 0 - Part A
// "Noll Sinusoids"
// Course:Special Topics in Interactive Art & Computational Design
// By: Mehrdad Ghods
// For project description please visit:
// "https://ems.andrew.cmu.edu/2010spring/projects/project-0/"
 
import processing.pdf.*;
 
// declare width and height of PDF page
int widthPDF = 800;
int heightPDF = 600;
// declare Sinusoid starting Y
float sinusoidY;
// declare margin
float margin = heightPDF / 20;
 
///////////////
// Main Methods
///////////////
 
// this method initialize renderer
// in this case pdf file renderer
void setup() {
  // create a 800X600 pixel one page PDF file
  //size(widthPDF, heightPDF);
  size(widthPDF, heightPDF, PDF, "NollSinusoids.pdf");
  // determine weight of strokes on 10
  strokeWeight(1.15);
  // draw anti-aliased edges
  smooth();
  // make background white
  background(255);
}
 
// this method draw using initialized renderer
void draw() {
  // draw 90 Sinusoids
  for(int i = 0; i < 90; i++){
    // determine sinusoid starting Y
    sinusoidY = margin + i * (heightPDF - (2 * margin)) / 90;
    // draw a Sinusoid
    drawNollSinusoid();
  }
  exit();
}
 
////////////////
// Helper Mthods
////////////////
 
// this method draw Noll a Sinusoid
void drawNollSinusoid(){
  // declare Sinusoids local X and Y
  float sinusoidLocalPX = 0;
  float sinusoidLocalX = 0;
  float sinusoidLocalPY = 0;
  float sinusoidLocalY = 0;
  // declare precision of drawing
  float precision = 1.0;
  // declare Sinusoid's properties
  // 1- amplitude
  float A = 5 * margin / 6;
  // 2- reverse of spatial frequency
  float k = 1.0 /(widthPDF / 120);
  // 3- phase
  float phase = 0;
 
  // draw Sinusoid by moving a point along page width, with height
  // determined by Sinusoid equation which is:
  // Y = A.Sin(k.X + phase), k divided by a linear function
  // each PI radians.
  while (sinusoidLocalX <= float(widthPDF)) {
    // to create a smoother view two points be calculated
    // and a line between them be drawn
    // increase X by one
    // calculate pervious X
    sinusoidLocalPX = sinusoidLocalX;
    // calculate X
    sinusoidLocalX += precision;
    // calculate Y - 1
    sinusoidLocalPY = sinusoidY - A * sin((PI / 180 * sinusoidLocalPX) / k);
    // calculate Y
    sinusoidLocalY = sinusoidY - A * sin((PI / 180 * sinusoidLocalX) / k);
    // draw a point od Sinusoid
    line(sinusoidLocalPX, sinusoidLocalPY, sinusoidLocalX, sinusoidLocalY);
    k += 0.0001 * (widthPDF / 120) * precision;
  }
}

PART B – Tennis for Two

The link to applet:

Tennis for Two

The link to code: (Copy & Paste txt into processing environment, save the file, and run it!!!)

Tennis for Two Code

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