
-----------------------------------
sammi
Thu Oct 20, 2011 7:00 pm

Making moons orbit my planet
-----------------------------------
What is it you are trying to achieve?



What is the problem you are having?



Describe what you have tried to solve this problem



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)




View.Set ("graphics,offscreenonly")
var x, y : int
x := maxx div 2
y := maxy div 2

%%%% PLANETS %%%%%
var xDistMerc, yDistMerc : real % width/height of Mercury
var distanceMerc : int := 70 %
var angleMerc : int := 80 % where the mercury goes around the sun
var hypMerc : int := 30
var xDistVenus, yDistVenus : real % Venus width/height
var angleVenus : int := 20
var distanceVenus : int := 90
var xDistEarth, yDistEarth : real % Earth width/height
var angleEarth := 40
var distanceEarth := 110


%%%%% MOONS %%%%%
var yDistMercMoon, xDistMercMoon : real
var distanceMercMoon : int := 10
var angleMercMoon : int := 20
var hypMercMoon : int := 30

var keys : array char of boolean

loop
    Input.KeyDown (keys)

    if keys ('a') = true then     % move both planets left
        x := x - 1
    end if

    if keys ('d') = true then % move both planets right
        x := x + 1
    end if

    if keys ('s') = true then % move both planets down
        y := y - 1
    end if

    if keys ('w') then % move both planets up
        y := y + 1
    end if

    angleMerc := angleMerc + 1
    angleVenus := angleVenus + 1
    angleEarth := angleEarth + 1
    angleMercMoon := angleMercMoon + 1
    
    % PLANET trig calculations
    xDistMerc := cosd (angleMerc) * distanceMerc % mercury
    yDistMerc := sind (angleMerc) * distanceMerc
    xDistVenus := cosd (angleVenus) * distanceVenus
    yDistVenus := sind (angleVenus) * distanceVenus
    xDistEarth := cosd (angleEarth) * distanceEarth
    yDistEarth := sind (angleEarth) * distanceEarth

    %MOON trig calculations
    xDistMercMoon := cosd (angleMercMoon) * distanceMercMoon
    yDistMercMoon := sind (angleMercMoon) * distanceMercMoon
    
    %%%%% PLANETS %%%%%
    Draw.FillOval (x, y, 40, 40, 43) %sun
    Draw.FillOval (round (x + xDistVenus), round (y + yDistVenus), 8, 8, 41) % Mercury
    Draw.FillOval (round (x + xDistMerc), round (y + yDistMerc), 8, 8, 26) % Venus
    Draw.FillOval (round (x + xDistEarth), round (y + yDistEarth), 8, 8, 104) % Earth
    
    %%%%% MOONS %%%%%
    Draw.FillOval (round (x + xDistMerc), round (y+ yDistMerc), 2, 2, 41) 

    View.Update ()
    delay (15)
    cls ()
end loop




Please specify what version of Turing you are using


-----------------------------------
Raknarg
Thu Oct 20, 2011 7:24 pm

RE:Making moons orbit my planet
-----------------------------------
You're using DistMerc for your moon and mercury. They're in the same spot.

-----------------------------------
sammi
Thu Oct 20, 2011 7:28 pm

RE:Making moons orbit my planet
-----------------------------------
kay i figured that out now i just need it to orbit the gray planet

-----------------------------------
Aange10
Thu Oct 20, 2011 7:57 pm

Re: RE:Making moons orbit my planet
-----------------------------------
kay i figured that out now i just need it to orbit the gray planet

How would you go about making it orbit the grey planet? When do you want it to orbit the planet and not the orange dot? If it's distance is within 10 pixles? How would you go about telling the computer what you want it to do?

-----------------------------------
sammi
Thu Oct 20, 2011 7:59 pm

Re: RE:Making moons orbit my planet
-----------------------------------
kay i figured that out now i just need it to orbit the gray planet

How would you go about making it orbit the grey planet? When do you want it to orbit the planet and not the orange dot? If it's distance is within 10 pixles? How would you go about telling the computer what you want it to do?

sorry not understanding what you mean.......

-----------------------------------
Raknarg
Thu Oct 20, 2011 8:06 pm

RE:Making moons orbit my planet
-----------------------------------
Well, basically you're setting the distance relative to the planet like the planet is to the sun. The distance away is the distance of the planet away from the sun, plus its own distance away from that planet.

-----------------------------------
Beastinonyou
Thu Oct 20, 2011 9:49 pm

Re: Making moons orbit my planet
-----------------------------------

sorry not understanding what you mean.......


He's simply phrasing it in a way that tries to make you figure it out by yourself. It's always better to attempt things by yourself for awhile before posting for help.


After looking at your code, it seems that you are orbiting the Moon around the Sun in the same position as Mercury, which is why the Moon is on Mercury.

If you take a look at your code, you have this: 


%%%%% MOONS %%%%% 
Draw.FillOval (round (x + xDistMerc), round (y+ yDistMerc), 2, 2, 41) 


That is basically drawing your Moon at the same spot Mercury is orbiting the sun at. (You have found this error)

If you look below, technically, it should be this, to be correct in terms of drawing the moon

%%%%% MOONS %%%%%
Draw.FillOval (round(x + xDistMercMoon), round (y + yDistMercMoon), 2, 2, 41)


However, If you run that line, you get the Moon orbiting around the very center of the Sun, Now being Inside the Sun.

If you modify that line a bit more, you get this:


Draw.FillOval (round ((x + xDistMercMoon) + xDistMerc), round ((y + yDistMercMoon) + yDistMerc), 2, 2, 41)


When you run that line into your program, Although it Appears to be orbiting your planet, it Really just orbiting the sun, directly behind Mercury.


Finally, If you make some further modifications to your program, you can end up with this:


View.Set ("graphics,offscreenonly")
var x, y, xMerc, yMerc : int
x := maxx div 2
y := maxy div 2

%%%% PLANETS %%%%%
var xDistMerc, yDistMerc : real % width/height of Mercury
var distanceMerc : int := 70 %
var angleMerc : int := 80 % where the mercury goes around the sun
var hypMerc : int := 30
var xDistVenus, yDistVenus : real % Venus width/height
var angleVenus : int := 20
var distanceVenus : int := 90
var xDistEarth, yDistEarth : real % Earth width/height
var angleEarth := 40
var distanceEarth := 110


%%%%% MOONS %%%%%
var yDistMercMoon, xDistMercMoon : real
var distanceMercMoon : int := 20
var angleMercMoon : int := 20
var hypMercMoon : int := 30

var keys : array char of boolean

loop
    Input.KeyDown (keys)

    if keys ('a') = true then     % move both planets left
        x := x - 1
    end if

    if keys ('d') = true then % move both planets right
        x := x + 1
    end if

    if keys ('s') = true then % move both planets down
        y := y - 1
    end if

    if keys ('w') then % move both planets up
        y := y + 1
    end if

    angleMerc := angleMerc + 1
    angleVenus := angleVenus + 1
    angleEarth := angleEarth + 1
    angleMercMoon := angleMercMoon + 1

    % PLANET trig calculations
    xDistMerc := cosd (angleMerc) * distanceMerc % mercury
    yDistMerc := sind (angleMerc) * distanceMerc
    xDistVenus := cosd (angleVenus) * distanceVenus
    yDistVenus := sind (angleVenus) * distanceVenus
    xDistEarth := cosd (angleEarth) * distanceEarth
    yDistEarth := sind (angleEarth) * distanceEarth

    xMerc := round(x + xDistMerc) % The X-Coordinate of Mercury (Center) as it Orbits the Sun
    yMerc := round(y + yDistMerc) % The Y-Coordinate of Mercury (Center) as it Orbits the Sun

    %MOON trig calculations
    % Add angle of Mercury to Sun + angle of Mercury to Moon, Multiplied by Distance of Mercury to Moon 
    xDistMercMoon := cosd (angleMercMoon + angleMerc) * distanceMercMoon
    % Same as Above, but for Y-Coordinate
    yDistMercMoon := sind (angleMercMoon + angleMerc) * distanceMercMoon

    %%%%% PLANETS %%%%%
    Draw.FillOval (x, y, 40, 40, 43) %sun
    Draw.FillOval (round (x + xDistVenus), round (y + yDistVenus), 8, 8, 41) % Mercury
    Draw.FillOval (round (x + xDistMerc), round (y + yDistMerc), 8, 8, 26) % Venus
    Draw.FillOval (round (x + xDistEarth), round (y + yDistEarth), 8, 8, blue) % Earth

    %%%%% MOONS %%%%%
    % for X-Coordinate of Moon, Add the X-Value from the center of Mercury + (x) Moon Distance from Mercury
    % for Y-Coordinate of Moon, Add the Y-Value from the center of Mercury + (y) Moon Distance from Mercury
    Draw.FillOval (round (xMerc + xDistMercMoon), round ((yMerc + yDistMercMoon)), 2, 2, 41)

    View.Update ()
    delay (15)
    cls ()
end loop


Notice my Changes? I'll Point them out:


var xMerc, yMerc : int


xMerc := x + xDistMerc % The X-Coordinate of Mercury (Center) as it Orbits the Sun
yMerc := y + yDistMerc % The Y-Coordinate of Mercury (Center) as it Orbits the Sun


