Yesterday I started doing some code to practice a bit the concepts of OOP... I'm trying to make a simple Space Invaders alien generator... Basically I want to create a code that will create a 12x8 grid of square objects, and fill it randomly white or black. Then is the part I got stuck... I want to take that grid and just flip it so to create a symmetric shape.... I basically create the first half of the alien and flip horizontally to complete it.
I am using a 2d Array to create the first grid and push/pop Matrix for the symmetry... But the result is upside down as you can see from the code below... Any ideas?
Tile [][] grid;
//number of rows and columns
int cols;
int rows;
void setup() {
size(600, 600);
background(255);
//cols=width/6;
// rows=height/6;
cols=12;
rows=8;
grid = new Tile[cols][rows]; //the array dimensions are equal to n.of rows/columns
I'm a bit at loss at the moment... I'm not an expert coder so I'm still learning to use basic things such as how to deal with 2d Array...
What I'm trying to do is, I guess, not that hard. I created a grid of objects with the line of code provided on the explanation of a 2dimensional array... like this;
Tile [][] grid;
//number of rows and columns
int cols;
int rows;
void setup() {
size(600, 600);
cols=width/6;
rows=height/6;
grid = new Tile[cols][rows]; //the array dimensions are equal to n.of rows/columns
//loop through cols and rows
for (int i=0; i<cols; i++) {
for (int j=0; j<rows; j++) {
//initiate objects
grid[i][j] = new Tile (i*60, j*60, 60, 200);
}
}
}
SO this part I get, it's not complicated... What I want to do next somehow gets me confused. What I did is first rendering the grid with a fill(200).
I then wanted to change the color of one of the cell, meaning I have to access it by specifying the indexes of the array, something like this
void draw() {
background(50);
for (int i=0; i<cols; i++) {
for (int j=0; j<rows; j++) {
//show me them goodies
grid[i][j].display();
}
}
grid[4][4].black();
}
So the nested loops actually render the grid (display is a class method), and the line 10 should access the Tile at position 4,4 and change fill(200) to 0....
but it doesn't... any idea why?
I'll write you down also the class file (just in case);
class Tile {
float x, y;
float side;
int col;
Tile (float tempX, float tempY, float tempSide, int tempCol) {
I've been trying this for a while, but I don't understand if it's me missing something or whatelse....
I'm trying to create a simple GUI where I have a color picker... Problem is the slider are quite small and I would like to augment the HEIGHT of the RGB slider...
The way it should be is that the last two parameters are for length (siderW+50) and height (0)... But no matter what value I assign to the last it just won't change...
Is it possible or not?
The alternative otherwise would be to use the simple Slider with the size I want; I would have then to change color with the setColor method and so forth for the two other color picker slider (I'm thinking RGB)... Lot of work, so I hope you might help shed some light on the issue...
I've had a lot of spare time on my hand the last few days and I've been fooling around with processing and the mighty WEB.
All I want to do is for processing to communicate with a website, blog or similar, download informations from the page and turn them into values to use for other purposes (such as dimming led through an Arduino i.e. absolutely pointless programming exercise). I chose for now to use facebook as a target for experimenting since I thought many people had tried before already.
Anyway I've scanned the forum, the processing wiki, and the FB developer page hoping to understand how to do it, without much success.
I found out this line of code in here that uses REST API for FB:
and it says to use the Graph API even though it is not clear at all to me how to implement that into the coding. All I see is a bunch of https examples I don't know how to translate in useful coding for Process.
In the REST CODE I posted you can read that it access informations of the users through specific methods:
String xmlResponse = fbCallMethod( new String[] {
"method=facebook.Users.getInfo",
"uids=" + fbUserIDs,
"fields=uid,first_name,last_name", // see link above for more options
I fooled around using old RestCode syntax without much success.
Is anyone up to write down a possible way to make Processing inquiry a specific page and download public informations? I know I'm not the only one interested out there!
I'll keep on fooling around with the code, hoping to bring something more than a request to the discussion
I've been working on this project for a while now after I read a book called Emergence: The Connected Lives of Ants, Brains, Cities, and Software... Super cool text... Without going too much in details I want to create a series of identical objects that behave following few simple rules, while interacting with each other...A sort of interconnected frame of objs that observe and react on each other...To make the idea more clear I made a small viz of the logic behind the code...check the png i posted here... If you look at my coding you'll see that I: 1) created an array of objects called lampList 2) told to two of them to Display(): this means thy will simply see the dist() btw center & mouseX/Y and use that to determine the transparency. 3)assigned the third obj the doOpposite(): it will see what is the condition of the first obj and do the opposite!
The thing I can't seem to do is apply the same three behavior to ALL obj! All object should be able to: 1)read the distance to the mouseX/Y and behave consequently 2)see what is the closest obj doing, and do the opposite
I added some more comment to the coding to explain what I'm doing...
//create the arrayList and create 3 Lamp OBJ... lampList = new ArrayList(); lampList.add(new Lamp(200,150)); lampList.add(new Lamp(500,300)); lampList.add(new Lamp(300,350)); }
void draw() { background(0); //apply behaviours to each array obj for(int i=0;i<lampList.size();i++) { lampList.get(0).display(); lampList.get(2).display(); lampList.get(1).doOpposite(); }
}
void mouseMoved() { lastMove = millis(); }
class Lamp { float x; float y; int ellipseWidth; float transp; color c;
Lamp(float tempx, float tempy) { x = tempx; y = tempy; ellipseWidth = 50; c = color(random(255),random(255),random(255)); }
void display() { ellipseMode(CENTER); /* here is the trick! calculate the dist between center of the obj and mouse X & Y. costrain the values between 0 and 250 and send it to the fill() */ transp = dist(x, y, mouseX, mouseY); transp = constrain(transp,0,255); fill (c,transp); ellipse(x, y, ellipseWidth, ellipseWidth); }
void doOpposite() { /* here is the first probem which is that I managed to only follow a specific obj, and not the closest...So here I tell the second to check the first */ stealTransp = lampList.get(0).transp; diff = scaleRange - stealTransp; ellipseMode(CENTER); fill (c, diff); ellipse(x, y, ellipseWidth, ellipseWidth); }
}
Hopefully if all works, strange cool things should happen...
I've been trying to this for a few days but I'm ashamed to say I'm stuck....
The code I'm doing is meant to visualize a project I'm working on. Basically it's a bunch of lamps that reacts to the user interaction by dimming on and off...Pretty straightforward....
On the screen you have two light sources ( two ellipses) and the mouse cursor is playing as the visitor: the closest the visitor/cursor the more the light dim; and this is what I called first behavior. Now I'd like to add a new behavior that is triggered whenever the visitor/cursor stands still; I'd like to make Processing understand that the cursor is still for, let's say 3 seconds, and start a new behavior, like changing color to the light (I haven't figure out exactly what but let's stick to that now).
Here is the code;
Lamp myLamp;
Lamp myLamp2;
void setup(){
size(800,600);
background(0);
smooth();
myLamp = new Lamp(200,150);
myLamp2 = new Lamp (500,300);
}
void draw() {
myLamp.display();
myLamp2.display();
println(" c value is " + myLamp.c + " and mouse X is " + mouseX);
}
/*
This is the class used to define the Lamp Object attributes
*/
class Lamp {
//data
float posX;
float posY;
int ellipseWidthHeight;
float c; // the color of the speheres (will change with mouse positioning)*/
/*
constructors assign values to the attributes.
*/
Lamp(float tempPosX, float tempPosY) {
posX = tempPosX;
posY = tempPosY;
ellipseWidthHeight = 50;
}
/*
methods determine what to do with the constructors
*/
void display() {
ellipseMode(CENTER);
//color c is set by calculating distance beteween mouse pointer and center of te circles
So the dimming effect is done by assigning to the fill() a value (C) that is the Distance between MouseX and Y and the center of the ellipses.
What I tried to do without success is reading the Mouse XandY: if the value stays the same for 3 seconds ( = the cursor is still ) then do something.....