Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
Achillx
Achillx's Profile
2
Posts
3
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
game of life
[3 Replies]
31-Oct-2012 01:13 PM
Forum:
Programming Questions
Hello,
I'm trying to make the Game of Life. It gives me no errors but it doesn't do anything!
Here is my code..
int sz = 100;
int recSize = 5;
int seeds = 30;
int field[][] = new int[sz][sz];
void setup() {
frameRate(5);
size(recSize*sz, recSize*sz);
for ( int i = 0; i < seeds; i++) {
field[int(random(0, sz))][int(random(0, sz))] = 1;
}
}
void draw() {
//noStroke();
// background(0);
drawField();
replaceCells();
}
void replaceCells() {
for ( int x = 1; x < sz-1; x++) {
for ( int y = 1; y < sz-1; y++) {
int AboveLeft = field[x-1][y-1];
int AboveCenter = field[x][y-1];
int AboveRight = field[x+1][y-1];
int Left = field[x-1][y];
int Right = field[x+1][y];
int BottomLeft = field[x-1][y+1];
int BottomCenter = field[x][y+1];
int BottomRight = field[x+1][y+1];
int sum = AboveLeft+AboveCenter+AboveRight+Left+Right+BottomLeft+BottomCenter+BottomRight;
println(sum);
if (field[x][y] == 1 && sum < 2) {
field[x][y] = 0;
}
if (field[x][y] == 1 && sum == 2) {
field[x][y] = 1;
}
if (field[x][y] == 1 && sum == 3) {
field[x][y] = 1;
}
if (field[x][y] == 1 && sum > 3) {
field[x][y] = 0;
}
if (field[x][y] == 0 && sum == 3) {
field[x][y] = 1;
}
}
}
}
void drawField() {
for ( int c = 0; c < sz; c++) {
for ( int d = 0; d < sz; d++) {
stroke(100);
if (field[c][d] == 1) {
fill(255);
}
else {
fill(0);
}
rect(c*recSize, d*recSize, recSize, recSize);
}
}
}
How to control reading speed
[6 Replies]
15-Oct-2012 02:42 AM
Forum:
Contributed Library Questions
I'm writing a code to "translate" word into sound but it plays it almost instantly!
I want to control how many letters/second is reading which means how many note/second it plays.
I used something to delay the processing but when I run it, the processing app freezes!
import arb.soundcipher.*;
SoundCipher sc = new SoundCipher(this);
long lastTime = 0;
void setup() {
frameRate(10);
sc.instrument(90);
String geo[] = loadStrings ("dog.txt");
String wholeText = join(geo, "");
}
void draw(){
for (int i=0; i < wholeText.length(); i++) {
char c;
c = wholeText.charAt(i);
println ("Now playing letter:" + c);
sc.playNote (c -40, 100, 0.5);
lastTime = millis();
while (millis() - lastTime < 100){
println("do every 1/10 of sec");
}
}
«Prev
Next »
Moderate user : Achillx
Forum