My little problem

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Sargent@Eagle
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 9
Joined: Fri Apr 24, 2009 11:30 am
Location: croatia

My little problem

Post by Sargent@Eagle »

Ok sorry to bother you but right now I'm really angry cause I don't have any idea how to go further with this program

I believe that for you it's a piece of cake, and for me it's first step into programing at my own
This is my first program well he's not yet finished but it's the first that i have created on my own.

I want to create something like this http://www.walter-fendt.de/ph14cr/interference_cr.htm

Code: Select all

#include <cstdlib>
#include <iostream>
#include <winbgim.h>

using namespace std;

int main(int argc, char *argv[])
{
    
    system("TITLE INTERFERENCIJA DVAJU VALOVA");
    
    int gdriver=9, gmode=2,y,k,udaljenost,t,f,x;
    char odgovor='d';
    initgraph(&gdriver,&gmode,"");
    setbkcolor(WHITE);
    setcolor(BLACK);
        cleardevice();
        
do
   {
 
     cout<<"unesite udaljenost izmedu sredista krugova A i B"<<endl;    //this is a difference between A pixel and B pixel, the centers of circles  
    
cin>>udaljenost;

     f=udaljenost/2;              
     y=320-f;
     k=320+f;
    
     cout<<"unesite brojku u milisekundama za brzinu izovedenja"<<endl;        // enter the number (milliseconds) for speed of circles
     cout<<"standardna brojka je 50 (manje=brze)"<<endl;
     cin>>t;
    
    
 
         for (x=10;x<400;x++)
    {
     
    
       delay(t);


       ___________________________________________
       cleardevice();
       circle(y,240,x);
       circle(k,240,x);
     ______________________________________________
       



       circle(y,240,x-10)
       circle(k,240,x-10);
     
       circle(y,240,x-20);
       circle(k,240,x-20);
       
       circle(y,240,x-30);
       circle(k,240,x-30);
         
       circle(y,240,x-40);
       circle(k,240,x-40);
        
       circle(y,240,x-50);
       circle(k,240,x-50);
         
       circle(y,240,x-60);
       circle(k,240,x-60);
     
       circle(y,240,x-70);
       circle(k,240,x-70);
    
       circle(y,240,x-80);
       circle(k,240,x-80);
      
      
       circle(y,240,x-90);
       circle(k,240,x-90);
       
       circle(y,240,x-100);
       circle(k,240,x-100);
       
       circle(y,240,x-110);
       circle(k,240,x-110);
       
       circle(y,240,x-120);
       circle(k,240,x-120);
       
       circle(y,240,x-130);
       circle(k,240,x-130);
       
       circle(y,240,x-140);
       circle(k,240,x-140);
       
       circle(y,240,x-150);
       circle(k,240,x-150);
       
       circle(y,240,x-160);
       circle(k,240,x-160);
       
       circle(y,240,x-170);
       circle(k,240,x-170);
         
       circle(y,240,x-180);
       circle(k,240,x-180);
        
       circle(y,240,x-190);
       circle(k,240,x-190);
         
       circle(y,240,x-200);
       circle(k,240,x-200);
     
       circle(y,240,x-210);
       circle(k,240,x-210);
    
       circle(y,240,x-220);
       circle(k,240,x-220);
      
      
       circle(y,240,x-230);
       circle(k,240,x-230);
       
       circle(y,240,x-230);
       circle(k,240,x-230);
       
       circle(y,240,x-240);
       circle(k,240,x-240);
       
       circle(y,240,x-250);
       circle(k,240,x-250);
       
       circle(y,240,x-260);
       circle(k,240,x-260);
       
       circle(y,240,x-270);
       circle(k,240,x-270);
       
       circle(y,240,x-280);
       circle(k,240,x-280);
       
       
      
       
       
       
    }

  
cout<<"Zelite il ponoviti animaciju (y,n)?"<<endl;
odgovor=getch();
}
while(odgovor=='y');
closegraph();
    return 0;
}


The separated(________________) part is the problem. They're not supposed to appear when they radius isn't above 0 so that they don't make those stupid black lines.
I have no idea how to make it. So if someone can pls help me.

btw. the instructions are on Croatian so I'll translate them for you, if you need it.
Martyj
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Thu Apr 23, 2009 11:23 am
Location: Ogden Utah
Contact:

Re: My little problem

Post by Martyj »

You would use java for it. Not C or C++ whatever language that is. Well that's if you wanted to do it for a web app.
User avatar
Sargent@Eagle
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 9
Joined: Fri Apr 24, 2009 11:30 am
Location: croatia

Re: My little problem

Post by Sargent@Eagle »

it doesn't has to be on net...

the link above is just a concept how i would like it to look ...
User avatar
Sargent@Eagle
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 9
Joined: Fri Apr 24, 2009 11:30 am
Location: croatia

Re: My little problem

Post by Sargent@Eagle »

I've tried by puting

if how do you call say it on english function in front of every circle

like:


