Wednesday, April 30, 2014
Tarot code
"import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;
import ddf.minim.*;
import processing.video.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public class Tarot3dv extends PApplet {
String mType=".mp4";
Minim sounder;
AudioPlayer myShuffling, myCardFlip , bgMusic;
boolean mouseLock=false;
int over=0; // what is the mouse over?
CardDeck deck;
Card cPast=null;
Card cPresent=null;
Card cFuture=null;
int shuffling=0;
Movie mIntro1;
Movie mIntro2;
Movie mOutro;
int vPlaying=0; // lock out mouse while movie playing
Movie current;
Movie randM[];
int vNext=0; // What movie to play next
int INTRO1=0;
int INTRO2=20;
int IPAST=11;
int IPRESENT=12;
int IFUTURE=13;
int PAST=1;
int PRESENT=2;
int FUTURE=3;
int OUTRO=9;
int NOTHING=999;
// intros
Movie mIPast;
Movie mIPresent;
Movie mIFuture;
// movies for Selected actual cards
Movie mvPast;
Movie mvPresent;
Movie mvFuture;
//PImage cn1;
//PImage cn2;
//card positions
int xDeck =50;
int xPast=180;
int xPresent=330;
int xFuture=480;
int yCards=360;
int cWidth =100;
int cHeight=140;
float mPast=0; //Controller for moving cards in secs/60?
float mPres=0;
float mFut=0;
float mMax=30; //Max time/60 secs for card movement
float yRx = (yCards+cHeight/2); // the y coord for rotating cards around X axis.
public void setup() {
randM=new Movie[6];
size(700, 520, P3D);
//frameRate(30);
println ("loading movies");
mIntro1 = new Movie(this, "Vmisc/intro" + mType);
mIntro2 = new Movie(this, "Vmisc/ppf" + mType);
mOutro = new Movie(this, "Vmisc/outro" + mType);
vNext=INTRO1;
mIPast = new Movie(this, "Vmisc/past" + mType);
mIPresent = new Movie(this, "Vmisc/present" + mType);
mIFuture = new Movie(this, "Vmisc/future" + mType);
for (int i =0;i<6;i++){
randM[i] = new Movie(this, "Vmisc/r"+ i + mType);
}
println("creating deck");
deck=new CardDeck();
deck.shuffle();
//cn1=loadImage("Candle_1.jpg");
//cn2=loadImage("Candle_2.jpg");
println("loading sound");
sounder = new Minim(this) ;
myShuffling = sounder.loadFile("shuffling-cards-1.mp3") ;
myCardFlip = sounder.loadFile("cardFlip.mp3") ;
bgMusic = sounder.loadFile("Highline.mp3") ;
bgMusic.loop(10);
bgMusic.shiftGain(-60, -20, 2000); // decibel volume -80 to 13
println("end setup");
}
public void draw() {
translate(0,0,0);
background(0);
fill(18); // Dark gray to mark the space for cards
// Movie display the currnet frame from the movie.
if ((vPlaying==0 && vNext!=NOTHING) // if theres a movie to play
&& (mPast==0 && mPres==0 && mFut==0 && shuffling == 0)) // and nothing's moving
chooseMovie(); // start it
image(current, 30,0, 620, 350); // display a frame of the movie
// Candles
//image(cn1,30,100,50,100);
//image(cn2,width-(30+50),100,50,100);
if (vPlaying>0) vPlaying--; // 0= no movie is currently in progress
if (mPast>0) mPast--;
if (mPres>0) mPres--;
if (mFut>0) mFut--;
displayTable(); // display everything on the table
}
// Only come here if nothing is playing and a Next video is selected
// Decide which movie to play next and start it
public void chooseMovie(){
int r=PApplet.parseInt(random(20));
println("r", r, " next=",vNext);
// What do we want to play next...
if (vNext==INTRO1) {
vNext=NOTHING;
current=mIntro1;
} else
if (vNext==INTRO2) {
vNext=NOTHING;
current=mIntro2;
} else
if (vNext==OUTRO) {
vNext=NOTHING;
current=mOutro;
} else
if (vNext==PAST ) {
if (r<6)
current=randM[r];
else{
current=mvPast;
vNext=PRESENT;}
} else
if (vNext==PRESENT ) {
if (r<6)
current=randM[r];
else{
current=mvPresent;
vNext=FUTURE;}
} else
if (vNext==FUTURE) {
if (r<6)
current=randM[r];
else{
current=mvFuture;
vNext=OUTRO;}
} else
if (vNext==IPAST) {
if (r<6)
current=randM[r];
else{
current=mIPast;
vNext=-1;}
} else
if (vNext==IPRESENT) {
if (r<6)
current=randM[r];
else{
current=mIPresent;
vNext=-1;}
} else
if (vNext==IFUTURE) {
if (r<6)
current=randM[r];
else{
current=mIFuture;
vNext=-1;}
}
if (vNext == -1) // after a PPF intro might need to start reading
if (cPast !=null && cPresent !=null && cFuture != null) // all cards ar laid
{
vPlaying=40; // give it time to start
vNext=PAST;
}
else
vNext=NOTHING;
current.stop();
vPlaying=40; // give it time to start
current.play(); // switched movies, now play it.
}
public void mousePressed(){
if (mouseLock) return; // Not a new click so exit
if (vPlaying>0) return; // dont respond to clicks while a movie is playing
mouseLock=true;
over=locateMouse();
if (over==1){
myShuffling.rewind();
myShuffling.play();
deck.shuffle();
shuffling=22;
cPast=null; cPresent=null;cFuture=null;
vNext=INTRO2;
}
if (over==2&&cPast==null){
myCardFlip.rewind();
myCardFlip.play();
cPast = deck.deal1();
mvPast = new Movie(this, "CardV/" + cPast.name + mType);
vNext = IPAST;
mPast=mMax; // take a half second to move.
}
if (over==3&&cPresent==null){
myCardFlip.rewind();
myCardFlip.play();
cPresent = deck.deal1();
mvPresent = new Movie(this, "CardV/" + cPresent.name + mType);
vNext=IPRESENT;
mPres=mMax; // take a half second to move.
}
if (over==4&&cFuture==null){
myCardFlip.rewind();
myCardFlip.play();
cFuture = deck.deal1();
mvFuture = new Movie(this, "CardV/" + cFuture.name + mType);
vNext=IFUTURE;
mFut=mMax; // take a half second to move.
}
// if (cPast!=null && cPresent!=null && cFuture!=null)
// {
// vPlaying=30; // give it half a sec to start
// vNext=PAST;
// }
}
public int locateMouse(){
if (mouseY < yCards) return 0;
if (mouseY > yCards + cHeight) return 0;
if (mouseX > xDeck && mouseX xPast && mouseX<=xPast+cWidth) return 2; //over past
if (mouseX > xPresent && mouseX<=xPresent+cWidth) return 3; //over present card
if (mouseX > xFuture && mouseX<=xFuture+cWidth) return 4; //over future card
return 0;
}
public void displayTable()
{
// Display all the foreground features
// That is, everything rotated like on a table.
pushMatrix();
translate(0,yRx,10); // put the x axis at halfway down the deck
rotateX(PI/4); // turn card for 3d
displayDeck();
displayCard(cPast, xPast, mPast/mMax);
displayCard(cPresent, xPresent, mPres/mMax);
displayCard(cFuture, xFuture, mFut/mMax);
popMatrix();
}
public void displayCard(Card c, float atX, float xFact)
// display a card c at position atX or at xFact towards it
{
if (c==null)
{ // No card for this slot yet
if ((mPast+mPres+mFut)==0) // only show card spot if nothing moving
rect(atX,cHeight/-2,cWidth,cHeight);
return;
}
if (xFact>0) // is this card on the move
translate(0,0,cHeight/1.5f); // set zaxis closer while turning
rotateX((2*PI)-(PI*(xFact))); // turn card axis xFact fraction
if (xFact>0.5f)
image(deck.backside,xDeck+(int)((atX-xDeck)*(1-(xFact))),(cHeight/-2),cWidth,cHeight);
else
image(c.cardFace,xDeck+(int)((atX-xDeck)*(1-(xFact))),(cHeight/-2),cWidth,cHeight);
}
public void displayDeck()
// display the card deck
{
if (shuffling>0) shuffling--;
pushMatrix();
for (int i=0;i<22+shuffling;i++)
{
image(deck.backside,xDeck,(cHeight/-2),cWidth,cHeight);
translate(1,0,2);
}
popMatrix();
}
public void mouseReleased(){
mouseLock=false;
}
// Called every time a new frame is available to read, makes the image available
public void movieEvent(Movie m) {
int m2=30-vPlaying;
//println("time since last frame="+m2);
vPlaying=30; // lock out mouse for some frames
m.read();
}
class Card
{
int sortkey;
//int description;
boolean dealt=false;
int num;
String name;
PImage cardFace;
float sortSeq;
Card(String iName)
{
name=iName;
dealt=false;
cardFace=loadImage("cards/" + name+".jpg");
}
}
class CardDeck
{
int deckSz=22; // cards in deck
//Card cards[];
Card[] cards;
PImage backside;
CardDeck(){
// initialize the deck by creating all the cards in it.
backside=loadImage("cards/Backside.jpg");
cards=new Card [deckSz];
cards[0]= new Card("Fool");
cards[1]= new Card("Magician");
cards[2]= new Card("HighPriestess");
cards[3]= new Card("Empress");
cards[4]= new Card("Emperor");
cards[5]= new Card("Hierophant");
cards[6]= new Card("Lovers");
cards[7]= new Card("Chariot");
cards[8]= new Card("Strength");
cards[9]= new Card("Hermit");
cards[10]= new Card("WheelofFortune");
cards[11]= new Card("Justice");
cards[12]= new Card("HangedMan");
cards[13]= new Card("Death");
cards[14]= new Card("Temperance");
cards[15]= new Card("Devil");
cards[16]= new Card("Tower");
cards[17]= new Card("Star");
cards[18]= new Card("Moon");
cards[19]= new Card("Sun");
cards[20]= new Card("Judgement");
cards[21]= new Card("Universe");
}
// Give each card a random number and mark them as not dealt
public void shuffle()
{
for (int i=0; i
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment