Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 i need help making a picture move
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mattsyv




PostPosted: Thu Jan 19, 2006 6:59 pm   Post subject: i need help making a picture move

i have made a animaion and i need help with making the little gree fish to move across the screenjust back and forth here are the codes for my animation
code:

setscreen ("graphics:640,480")
%writing
colorback (black)
color(white)
cls
put"M"..
delay(100)
put"a"..
delay(100)
put"d"..
delay(100)
put"e "..
delay(100)
put"B"..
delay(100)
put"y "..
delay(100)
put"M"..
delay(100)
put"a"..
delay(100)
put"t"..
delay(100)
put"t"..
delay(100)
put"h"..
delay(100)
put"e"..
delay(100)
put"w "..
delay(100)
put"S"..
delay(100)
put"y"..
delay(100)
put"v"..
delay(100)
put"r"..
delay(100)
put"e"..
delay(100)
put"t"..
delay(2000)
%backround
drawfillbox (0, 0, 640, 480, black)
%boatsail
Draw.ThickLine (340, 240, 340, 480, 5,white)
drawline (170, 360, 340, 360, white)
drawline (170, 360, 340, 480, white)
drawfill (300, 400, white, white)
%boat
drawline (0, 240, 640, 240, red)
drawline (0, 240, 170, 120, red)
drawline (170, 120, 510, 120, red)
drawline (510, 120, 640, 240, red)
drawfill (500, 200, red, red)
%ocean
drawfillbox (0, 0, 640, 130, blue)
%ocean waves
drawfilloval (0, 0, 170, 170, blue)
drawfilloval (100, 0, 170, 170, blue)
drawfilloval (200, 0, 170, 170, blue)
drawfilloval (300, 0, 170, 170, blue)
drawfilloval (400, 0, 170, 170, blue)
drawfilloval (500, 0, 170, 170, blue)
drawfilloval (600, 0, 170, 170, blue)
drawfilloval (700, 0, 170, 170, blue)
%MR.moon
drawfilloval (630, 450, 70, 70, gray)
%fish
drawfilloval (400, 70, 150, 60, green)
% fish tail
drawline (510, 70, 590, 150, green)
drawline (510, 70, 590, 10, green)
drawline (590, 10, 590, 150, green)
drawfill (580, 130, green, green)
%fish eye
drawfilloval (300, 80, 10, 10, black)
drawfilloval (300, 80, 3, 3, yellow)
%fish bubbles
drawfilloval (240, 125, 5, 5, white)
drawfilloval (240, 105, 5, 5, white)
drawfilloval (240, 85, 5, 5, white)
drawfilloval (245, 75, 3, 3, white)
%fishmouth
drawline (250,60,270,70,blue)
drawline (270,70,250,80,blue)
drawline (250,80,250,60,blue)
drawfill (260,70,blue,blue)
% fire bird
Draw.Arc (550, 400, 50, 20, 90, 180, brightred)
Draw.Arc (549, 400, 50, 20, 90, 180, brightred)
Draw.Arc (548, 400, 50, 20, 90, 180, brightred)
Draw.Arc (547, 400, 50, 20, 90, 180, brightred)
Draw.Arc (450, 400, 50, 20, 0, 90, brightred)
Draw.Arc (449, 400, 50, 20, 0, 90, brightred)
Draw.Arc (448, 400, 50, 20, 0, 90, brightred)
Draw.Arc (447, 400, 50, 20, 0, 90, brightred)
%clouds
drawfilloval (70, 410, 30, 30, darkgray)
drawfilloval (90, 400, 30, 30, darkgray)
drawfilloval (120, 410, 30, 30, darkgray)
%stars
Draw.FillStar (170, 400, 200, 420, yellow)
Draw.FillStar (260, 460, 290, 480, yellow)
Draw.FillStar (400, 300, 430, 320, yellow)
%mapleleaf
Draw.FillMapleLeaf (305,170 ,375 , 230, white)
Draw.FillMapleLeaf (255,370 ,320 , 430, red)
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Thu Jan 19, 2006 7:02 pm   Post subject: (No subject)

You need to use variables. Set the x- and y- coords to whatever position you want, and it a loop of some kind (likely a for loop) increase/decrease them as needed.
Drakain Zeil




PostPosted: Thu Jan 19, 2006 7:30 pm   Post subject: (No subject)

Don't forget about your loops, I see tons of spaces in there that you could cut your lines of code in half with, just from a for loop. ex:

The first part of your code that slowly creeps letters onto the screen:

code:
var text:="BlahBlahBlah"
for i:1..length(text)
put text(i)..
delay (100)
end for
mattsyv




PostPosted: Thu Jan 19, 2006 7:55 pm   Post subject: help

can u show me the variable thing and an how would i set the code
Drakain Zeil




PostPosted: Thu Jan 19, 2006 8:31 pm   Post subject: (No subject)

Another example is your waves, just do this instead:

for i:0..700 by 100
drawfilloval (i, 0, 170, 170, blue)
end for
That's 5 less lines right off the bat...

Anyway, I'm not sure what you mean by the variable thing.
GoVikingsGo




PostPosted: Thu Jan 19, 2006 8:31 pm   Post subject: (No subject)

k mattsyv the dudes above me are very very good while can go to ur level and code it the way u understand it

the easiest way to do thing is to use a for loop

I hope u know what that is....

anyways this is the basic animation