for (x=0;x<400;x++);
{
if (x<10)
{
circle(x,y,r);
}

for instance, but it didn't work it showed me only first circle, he moved well till the end of screen but the other 30 weren't moving

not sure what's the problem and how to deal this then :worship:
User avatar
hellknight
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 37
Joined: Fri Apr 24, 2009 2:54 am
Current Project: Non
Favorite Gaming Platforms: Pc, NES, PS1, PS2, xBOX
Programming Language of Choice: c,c++,c#,JS, haskell
Location: India

Re: My little problem

Post by hellknight »

turned out i didnt had <winbgim.h>.......so i couldnt compiled ur code.
i on the other hand created a simple Young's double slit using OpenGL,try this out.
(Dont bother about GLutFunction calls...just check the interference function.) i hope it helps. :P

Code: Select all

#include<windows.h>
#include<math.h>
#include<gl/gl.h>
#include<gl/glu.h>
#include <GL/glut.h>

int  VPx=100;//viewport x
int  VPy=100;//viewport y
static int r;//this will help in draw the circle later

//----creats a circle-------the hard way-------lol
//--not the very perfact circle as we get from bressehem,yet :P
void circle(int x,int y,int radius)
{
     //--these values caluculate the circles point by polar co-ordinates
     //----(x,y)-->(rcos(theta),rsin(theta)
     //---making the circle perform large caliculation effectively controls the fram rate
     //----adjust the incremental value of the i to adjust framerate
     for(float i=0.0f;i<2*3.1415;i+=0.002f)
     {
                glBegin(GL_POINTS);
                glVertex2f(x+radius*cos(i),y+radius*sin(i));
                glEnd();
                }
 }
//-------interference function creator----

void Interference(int slit1x,int slit1y,int slit2x,int slit2y)
{
     //---draw the source points
     glPointSize(8.0f);
     glBegin(GL_POINTS);
         glColor3f(1.0f,0.0f,0.0f);
         glVertex2i(slit1x,slit1y);
         glColor3f(0.0f,0.0f,1.0f);
         glVertex2i(slit2x,slit2y);
     glEnd();
     //---draw the circles
     glPointSize(1.0f);
     glColor3f(0.0f,1.0f,0.0f);
    for(int j=0;j<70;j+=3)
    {
             circle(slit1x,slit1y,r+j);
             circle(slit2x,slit2y,r+j);
             }
      
     r+=3;
     if(r>150)
     {
             r=0;
             }
 }



void display(void)
{
    
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0f,1.0f,0.0f);
    Interference(15,0,-15,0);
    //glFlush();
    
    glutSwapBuffers();
    glutPostRedisplay();
    
}

void resh(int x,int y)
{
     GLfloat aspectRatio;
// Prevent a divide by zero
   if(y == 0)
        y = 1;
// Set Viewport to window dimensions
   glViewport(0, 0, x, y);
// Reset coordinate system
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   aspectRatio = (GLfloat)x / (GLfloat)y;
   if (x <= y)
   {
      glOrtho (-VPx, VPx, - VPy/ aspectRatio, VPy/ aspectRatio,1.0, -1.0);
      }
   else
   {
       glOrtho (-VPx * aspectRatio, VPx * aspectRatio,-VPy, VPy, 1.0, -1.0);
       }
       
       glMatrixMode(GL_MODELVIEW);
       glLoadIdentity();
 }
 

int 
main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);

    glutCreateWindow("Young's Double slits...yeah baby!!!");
    glutDisplayFunc(display);
    glutReshapeFunc(resh);
    glClearColor(0,0,0,1);

    glutMainLoop();

    return 0;
}
Dont Mind the typos...i m too lazy to correct them. :P
User avatar
Sargent@Eagle
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 9
Joined: Fri Apr 24, 2009 11:30 am
Location: croatia

Re: My little problem

Post by Sargent@Eagle »

hmmmmm can't compile this program

I have downloaded some GL libraries but still it doesn't work
can you give me link to download libraries so i can compile this

I'm using dev c++ 4.9.9.2 version
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: My little problem

Post by MarauderIIC »

they're not supposed to appear when they radius isn't above 0 so that they don't make those stupid black lines.
Do you mean they are not supposed to appear when the radius is below 0?

So can you do something like

Code: Select all

if (radius >= 0) {
    do the stuff you had
}
?

Sorry if that's not at all what you meant, I'm just basing the possible solution off of that one sentence since I only had a couple minutes to look :)
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Sargent@Eagle
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 9
Joined: Fri Apr 24, 2009 11:30 am
Location: croatia

Re: My little problem

Post by Sargent@Eagle »

I've puted this form in but then it only shows first circle

I'll do it all over again tomorrow
User avatar
hellknight
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 37
Joined: Fri Apr 24, 2009 2:54 am
Current Project: Non
Favorite Gaming Platforms: Pc, NES, PS1, PS2, xBOX
Programming Language of Choice: c,c++,c#,JS, haskell
Location: India

Re: My little problem

Post by hellknight »

Sargent@Eagle wrote:hmmmmm can't compile this program

I have downloaded some GL libraries but still it doesn't work
can you give me link to download libraries so i can compile this

I'm using dev c++ 4.9.9.2 version
goto Tools->check for updates/package------choose devpak from drop down menu-->in groups select OpenGL--->check for Glut (from available package list).
download that.
this will create a template in ur Dev C++ for Glut. use that template and run Glut program,thats it :D.
Dont Mind the typos...i m too lazy to correct them. :P
User avatar
Sargent@Eagle
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 9
Joined: Fri Apr 24, 2009 11:30 am
Location: croatia

Re: My little problem

Post by Sargent@Eagle »

all done now :)

tnx for your replies ,..
Post Reply