GIDForums  

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 31-Oct-2007, 22:10
Louis11 Louis11 is offline
New Member
 
Join Date: Oct 2007
Posts: 6
Louis11 is on a distinguished road
Unhappy

FLTK - Can't fill in my star . . .


I am writing a program to draw a star to the screen. I have done this successfully, and can run my code which produces a red star. As per my lab instructions (this is a school assignment) I am supposed to fill the star in. I figured, as my teacher informed me, that I could simply stick the code in a loop altering the size of the star until I get a completely filled star.

Below is my working star code, please bare in mind that many of the header files included where provided by my teacher for "simplicity" and I am required to use them. I don't believe the problem is here, but rather occurs when I try and reuse the same "Points" and "Lines":
CPP / C++ / C Code:
#include "Window.h"

#include "Graph.h"

#include "GUI.h"

#include "Simple_window.h"



#define PI 3.1459



using namespace Graph_lib;



int main(){

	Simple_window win(Point(100,100),600,400,"Olympic");



	int radius = 100;

	int origin = 500;

	

	// if you remove the stupid

	// for loop the thing draws a star. As soon as you put the code in any sort of loop

	// it goes crazy . . . what's the deal?

	

	// for(int i=0; i<=1; i++){

	Point one   = Point(-1*(radius * cos(PI/2))+origin, -1*(radius * sin(PI/2))+origin);

	Point two   = Point(-1*(radius * cos((5*PI)/6))+origin, -1*(radius * sin((5*PI)/6))+origin);

	Point three = Point(-1*(radius * cos((5*PI)/4))+origin, -1*(radius * sin((5*PI)/4))+origin);

	Point four  = Point(-1*(radius * cos((7*PI)/4))+origin, -1*(radius * sin((7*PI)/4))+origin);

	Point five  = Point(-1*(radius * cos(PI/6))+origin, -1*(radius * sin(PI/6))+origin);



	Line l1(one,three);

	l1.set_color(Color::red);

	l1.set_style(Line_style(Line_style::solid,2));

	win.attach(l1);

	

	Line l2(three,five);

	l2.set_color(Color::red);

	l2.set_style(Line_style(Line_style::solid,2));

	win.attach(l2);

	

	Line l3(five,two);

	l3.set_color(Color::red);

	l3.set_style(Line_style(Line_style::solid,2));

	win.attach(l3);

	

	Line l4(two,four);

	l4.set_color(Color::red);

	l4.set_style(Line_style(Line_style::solid,2));

	win.attach(l4);

	

	Line l5(four,one);

	l5.set_color(Color::red);

	l5.set_style(Line_style(Line_style::solid,2));

	win.attach(l5);

	// }

	

	win.wait_for_button();

}

Any ideas as to why simply placing this code in a loop doesnt work? When out of a loop it produces a star, when inside the loop it produces a small scribble in the top left corner.

Any help would be greatly appreciated!
  #2  
Old 31-Oct-2007, 22:57
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough

Re: FLTK - Can't fill in my star . . .


Is it possible for you to post the included files here? Without them, you can't really expect to get any useful help with the FLTK code.

I'll venture a guess that you will want to explore the drawing functions that can be found in the documentation under, oddly enough, Function Reference - Drawing Functions.

Also, take a look at the arc example in the test dir for complex drawing.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #3  
Old 31-Oct-2007, 23:14
Louis11 Louis11 is offline
New Member
 
Join Date: Oct 2007
Posts: 6
Louis11 is on a distinguished road

Re: FLTK - Can't fill in my star . . .


All of the included files can be found at: courses.cs.tamu.edu/daugher/cpsc121/07fall/

Under the "Code" section on the right hand side of the page. Sorry I tried to post direct links to the source but the ending directories got stripped off. All except Samle_main3.cpp are needed.

There are quite a few. And several (the .cpp files) must be compiled along with star.cpp (the first posted source code)

My problem doesn't reside in any of those files. I am assuming it has to do with the scope of the loop the encompasses the actual code that produces the star.

Basically what I want to do is draw a small star, then a larger one, then a larger . . . until I have a star of desired size that is filled in (by all the smaller stars).

I assumed that once I got the code working to draw the star I could simply throw it in a for loop and change the "radius" variable (this is the radius of my unit circle . . . ) and it would produce a smaller star. But, as soon as the previously posted code is placed in a loop it goes crazy producing a tiny scribble in the top left corner.

Even when I set the loop to go through only once, or just set it in an if statement that's set to true it does the same thing.
  #4  
Old 01-Nov-2007, 05:01
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough

Re: FLTK - Can't fill in my star . . .


If I can make some time I'll try this out later.
For anyone else,

http://courses.cs.tamu.edu/daugher/cpsc121/07fall/

Louis, your links will eventually show up when you get enough posts.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #5  
Old 01-Nov-2007, 09:31
bluekid bluekid is offline
Junior Member
 
Join Date: Apr 2006
Posts: 43
bluekid will become famous soon enough

Re: FLTK - Can't fill in my star . . .


try
Fl::redraw();
within the loop
to fill star you must be decrease a radius and draw
  #6  
Old 01-Nov-2007, 13:46
Louis11 Louis11 is offline
New Member
 
Join Date: Oct 2007
Posts: 6
Louis11 is on a distinguished road

Re: FLTK - Can't fill in my star . . .


Quote:
Originally Posted by bluekid
try
Fl::redraw();
within the loop
to fill star you must be decrease a radius and draw

I have tried implementing the redraw on the line(s). But unfortunately this is not supported by Graph.h (the header file provided by my professor . . .). Is there any way to call it anyway? Or is there another way to correct my problem?

Here is what happens when the program is run. The top window shown in the image is the code outside of a for loop, the bottom is the code inside of a for loop:

CPP / C++ / C Code:
for(int radius=75; radius<=75; radius++){
... code here ...
}



Just produces crazy lines. Regardless of the loop, it does the same thing.

Thanks
  #7  
Old 01-Nov-2007, 18:12
Louis11 Louis11 is offline
New Member
 
Join Date: Oct 2007
Posts: 6
Louis11 is on a distinguished road

Re: FLTK - Can't fill in my star . . .


Figured it out. It was a scope problem :-) Thanks for the help!
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB 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
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 15:41
Re: Derived FLTK Classes cable_guy_67 FLTK Forum 0 26-Jun-2005 20:07
FLTK with GLUT usmsci FLTK Forum 4 26-Nov-2004 16:21
fltk and ncurses podarok FLTK Forum 2 08-Nov-2004 07:45
Welcome to the FLTK Forums dsmith FLTK Forum 0 08-Sep-2004 06:58

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:53.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.