Quantcast
Channel: Arduino - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 747

Coming to an end with this assignment. Just cannot make the text appear on the screen.

$
0
0
int pageNumber = 1;
//Variables for falling ball
float y0 = 0;
float x0 = random (width);
float y0_speed=3;

PImage bot;
PImage gift;
PImage img;
PImage img2;

int quantity = 300;
float [] xPosition = new float[quantity];
float [] yPosition = new float[quantity];
int [] flakeSize = new int[quantity];
int [] direction = new int[quantity];
int minFlakeSize = 1;
int maxFlakeSize = 5;
int sceneNumber = 1;

PFont f; // Global font variable
float x; // Horizontal location
int index = 0;

String[] headlines = {
  "Merry Christmas!!! ",
  "and",
  "Happy New Year!!!",
};

import processing.serial.*;
import cc.arduino.*;
import com.tinkerkit.*;

Arduino arduino;

//declare the potentiometer
TKPotentiometer pot;

float minVal = 1023;
float maxVal = 0;

void setup() {
size(800,600);
  arduino = new Arduino(this, Arduino.list()[3], 57600);

   img=loadImage("Fullpage.png");
   img2=loadImage("800-600pixels.jpg");
   gift=loadImage("gift2.png");
   bot=loadImage("santasmall.png");
  //for every tinkerkit component we have to pass
  //the arduino and the port
  pot = new TKPotentiometer(arduino, TK.I0);

  noStroke();

  frameRate(30);
  noStroke();
  smooth();
    for(int i = 0; i < quantity; i++) {
    flakeSize[i] = round(random(minFlakeSize, maxFlakeSize));
    xPosition[i] = random(0, width);
    yPosition[i] = random(0, height);
    direction[i] = round(random(0, 1));
  }
}
void draw (){
if (pageNumber == 1) {
  // background(0);
 imageMode(CORNER);
image(img, 0, 0, 800, 600);
}
{
  img = loadImage("Full-page.png");
    f = createFont( "American Typewriter", 70);
  textFont(f, 50);
  fill(255, 255, 255);
  textAlign (LEFT);


if (pageNumber == 2) {
   imageMode(CORNER);
  image(img2, 0, 0);
  // Display headline at x location

//get the potentiometer values
  float val = pot.read();

  //calibration
  if (val < minVal) minVal = val;
  if (val > maxVal) maxVal = val;

  //map the values of the potentiometer
  //on the width of the window
  val = map(val, minVal, maxVal, 100, 700);

  imageMode(CENTER);
  image(bot, val, height-115);

  //print the potentiometer values
  println(val);

   for(int i = 0; i < xPosition.length; i++) {

    ellipse(xPosition[i], yPosition[i], flakeSize[i], flakeSize[i]);

    if(direction[i] == 0) {
      xPosition[i] += map(flakeSize[i], minFlakeSize, maxFlakeSize, .1, .5);
    } else {
      xPosition[i] -= map(flakeSize[i], minFlakeSize, maxFlakeSize, .1, .5);
    }

    yPosition[i] += flakeSize[i] + direction[i];

    if(xPosition[i] > width + flakeSize[i] || xPosition[i] < -flakeSize[i] || yPosition[i] > height + flakeSize[i]) {
      xPosition[i] = random(0, width);
      yPosition[i] = -flakeSize[i];
    }

  }
   //Blank out the background
  fill(255,0);
  rect(0,0,width,height);

  //Check if the ball is off the screen
  if(y0 > height+15)  //15 is the radius of the ball
  {
    y0 = -15; //Move it back to just above the screen
    x0 = random(width); //Pick a new random horizontal location on the canvas
    y0_speed = random(3, 7); //Pick a new random speed between 3 and 7
  }

  //Move the ball
  y0 += y0_speed; //Increase the balls y value by the variable
                  //y0_speed each time through the loop

  //Draw the ball
  fill(255,255,255);
  image (gift, x0, y0, 30, 30);
}
void keyPressed(){
  if (key == '1'){
   pageNumber = 1;
  }
   if (key == '2'){
   pageNumber = 2;
  }

}

Viewing all articles
Browse latest Browse all 747

Trending Articles