code:

for decreasing x : 600 .. 40
    drawfillbox (x, 200, x, 220, 10)
    delay (5)
end for
for  x : 40 .. 600
    drawfillbox (x, 220, x, 240, 40)
    delay (5)
end for


so basically u adjust the delat based on how fast u want the image to go
and so on so post back if u need more help

peace
Delos




PostPosted: Thu Jan 19, 2006 11:14 pm   Post subject: (No subject)

Ok, we're getting somewhere here.

Let's start by defining what we want to do:
- create an animation of a box that moves from left to right
- it must maintain its shape and colour
- we want the animation to be smooth
- we're not positive exactly where we want to place the box eventually, so we want to be able to change this later as well

1. Preparation and Variables.
We will need a number of variables for this. Most importantly, we'll need to have two to store the location of the box. Note, I'm going to keep this all simple and not try introduce too many complex coding paradigms. There are more efficient ways of doing some of these things, but not worth it for this purpose.

code:

var boxX, boxY : int
% These will be for its location.
var animDelay : int
% This will be used later.


2. Draw The Box.
Ok, so we have things prepared, so let's draw a box. We'll use this same box throughout.

code:

Draw.FillBox (boxX, boxY, boxX + 20, boxY + 20, 7)


Oh no! Something went wrong and the programme crashed. You'll need to initialize those variables first. Do so, and pick whatever location you want.

3. Animate.
The basic idea here is to draw the box, shift it a little, draw it again, and so on; clearing the screen where needed.

code:

Draw.FillBox (boxX, boxY, boxX + 20, boxY + 20, 7)
boxX += 5
% Increase the next x-location by a bit.
cls
Draw.FillBox (boxX, boxY, boxX + 20, boxY + 20, 7)
% Draw the next frame.


Ok, this didn't really work. We barely saw the first box, but we did see the second. We'll need to add some delays. This is where animDelay comes into play. Set it to some value, and insert it where applicable.

After doing this, we still only have two frames. It will also be really tedious trying to draw each frame manually. So, we'll incorporate a loop.

code:

for i : 1..10
   Draw.FillBox (boxX, boxY, boxX + 20, boxY + 20, 7)
   boxX += 1
   delay (animDelay)
   cls
end for


You now get a box slowly (or quickly) shifting right. Play with the delay a bit to get a realistic movement. Also, change the iterations of the for loop from 10 to a higher number to make it go for longer.

4. Onwards.

Where next? Well, you can now start adding more shapes, colours, and such. Keep in mind that one for loop will execute at a time, and you can update the properties of various shapes at a time if you need to.
Once you've done some more animation, you'll realize that your screen flickers a lot. I'll leave you to search up how to fix that - it's a very common problem so there are a lot of Q&As on it.
Also, remember that by changing your variables around, you can change where things start and where they end. Experiment by using more variables for the different parameters that you use in your drawings. You may want to include some randomness to it too - just for fun.
Once you're down with this, extrapolate what you know to your fish. By that time, it will be best for you to start using procedures to streamline how you draw things. Check the [Tuts] for more info.
GoVikingsGo




PostPosted: Fri Jan 20, 2006 10:11 am   Post subject: (No subject)

Okay i think i explained it delos

but anyways matt post here for help so every1 can benefit but if you want the thing to go off the screen then


code:

for decreasing x : 800 .. -200
    drawfillbox (x + 20, 200, x + 20, 220, 0)
    drawfillbox (x, 200, x, 220, 10)
    delay (5)
end for
for x : -200 .. 800
    drawfillbox (x - 20, 220, x - 20, 240, 0)
    drawfillbox (x, 220, x, 240, 40)
    delay (5)
end for


basically you have to draw another box using the back ground color and it has to be x + 20 or x-20 going the other way


if u want if off the screen then just extend the for loop numbers at the top

for decreasing x : 800 .. -200

remember that the screen is 640 by 400

peace

post back for more help
Sponsor
Sponsor
Sponsor
sponsor
mattsyv




PostPosted: Fri Jan 20, 2006 1:28 pm   Post subject: ok kool

i understand
but cant u just do it for me
do_pete




PostPosted: Fri Jan 20, 2006 1:36 pm   Post subject: (No subject)

No. We don't do people's homework.
codemage




PostPosted: Fri Jan 20, 2006 1:38 pm   Post subject: (No subject)

That would suck all the fun out of it.

It's your course. If you understand it now, do it.
mattsyv




PostPosted: Fri Jan 20, 2006 10:05 pm   Post subject: wtf

its not my home work im 35 i just want to have fun and this is just for the hel of it
mattsyv




PostPosted: Fri Jan 20, 2006 10:11 pm   Post subject: man

im lost agian u showed me the code but i need to know what every thingmeans
Delos




PostPosted: Sat Jan 21, 2006 12:15 am   Post subject: Re: wtf

mattsyv wrote:
its not my home work im 35 i just want to have fun and this is just for the hel of it

Eh

mattsyv wrote:
im lost agian u showed me the code but i need to know what every thingmeans

Let's try this again. Read This post. It explains everything quite competely.

[sigh].
You're the only person I've ever known to use the 'Subject' line in posts. Interesting.
Also, 35 year olds do not amuse themselves by learning a programming language whose applicability extends only to a small fraction of Southern Ontario high schools, perhaps a few other places around Canada. You really need a better alibi.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: