We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Easy Paddle
Page Index Toggle Pages: 1
Easy Paddle (Read 442 times)
Easy Paddle
Mar 14th, 2010, 5:56am
 
Here is a really basic sketch but it has potential

http://www.openprocessing.org/visuals/?visualID=8228


Implements the technique of optikorakel
//openprocessing.org/visuals/?visualID=7554

From here you can modify when the ball collides but just checking to see what colour it comes into contact and then change direction based on where on the ellipse it hits.

Easy Ball collision code or even for some type of water-gun game where you can check and see what colour combination you can come up with.

Original sketch
...
http://openprocessing.org/visuals/?visualID=8227

www.instructables.com/id/shaped-buttons-with-Processing/

Here is the condensed code but it is faster when you have the BNC (bounce procedure) as a separate class/sketch/tab

Code:

//Owaun Scantlebury
//Implements the technique of optikorakel
//openprocessing.org/visuals/?visualID=7554
//instructables.com/id/shaped-buttons-with-Processing/

public boolean forward = true;
public boolean up = false;
public int px=0;
public int py =0;
public int ly=0;
public int lx=0;


public color[] A,B,mix;
PGraphics ulayer;
void setup(){
 mix = new color[8];
 mix[0]=color(233,23,23);
 mix[1]=color(5,55,35);
 mix[2]=color(255,245,0);
 mix[3]=color(133,33,123);
 mix[4]=color(9,125,125);
 mix[5]=color(145,245,0);
 mix[6]=color(104,10,10);
 mix[7]=color(133,25,225);
 size(255,255,JAVA2D);
 frameRate(3000);
 loadPixels();
 A= pixels;

 ulayer = createGraphics(width,height,P2D);
 ulayer.loadPixels();

 B = ulayer.pixels;

 ulayer.smooth();
 makemask();
 smooth();
 rectMode(CENTER);
 ellipseMode(CENTER);
}

void draw(){
 bounce();

 background(-1);

 //line(width/2,height/2,width-50,50);
 ////line(width-50,50,50,50);
 //line(width/2,height/2,50,50);
 //line(width/2,height/2,50,height-50);
 //line(width/2,height/2,width-50,height-50);
 //line(width/2,height/2,50,height/2);
 //line(width/2,height/2,width-50,height/2);
 //makepoint(width/2,height/2,25, 25,mix[0]);


 line(px,py,width-50,50);
 line(px,py,50,50);
 line(px,py,50,height-50);
 line(px,py,width-50,height-50);
 line(px,py,50,height/2);
 line(px,py,width-50,height/2);
 makepoint(px,py,25, 25,mix[0]);

 makepoint(width-50,50,25, 25,mix[1]);

 makepoint(50,50,25, 25,mix[2]);
 makepoint(50,height-50,25, 25,mix[3]);
 makepoint(width-50,height-50,25, 25,mix[4]);
 makepoint(50,height/2,25, 25,mix[5]);
 makepoint(width-50,height/2,25, 25,mix[6]);
 if (mousePressed) {
   background(-1);
   image(ulayer,0,0);

 }
}
void makemask(){
 ulayer.beginDraw();
 ulayer.rectMode(CENTER);
 ulayer.ellipseMode(CENTER);

 makepoint2(width/2,height/2,25, 25,mix[0]);

 makepoint2(width-50,50,25, 25,mix[1]);

 makepoint2(50,50,25, 25,mix[2]);
 makepoint2(50,height-50,25, 25,mix[3]);
 makepoint2(width-50,height-50,25, 25,mix[4]);
 makepoint2(50,height/2,25, 25,mix[5]);
 makepoint2(width-50,height/2,25, 25,mix[6]);
 ulayer.endDraw();
}

void makepoint(int x,int y,int h, int w,color f){
 //noFill();
 fill(-1);
 stroke(1);
 if (ulayer.get(mouseX,mouseY)==f){
   fill(f);
   rect(x,y,h,w);
 }

 ellipse(x,y,h,w);
}

void makepoint2(int x,int y,int h, int w,color f){

 ulayer.fill(f);
 ulayer.noStroke();

 ulayer.ellipse(x,y,h,w);
}


void keyPressed(){
if (!online)save("marker.png");
}


public void bounce(){
boolean rnd = true;
int by = 3;
int lo = 1;
int hi = 5;
 
if (forward){
 if (rnd)px+=random(lo,hi);
  if (!rnd){
   px+=by;
  }
}


  if (!forward){
    if(rnd)px-=random(lo,hi);  
    if (!rnd){
     px-=by;
    }
    }
 
  if (up){
   if (rnd)py-=random(lo,hi*2);
    if (!rnd){
      py+=by;
    }
    }
   
    if (!up){
     if(rnd)py+=random(lo,hi*2);
    if (!rnd){
      py-=by;
    }  
     
    }
 
 
  if (px>width)
    {
     
      forward = false;
     
    }
   
    if (get(px,py)==mix[0]){
      forward = false;
    }
  if (px<0)    forward = true;
  if (py>height)up     = true;
  if (py<0     )up     = false;
 }  
 
Page Index Toggle Pages: 1