Showing posts with label mass writing. Show all posts
Showing posts with label mass writing. Show all posts

Friday, 5 December 2008

Chunk16 - Source Code

Thanks to Martin, I downloaded JEdit, this makes it much easier to cut and paste the code. After installing JEdit the plug in manager can install codeToHTML.
JEdit adds line numbers too, so this should also help explain the relevant statements in the text.I cant see there being much changes apart from making the filled circles smaller when they are at the top of the picture.
Clicking on the picture will start the randomizer application (If you have a Java runtime environment installed...)





  1:/*
2: title: Funky Chunk 16
3: description: random pattern generator
4: created: December 2, 2008
5: by: Rosie Wood
6:*/
7:
8:// define Global variable values
9://These are constant variables and therefore they are not changed
10://by the program. Setting their value here in one place helps with maimtenance
11:int sizeWindow=600;
12:int centre=sizeWindow/2;
13:int xpos = centre;
14:int ypos = centre;
15:int patternsPerPicture=round(random(2,50));
16:
17://this variable is changed frequently by the application
18:int interval=30;
19:
20:// set the sketch window size and background
21://turn off fill so that patterns underneath can be seen
22://set the rate that the screen refreshes at (found this value was best for this application?)
23:void setup(){
24: size(sizeWindow, sizeWindow);
25: background(0);
26: stroke(204, 102, 0);//colour red
27: noFill();
28: frameRate(.2);
29: draw();}
30:
31:void draw(){
32: //local variables
33: int count=0;
34: int design=0;
35: for(count=0;count<patternsPerPicture;count++){
36: if(count%100==0)background(0); //set the backgound to black sometimes
37: interval=round(random(5,70));//increment by interval in while loops
38: changeColour();
39: design=round(random(1,9)); //a random numver for which design to use in the switch
40: switch(design){
41: case 1:
42: while(interval<width){ //while intervel is less than the width of the window
43: drawCircle2(interval-round(random(40,width/2)));//call function drawCircle2 with a random parameter
44: interval+=round(random(3,70)); }
45: break;
46: case 2:
47: drawCircles(round(random(20,round(random(1,50))))); //call the drawCircles function
48: break;
49: case 3:
50: strokeWeight(getSW());//set the strokewright to the number returned by the getSW function
51: while(interval<width){
52: drawCircle2(interval-round(random(1,width/2)));//use the drawCircle2 function
53: interval+=round(random(1,width/2));}
54: break;
55: case 4:
56: strokeWeight(getSW());
57: while(interval<width){
58: drawCircle3(interval-round(random(2,width/4)));
59: interval+=round(random(1,30));}
60: break;
61: case 5: //As this case doesnt have a break it uses the same code as case 6
62: //the following code can be uncommented to add lines but I dont like them much
63: /*strokeWeight(getSW());
64: for(int b=1;b<width;b=b+round(random(1,20))){
65: int down=round(random(width/2));
66: int across=round(random(width/2));
67: line(xpos,ypos,across-b,down-b);
68: line(xpos,ypos,across+b+xpos,down-b);
69: line(xpos,ypos,across-b,width-down+b);
70: line(xpos,ypos,across+b+xpos,width-down+b);}
71: break;
72: */
73: case 6:
74: while(interval<width){
75: fill(random(255),random(255),random(255)); //use a random colour to fill circle
76: drawCircle2(interval);
77: interval+=round(random(2,200));}
78: noFill();//switch off fill
79: break;
80: case 7:
81: while(interval<width){
82: drawCircle2(interval);
83: interval+=random(1,40);}
84: break;
85: case 8:
86: while(interval<width){
87:
88: fill(random(255),random(255),random(255));//fill squares with a random colour
89: drawSquares((round(random(1,100))));//call function drawSquares with a random number
90: interval+=round(random(100,400));}//made this interval larger to stop filled squares covering over preceeding patterns
91: noFill();
92:
93: break;
94: case 9:
95: while(interval<width){
96: changeColour();
97: drawSquares(interval-round(random(1,width/2)));//draws unfilled squares
98: interval+=20;}
99: break;
100: }}
101: patternsPerPicture=round(random(2,50));//change number of patterns for next picture
102: }
103:
104://function to change the stroke colour doesnt accept parameter and doesnt return anything
105:void changeColour(){
106: stroke(random(255),random(255),random(255));}
107:
108://function draws circles accepts parameter gap and uses it to increment loop untill
109:void drawCircles(int gap){
110: for(int n=0;n<round(random(width/2,width));n+=gap){
111: drawCircle(n);}}
112:
113://no parameters, no return valur
114:void drawCircle2(int diameter){
115: ellipse(xpos, ypos, diameter-random(5,diameter), diameter-random(5,diameter));}
116:
117://accepts 1 parameter
118:void drawCircle3(int diameter){
119: ellipse(xpos, ypos, (diameter*random(5,diameter))/(random(5,diameter)*19), (diameter*random(5,diameter))/(random(5,diameter)*19) );}
120:
121:void drawSquares(int diameter){
122: int r= round(random(1,4));
123: //if/ifelse/else block
124: if(r==1){
125: rectMode(CENTER);}
126: else if(r==2){
127: rectMode(RADIUS);}
128: else if(r==3){
129: changeColour();}
130: else{
131: stroke(round(random(255)),round(random(255)),round(random(255)),round(random(255)));}
132: rect(xpos,ypos,diameter,diameter);}
133:
134://returns integer valur for stroke weight depending on framecount
135:int getSW(){
136: int fc=round(random(frameRate*500)/5);
137: //case statement with default value
138: switch(fc){
139: case 1:return 1;
140: case 2:return 2;
141: case 3:return 3;
142: case 4:return 4;
143: case 5:return 5;
144: case 6:return 6;
145: case 7:return 7;
146: case 8:return 8;
147: case 9:return 9;
148: default :return round(random(1,4));}}
149:
150:void drawCircle(int diameter){
151: ellipse(xpos, ypos, diameter, diameter);
152: ellipse(xpos, ypos, diameter-interval, diameter);
153: ellipse(xpos, ypos, diameter, diameter-interval);
154: ellipse(xpos, ypos, diameter, diameter);}

Friday, 17 October 2008

Making a Start

I have done a fair amount of Java Programming and have used the Graphics class a fair bit, but this area of Java was mostly self taught. My introduction to Java graphics was the Timothy Budd course book for M301.
I have researched various graphic concepts in the past, but I always come back to the standard Java awt graphics package because of its simplicity. I have been intending to start using the Graphics 2D class, as I think I understand most of its methods.
Maths is something I studied way back in MU120, but trigonometry and algebra are now just a foggy memory. This is a pity as I think they would make some interesting effects.
I have a web site where my Java RPG Game Solundria can be launched with Web Start. The game is in serious need of a graphical makeover, so I am hoping that the study of Processing may help me accomplish this.
I put a blog post up on my page on 38 minutes (a digital Media Web Site) about the OU record attempt.
I did a bit of browsing and started to read a sample chapter of the Processing book, but it seemed to time out or something. The Processing methods were not as bad as I had expected and I cant wait for the book voucher to arrive, so I can try some new stuff out.
Its maybe a forlorn hope but I'd like to make some kind of business when I eventually (if ever...) finish Solundria. I will have to examine the licence for the Processing classes as they are Open Source. Even if they cant be used in my game some of the methods are very similar to Java, so I think it will still be a worthwhile learning experience.