%MOON trig calculations
% Add angle of Mercury to Sun + angle of Mercury to Moon, Multiplied by Distance of Mercury to Moon 
xDistMercMoon := cosd (angleMercMoon + angleMerc) * distanceMercMoon
% Same as Above, but for Y-Coordinate
yDistMercMoon := sind (angleMercMoon + angleMerc) * distanceMercMoon


% And Lastly,

    %%%%% MOONS %%%%%
    % for X-Coordinate of Moon, Add the X-Value from the center of Mercury + (x) Moon Distance from Mercury
    % for Y-Coordinate of Moon, Add the Y-Value from the center of Mercury + (y) Moon Distance from Mercury
    Draw.FillOval (round (xMerc + xDistMercMoon), round ((yMerc + yDistMercMoon)), 2, 2, 41)


If you have any questions, let me know. It took me awhile to properly get it, but hey, No school tomorrow, so extra programming time for me =P

-----------------------------------
sammi
Sat Oct 22, 2011 12:22 pm

RE:Making moons orbit my planet
-----------------------------------
i have another problem........but before i post my code what do i have to put in front of it to make it look like the code above? i cant remember....

-----------------------------------
Zren
Sat Oct 22, 2011 1:08 pm

RE:Making moons orbit my planet
-----------------------------------



[/code]

-----------------------------------
sammi
Sun Oct 23, 2011 1:46 pm

RE:Making moons orbit my planet
-----------------------------------
whats the command for importing a picture? I want a picture of a spaceship to zoom through underneath my solar system.

 
View.Set ("graphics,offscreenonly")
var x, y : int
x := maxx div 2
y := maxy div 2


%%%% PLANETS %%%%%
var xDistMerc, yDistMerc : real % Mercury
var distanceMerc : int := 70 % How far from the sun it is
var angleMerc : int := 80 % where the mercury goes around the sun

var xDistVenus, yDistVenus : real % Venus
var angleVenus : int := 20
var distanceVenus : int := 100 

var xDistEarth, yDistEarth : real % Earth 
var angleEarth := 260
var distanceEarth := 110

var xDistMars, yDistMars : real % Mars
var angleMars := 170
var distanceMars := 150

%%%%% MOONS %%%%%
var yDistMercMoon, xDistMercMoon : real
var distanceMercMoon : int := 20
var angleMercMoon : int := 20
var hypMercMoon : int := 30

var yDistVenusMoon1, xDistVenusMoon1 : real
var distanceVenusMoon1 : int := 20
var angleVenusMoon1 : int := 20
var hypVenusMoon1 : int := 30
var yDistVenusMoon2, xDistVenusMoon2 : real
var distanceVenusMoon2 : int := 20
var angleVenusMoon2 : int := 90
var hypVenusMoon2 : int := 30


var yDistEarthMoon, xDistEarthMoon : real
var distanceEarthMoon : int := 20
var angleEarthMoon : int := 20
var hypEarthMoon : int := 30

var yDistMarsMoon1, xDistMarsMoon1 : real
var distanceMarsMoon1 : int := 30
var angleMarsMoon1 : int := 100
var hypMarsMoon1 : int := 30

var yDistMarsMoon2, xDistMarsMoon2 : real
var distanceMarsMoon2 : int := 20
var angleMarsMoon2 : int := 20
var hypMarsMoon2 : int := 30

var yDistMarsMoon3, xDistMarsMoon3 : real
var distanceMarsMoon3 : int := 40
var angleMarsMoon3 : int := 150
var hypMarsMoon3 : int := 30

var keys : array char of boolean

loop
    angleMerc := angleMerc + 1
    angleVenus := angleVenus + 1
    angleEarth := angleEarth + 1
    angleMars := angleMars + 1
    angleMercMoon := angleMercMoon + 3
    angleVenusMoon1 := angleVenusMoon1 + 2
    angleVenusMoon2 := angleVenusMoon2 + 2
    angleEarthMoon := angleEarthMoon + 4
    angleMarsMoon1 := angleMarsMoon1 + 2
    angleMarsMoon2 := angleMarsMoon2 + 2
    angleMarsMoon3 := angleMarsMoon3 + 2
    
    % PLANET trig calculations
    xDistMerc := cosd (angleMerc) * distanceMerc % mercury
    yDistMerc := sind (angleMerc) * distanceMerc
    
    xDistVenus := cosd (angleVenus) * distanceVenus % Venus
    yDistVenus := sind (angleVenus) * distanceVenus
    
    xDistEarth := cosd (angleEarth) * distanceEarth% Earth
    yDistEarth := sind (angleEarth) * distanceEarth
    
    xDistMars := cosd (angleMars) * distanceMars %Mars
    yDistMars := sind (angleMars) * distanceMars
    
    %MOON trig calculations
    xDistMercMoon := cosd (angleMercMoon) * distanceMercMoon
    yDistMercMoon := sind (angleMercMoon) * distanceMercMoon
    
    xDistVenusMoon1 := cosd (angleVenusMoon1) * distanceVenusMoon1
    yDistVenusMoon1 := sind (angleVenusMoon1) * distanceVenusMoon1
    xDistVenusMoon2 := cosd (angleVenusMoon2) * distanceVenusMoon2
    yDistVenusMoon2 := sind (angleVenusMoon2) * distanceVenusMoon2
    
    xDistEarthMoon := cosd (angleEarthMoon) * distanceEarthMoon 
    yDistEarthMoon := sind (angleEarthMoon) * distanceEarthMoon
    
    xDistMarsMoon1 := cosd (angleMarsMoon1) * distanceMarsMoon1
    yDistMarsMoon1 := sind (angleMarsMoon1) * distanceMarsMoon1
    xDistMarsMoon2 := cosd (angleMarsMoon2) * distanceMarsMoon2
    yDistMarsMoon2 := sind (angleMarsMoon2) * distanceMarsMoon2
    xDistMarsMoon3 := cosd (angleMarsMoon3) * distanceMarsMoon3
    yDistMarsMoon3 := sind (angleMarsMoon3) * distanceMarsMoon3
    
    %%%% BACKROUND %%%%
    Draw.Fill (maxx, 100, black, black) % BLACK SKY
    Draw.FillStar (150,150, 200, 200, yellow)
    Draw.FillStar (150,310, 200, 350, yellow)
    Draw.FillStar (350,110, 400, 150, yellow)
    Draw.FillStar (450,210, 500, 250, yellow)
    
    %%%%% PLANETS %%%%%
    Draw.FillOval (x, y, 40, 40, 43) %sun
    Draw.FillOval (round (x + xDistVenus), round (y + yDistVenus), 8, 8, 41) % Venus
    Draw.FillOval (round (x + xDistMerc), round (y + yDistMerc), 8, 8, 26) % Mercury
    Draw.FillOval (round (x + xDistEarth), round (y + yDistEarth), 8, 8, 104) % Earth
    Draw.FillOval (round (x + xDistMars), round (y + yDistMars), 8, 8, 104) % Mars
    
    %%%%% MOONS %%%%%
    Draw.FillOval (round (x + xDistMerc + xDistMercMoon), round (y + yDistMerc + yDistMercMoon), 2, 2, 41)
    
    Draw.FillOval (round (x + xDistVenus + xDistVenusMoon1), round (y + yDistVenus + yDistVenusMoon1), 2, 2, 50)
    Draw.FillOval (round (x + xDistVenus + xDistVenusMoon2), round (y + yDistVenus + yDistVenusMoon2), 2, 2, 50)
    
    Draw.FillOval (round (x + xDistEarth + xDistEarthMoon), round (y + yDistEarth + yDistEarthMoon), 2, 2, 50)
    
    Draw.FillOval (round (x + xDistMars + xDistMarsMoon1), round (y + yDistMars + yDistMarsMoon1), 2, 2, 50)
    Draw.FillOval (round (x + xDistMars + xDistMarsMoon2), round (y + yDistMars + yDistMarsMoon2), 2, 2, 50)
    Draw.FillOval (round (x + xDistMars + xDistMarsMoon3), round (y + yDistMars + yDistMarsMoon3), 2, 2, 50)
    
    
    View.Update ()
    delay (15)
    cls ()
end loop


-----------------------------------
Beastinonyou
Sun Oct 23, 2011 2:25 pm

Re: Making moons orbit my planet
-----------------------------------

whats the command for importing a picture? I want a picture of a spaceship to zoom through underneath my solar system.


I see you've took my example of the moons orbiting, and done it to the other planets. 

What you're looking for would be this:


var spaceShip : int := Pic.FileNew ("PictureName.bmp") % Pictures may be of .jpg or .bmp


To move it, you could just make a variable, shipX, and increment its value each time you go through the loop, then draw the picture at that x-value. 

Example:


drawfillbox (100, 100, 110, 110, black) % pretend this is my spaceShip

var spaceShip : int := Pic.New (100, 100, 110, 110) % With a picture file, use Pic.FileNew ("") instead
var shipY : int := 100
var shipX : int := 0

View.Set ("offscreenonly")
loop
     shipX += 1
     Pic.Draw (spaceShip, shipX, shipY, picMerge)
     delay (15)
     View.Update
     cls
     exit when shipX = maxx
end loop



Also, I would advise looking into arrays. A lot more organized, with much less var lines.
