WOP : 3-D box rotating on its own axis using processing

As a part of project, today I tried to make a 3-D box rotating on its own axis using processing.
this is how it looked like



import processing.opengl.*;
int depth = 200;
//Cube cubes = new Cube;
Cube cubes = new Cube(150, 75, depth/2);
void setup() {
size(640,480,P3D);
noStroke();

}

void draw() {
background(0);
fill(200);
pointLight(51, 102, 255, 65, 60, 100);
pointLight(200, 40, 60, -65, -60, -150);

// Raise overall light in scene
ambientLight(70, 70, 10);
translate(width/2,height/2,-depth);
rotateY(frameCount * 0.01);
cubes.drawCube();
}

class Cube{
int w,h,d;

Cube(int w, int h, int d){

this.w=w;
this.h=h;
this.d=d;
}
void drawCube(){
beginShape(QUADS);
vertex(-w/2,-h/2,-d/2);
vertex(w,-h/2,-d/2);
vertex(w,h,-d/2);
vertex(-w/2,h,-d/2);

vertex(-w/2 , -h/2 , d);
vertex(w, -h/2 , d );
vertex(w , h , d );
vertex(-w/2 , h , d );

// Left face
vertex(-w/2 , -h/2 , -d/2 );
vertex(-w/2 , -h/2, d );
vertex(-w/2, h , d );
vertex(-w/2 , h , -d/2 );

// Right face
vertex(w , -h/2 , -d/2 );
vertex(w , -h/2 , d );
vertex(w , h , d );
vertex(w , h , -d/2 );

// Top face
vertex(-w/2 , -h/2 , -d/2 );
vertex(w , -h/2 , -d/2 );
vertex(w , -h/2 , d );
vertex(-w/2 , -h/2 , d );

// Bottom face
vertex(-w/2 , h , -d/2 );
vertex(w , h , -d/2 );
vertex(w , h , d );
vertex(-w/2 , h , d );

endShape();
}
}

Advertisements

LED’s blinking according to coordinates of mouse

This is the experimental set-up I tried using Processing inheriting Arduino Libraries. Objective I wanted to do was to make red and blue coloured LED’s to blink according to the location of mouse’s X- coordinate is whether even or odd when clicked. i.e. When Mouse’s X-coordinate is even Red coloured LED blinks and when it is odd Blue Coloured LED will blink while clicking it including making different sized ellipse on the screen according to clicks.
hardware setting was nothing that hard, just two LEDs connected to pin 13 and pin 12 of arduino. Thats it.

Rest programming in Processing was as following:-

import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int ledPin1 = 13;
int ledPin2 = 12;
void setup(){
arduino = new Arduino(this, Arduino.list()[0],57600);
arduino.pinMode(ledPin1, Arduino.OUTPUT);
arduino.pinMode(ledPin2, Arduino.OUTPUT);
size(400,400);
background(0);
frameRate(15);
}
void draw(){
color c = color(200,0,0);
if(mousePressed == true){
fill(c, 150);
if(mouseX % 2 == 0){
fill(255,255,0);
ellipse(mouseX,mouseY,25,25);
arduino.digitalWrite(ledPin1, Arduino.HIGH);
delay(20000);}
arduino.digitalWrite(ledPin1,Arduino.LOW);
if(mouseX % 2 == 1){
ellipse(mouseX,mouseY,40,40);
arduino.digitalWrite(ledPin2, Arduino.HIGH);
delay(10000);}
arduino.digitalWrite(ledPin2, Arduino.LOW);
}
else{
fill(0);}
}

Processing using Arduino

Processing is an awesome library for interactive designers. I was reading stuff about it from last 1 month and after trying its example got an idea to implement after synchronising Arduino and processing and outcome was more awesome.
I synchronised arduino with processing library by following this link.