ImSpartacus
YaBB Newbies
Offline
Posts: 5
random() and open sketch file in a sketch file
Nov 28th , 2009, 4:43pm
Hello, everyone! I am a newbie when it comes to processing, I can understand alittle bit but a lot of times I need explanations. I really need some help on this question. Currently I found a script written by someone which i really like because it takes the time to explain how things work. I am currently messing around with it and this is what i have so far float a; void setup() { size(800,600); stroke(#9d0000); frameRate(30); } void draw() { a -= 0.08; background(0); for (int x = -5; x < 25; x++) { for (int z = -5; z < 25; z++) { int y = int(24 * cos(-0.55 * distance(x,z,0,0) + a)); float xm = x*17 -8.5; float xt = x*17 +8.5; float zm = z*17 -8.5; float zt = z*17 +8.5; int halfw = (int)width/2; int halfh = (int)height/2; int isox1 = int(xm - zm + halfw); int isoy1 = int((xm + zm) * 0.5 + halfh); int isox2 = int(xm - zt + halfw); int isoy2 = int((xm + zt) * 1 + halfh); int isox3 = int(xt - zt + halfw); int isoy3 = int((xt + zt) * 0.5 + halfh); int isox4 = int(xt - zm + halfw); int isoy4 = int((xt + zm) * 1 + halfh); fill (#9d0000); quad(isox2, isoy2-y, isox3, isoy3-y, isox3, isoy3+40, isox2, isoy2+40); fill (#9d0000); quad(isox3, isoy3-y, isox4, isoy4-y, isox4, isoy4+40, isox3, isoy3+40); fill(#9d0000 + y * 0.05); quad(isox1, isoy1-y, isox2, isoy2-x, isox3, isoy3-y, isox4, isoy4-x); } } } float distance(float x,float y,float cx,float cy) { return sqrt(sq(cx - x) + sq(cy - y)); } void keyPressed() { if (key == CODED) { if (keyCode == UP) { a -= 0.08 + .1; } else if (keyCode == DOWN) { a -= 0.08 + .2; } else if (keyCode == LEFT) { a -= 0.08 + .3; } else if (keyCode == RIGHT){ a -= 0.08 + .5; } else { a -= 0.08; } } currently I have where you push the arrow keys it increases the radius and speed. Thats good and what I want but i want it so instead of having to push the keys, it does it randomly by itself. I know about the random function but i cant seem to get it to work. Any help on how to make this work would be great. Also if anyone knows how to make it simplier (if thats a word) that would be great as well. Again the majority of this is not my coding the only thing i did was change some numbers here and there and typed the key functions. im a newbie. thanks Also does any one know if there is a code that allows you to open a sketch file within another sketch file?