Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 15th, 2006, 8:45 PM   #1
dark_omen
Hobbyist Programmer
 
Join Date: Dec 2004
Posts: 125
Rep Power: 4 dark_omen is on a distinguished road
Send a message via AIM to dark_omen
seirpinski's triangle help

OK so I have to make sierpinski's triangle recursively. I have most of it done, but for some reason it just shows the top and right triangle subdivisions.
Here is what I have:
public void Serpinski (int depth, int level, int x[], int y[], int num_points){
  		if(depth == level){//base case: if the depth equals the level then draw the triangle
  			g_parent.fillPolygon(x, y, num_points);
  			g_parent.setColor(Color.GREEN);
  		}
  		else{//recursive case
  			depth++;
  			//compute center of the sides the sides
  			//centers of x co-ordinates
  			int x0 = (x[0] + x[1])/2;
  			int x1 = (x[0] + x[2])/2;
  			int x2 = (x[1] + x[2])/2;
  			//centers of y co-ordinates
  			int y0 = (y[0] + y[1])/2;
  			int y1 = (y[0] + y[2])/2;
  			int y2 = (y[1] + y[2])/2;
  		    //then create new x and y arrays with new points, and solve recursively
  			//need three recursive calls because you then divide the triangle into three more triangles
  			int[] newX0 = {x[0], x0, x1};
  			int[] newY0 = {y[0], y0, y1};
  			Serpinski(depth, level, newX0, newY0, num_points);
  			
  			int[] newX1 = {x[1], x0, x2};
  			int[] newY1 = {y[1], y0, y2};
  			Serpinski(depth, level, newX1, newY1, num_points);
  			
  			int[] newX2 = {x[2], x1, x2};
  			int[] newY2 = {y[2], y1, y2};
  			Serpinski(depth, level, newX2, newY2, num_points);
  		}
   	}
dark_omen is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Troules with a triangle? ( how good is my code so far?) haniunited C 1 Nov 9th, 2005 12:28 PM
Help with pascal's triangle dark_omen Java 3 Nov 6th, 2005 9:10 PM
Triangle Output JavaBeginner Java 5 Sep 13th, 2005 11:41 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:16 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC