I have been working on a image generation script that uses the chaos game. I have run into some issues regarding generating a set of coordinates for a regular n-gon from a width and height of an image coupled with the number of vertices. I have a solution that unfortunately does not work, it will make a irregular triangle or an irregular pentagon, but nothing else I have tried has worked at all. I am looking for help in getting it to run properly. When completed it will save and spit out an image with a preset number of points plotted based on the factor and number of vertices that have also been predefined. If anyone can help with this, please let me know.

Thanks
Given vertex/side count n, image height im_y, image width im_x, and polygon radius from center to vertices r, in other words inscribed in a circle of radius r:


Code:
im = imagecreate($im_x,$im_y);
$color_k  = imagecolorallocate($im,0,0,0);
$d_theta = (2*pi)/$n;
for($theta=0;$theta<2*pi;$theta+=$d_theta)
imageline($im,$im_x/2+$r*cos($theta),$im_y/2-$r*sin($theta),$im_x/2+$r*cos($theta+$d_theta),$im_y/2-$r*sin($theta+$d_theta),$color_k);
Thanks Kerm, the code I had to do somthing very similar to that was 69 lines or so, and was much more complex, I will adapt this to fit the program (this stage of the program there is no image yet [and the later stages need the coordinates]). Thanks again Kerm.
Glenn wrote:
Thanks Kerm, the code I had to do somthing very similar to that was 69 lines or so, and was much more complex, I will adapt this to fit the program (this stage of the program there is no image yet [and the later stages need the coordinates]). Thanks again Kerm.
No problem, glad the code worked for you. Smile
I have now adapted the code into the program. A final version will be done soon, if anyone wants the code I can post it. The final version will include a form so they can specify the parameters, or if they don't it will give a generic image based on the settings in one of the files.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement