The Starry Night

For this week’s assignment, I wrote a program to add movement to one of my favourite paintings, the Starry Night. My program enables the moon and the stars to rotate in the sky. The background music is Vincent by Joanna Wang.

The user can also choose to add filters to the painting. If “t” is pressed, the threshold filter will be applied to the image. Likewise, “i” enables the invert filter, and “b” enables the blur filter.

Threshold

Invert

Blur

Here’s my code.

import processing.sound.*;
SoundFile file;

PImage source1;
PImage moon;
PImage star1;
PImage star2;
PImage star3;
PImage star4;
PImage star5;
PImage star6;
PImage star7;
PImage star8;
PImage star9;
PImage star10;
PImage star11;
PImage[] moves = new PImage[12];
int counter = 0;
int xPos_moon = 770;
int yPos_moon = 90;
int xPos_star1 = 320;
int yPos_star1 = 180;
int xPos_star2 = 605;
int yPos_star2 = 120;
int xPos_star3 = 515;
int yPos_star3 = 35;
int xPos_star4 = 230;
int yPos_star4 = 78;
int xPos_star5 = 97;
int yPos_star5 = 30;
int xPos_star6 = 250;
int yPos_star6 = 18;
int xPos_star7 = 332;
int yPos_star7 = 20;
int xPos_star8 = 393;
int yPos_star8 = 20;
int xPos_star9 = 30;
int yPos_star9 = 280;
int xPos_star10 = 100;
int yPos_star10 = 300;
int xPos_star11 = 290;
int yPos_star11 = 290;
float rot = 0.0;
boolean thres = false;
boolean invert = false;
boolean blur = false;

void setup() {
  file = new SoundFile(this, "Vincent.mp3");
  file.play();
  
  size(880, 592);
  rectMode(CENTER);
  imageMode(CENTER);

  source1 = loadImage("Stary Night.jpeg");
  moon = createImage(100, 100, RGB);
  star1 = createImage(50, 50, RGB);
  star2 = createImage(50, 50, RGB);
  star3 = createImage(60, 60, RGB);
  star4 = createImage(60, 60, RGB);
  star5 = createImage(78, 60, RGB);
  star6 = createImage(60, 34, RGB);
  star7 = createImage(60, 40, RGB);
  star8 = createImage(46, 40, RGB);
  star9 = createImage(52, 50, RGB);
  star10 = createImage(60, 66, RGB);
  star11 = createImage(90, 90, RGB);

  moves[0] = moon;
  moves[1] = star1;
  moves[2] = star2;
  moves[3] = star3;
  moves[4] = star4;
  moves[5] = star5;
  moves[6] = star6;
  moves[7] = star7;
  moves[8] = star8;
  moves[9] = star9;
  moves[10] = star10;
  moves[11] = star11;

  image(source1, width/2, height/2);
  
  if (thres) {
    filter(THRESHOLD);
  }
  if (blur) {
    filter(BLUR, 2);
  }
}

void draw() {  
  if (invert) {
    filter(INVERT);
  }

  rot += 1.0;
  source1.loadPixels();

  rotation(xPos_moon, yPos_moon, 50, 50, 0);
  rotation(xPos_star1, yPos_star1, 25, 25, 1);
  rotation(xPos_star2, yPos_star2, 25, 25, 2);
  rotation(xPos_star3, yPos_star3, 30, 30, 3);
  rotation(xPos_star4, yPos_star4, 30, 30, 4);
  rotation(xPos_star5, yPos_star5, 39, 30, 5);
  rotation(xPos_star6, yPos_star6, 30, 17, 6);
  rotation(xPos_star7, yPos_star7, 30, 20, 7);
  rotation(xPos_star8, yPos_star8, 23, 20, 8);
  rotation(xPos_star9, yPos_star9, 26, 25, 9);
  rotation(xPos_star10, yPos_star10, 30, 33, 10);
  rotation(xPos_star11, yPos_star11, 45, 45, 11);
}

void keyPressed() {
  if (key == 't') {
    thres = true;
  }

  if (key == 'i') {
    invert = true;
  }

  if (key == 'b') {
    blur = true;
  }
}


void keyReleased() {
  if (key == 't') {
    thres = false;
    image(source1, width/2, height/2);
  }

  if (key == 'i') {
    invert = false;
    image(source1, width/2, height/2);
  }

  if (key == 'b') {
    blur = false;
    image(source1, width/2, height/2);
  }
}

void rotation(int x_, int y_, int w_, int l_, int pos) {
  moves[pos].loadPixels();

  //extract pixels
  for (int y = y_-l_; y < y_+l_; y++) {
    for (int x = x_-w_; x < x_+w_; x++) {
      int loc = x + y*width;
      moves[pos].pixels[counter] = source1.pixels[loc];
      counter += 1;
    }
  }
  counter = 0;

  //rotate
  pushMatrix();
  translate(x_, y_);
  if (pos == 0) {
    rotate(radians(rot/4));
  } else {
    rotate(radians(rot/2));
  }
  image(moves[pos], 0, 0);
  //apply filters
  if (thres) {
    filter(THRESHOLD);
  }
  if (invert) {
    filter(INVERT);
  }
  if (blur) {
    filter(BLUR,2);
  }
  popMatrix();
}

 

 

Leave a Reply