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

Username:   Password: 
 RegisterRegister   
 Need a better, shorter version...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TokenHerbz




PostPosted: Sun Sep 25, 2005 12:48 am   Post subject: Need a better, shorter version...

Hey, so in my RPG, to start off the battle scene, i wish to have a pokemon type closer...

The problem, my vertions sloppy, crappy, and i believe extremely unessesary long code...

A) I tryed to use a for inside a for statment to make this easy, but i just suck at thinking, and had problems, so i did it the long way, WHICH is kinda crappy...

B) I ask for you to COPY - PASTE this, and run it, to get an idea of what i want to accomplish, Then i hope you are bored enough to make me a better, shorter verstion, Though if you dont, i would appreciate help on how i can shorted this code...

*********
Here is the CODE
code:

setscreen("Graphics:300;300")

var lx1,lx2,ly1,ly2: int    %%left variable
var tx1,tx2,ty1,ty2: int   %%Top
var rx1,rx2,ry1,ry2: int    %Right
var bx1,bx2,by1,by2: int    %%Bot

%lefts
ly1 := 0
ly2 := 300
lx1:= 0
lx2:= 10
proc left
    drawfillbox(lx1,ly1,lx2,ly2,black)
   % delay(200)
    lx2+= 10
    ly2-= 10
    lx1+= 10
    ly1+= 10   
end left
%tops
ty1 := 300
ty2 := 290
tx1:= 10
tx2:= 290
proc top
    drawfillbox(tx1,ty1,tx2,ty2,yellow)
  %  delay(200)
    tx1+= 10
    tx2-= 10
    ty1-= 10
    ty2-= 10
end top
%%Right
ry1 := 0
ry2 := 300
rx1:= 290
rx2:= 300
proc right
    drawfillbox(rx1,ry1,rx2,ry2,black)
   % delay(200)
    ry1+= 10
    ry2-= 10
    rx1-= 10
    rx2-= 10
end right
%%bottom
by1 := 0
by2 := 20
bx1:= 10
bx2:= 290
proc bottom
    drawfillbox(bx1,by1,bx2,by2,yellow)
  %  delay(200)
    by1+= 10
    by2+= 10
    bx1+= 10
    bx2-= 10
end bottom

loop
    left
    delay(50)
    top
    delay(50)
    right
    delay(50)
    bottom
    delay(50)
    exit when rx2 <= 150
end loop


**Please help me out Smile**

Byes!
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Sun Sep 25, 2005 2:03 am   Post subject: (No subject)

Well, this one won't make it shorter, but for the love of everything holy (or unholy, for that matter) please use more descriptive variable names! Razz

Also:

Turing:
var lx1,lx2,ly1,ly2: int    %%left variable
var tx1,tx2,ty1,ty2: int   %%Top
var rx1,rx2,ry1,ry2: int    %Right
var bx1,bx2,by1,by2: int    %%Bot


One word comes to mind immediately. That word is: record.

I see x and y coordinates.

Turing:
type Point :
   record
      x, y : int
   end record


Then I see two sets of coordinates used together.

Turing:
type Something :
   record
      point1, point2 : Point
   end record
Cervantes




PostPosted: Sun Sep 25, 2005 7:58 am   Post subject: (No subject)

Turing:

View.Set ("graphics:300;300")
assert maxx = maxy
for i : 0 .. maxx div 2 by 10
    for j : i .. maxy - i by 10
        Draw.FillBox (i, j, i + 10, j + 10, black)                  %left
        Draw.FillBox (maxx - i, j, maxx - i - 9, j + 10, black)    %right
        Draw.FillBox (j, i, j + 10, i + 10, yellow)                 %bottom
        Draw.FillBox (j, maxy - i, j + 10, maxy - i + 10, yellow)   %top
    end for
    delay (30)
end for


wtd wrote:

Turing:

type Point :
    record
        x, y : int
    end record


Indeed. I've used coordinate types such so often I just built them right into Turing, and made them pervasive. Now I've got them inside all sorts of built in functions.
code:

Math.Distance (point1, point2)

is a lot more readable than
code:

Math.Distance (x1, y1, x2, y2)
beard0




PostPosted: Sun Sep 25, 2005 11:29 pm   Post subject: (No subject)

Cervantes wrote:
Indeed. I've used coordinate types such so often I just built them right into Turing, and made them pervasive. Now I've got them inside all sorts of built in functions.


Pray tell: how? I would love to do this. Unless you just mean having the same "include" line at the begining of every program...
TokenHerbz




PostPosted: Mon Sep 26, 2005 1:06 am   Post subject: (No subject)

Cervantes your good...

But can you make one where it goes in a patter around?

2nd
--->----->---->|
^ |
1st | \/
^ | 3rd
ex.. | \/
<----<----<----
4th

Alternating in colours, BUT SWITCHING on inners?

So like this

1=black/2=yellow/3=black/4=yellow
then on next inside
1=yellow/2=black/3=yellow/4=black
then on next repeat


i need somthing awsome, for my RPG battle enteries


Infact i welcom all to post you code, ill make it a compitition Smile

though i just want an awsome one, short, cause i cant do it, my brain isn't pro yet...



THANK!?
Mr. T




PostPosted: Mon Sep 26, 2005 6:53 am   Post subject: Alex Young

People aren't just going to create large chunks of your code for you. Compsci is about learning, not blindly copying other's work. Rolling Eyes
TokenHerbz




PostPosted: Mon Sep 26, 2005 11:47 am   Post subject: (No subject)

aw ok, ill try more

i just really suck at the part of **Making it small**

i can code it, just it's large

i cant make it in a few lines, which is mainly what i was looking for, though i guess i should learn how to eh, ill work on it Smile
Mr. T




PostPosted: Mon Sep 26, 2005 4:16 pm   Post subject: Alex's Opinion

Arrays are a powerful tool for writing efficient code. Very Happy
Read up on the various compsci tutorials.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Mon Sep 26, 2005 4:39 pm   Post subject: (No subject)

beard0 wrote:
Cervantes wrote:
Indeed. I've used coordinate types such so often I just built them right into Turing, and made them pervasive. Now I've got them inside all sorts of built in functions.


Pray tell: how? I would love to do this. Unless you just mean having the same "include" line at the begining of every program...

Add a new module in %oot/support/predefs. I think I called mine Type. It looks like this:
Turing:

%
% Holds non-primitive data types.
%

% This does not have to be imported into your pgorams.

unit
module Type
    export ~.*all

    type coord2D :
        record
            x, y : real
        end record

    type vector2D :
        record
            mag, ang : real         % Magnitude, Angle
        end record

    type coord3D :
        record
            x, y, z : real
        end record

end Type

IIRC, the * means pervasive, and the ~. means export unqualified.

Next step: Add this module to the predefs.lst file. If you want to be able to use these types within the other predef modules, you must add this line above the other modules. I put it just after anyclass.
code:

"%oot/support/predefs/<your custom module name, including extension>"

Finished.

tokenherbz wrote:

But can you make one where it goes in a patter around?

Perhaps. Not at the moment. Neutral
[Gandalf]




PostPosted: Tue Sep 27, 2005 4:19 pm   Post subject: (No subject)

1. Make your code any way you know how.
2. Shorten it.
3. Change it according to the shortening.
4. Repeat 2&3 continuously.
codemage




PostPosted: Wed Sep 28, 2005 7:46 am   Post subject: (No subject)

1 quick example of an intro along that theme. I thought circles would look a bit more interesting - although a bit less '8-bit'.

I tried to upload as a file attachment - but it's not letting me. Here it is in all it's (lengthy - sorry) glory.

code:

%Created for CompSci.ca by codemage
%permission required for use

View.Set ("graphics:300;300,offscreenonly")
const midx := maxx div 2
const midy := maxy div 2
const outerbound := midx + 80

for decreasing radius : outerbound.. 0

%top
Draw.FillArc (midx, midy, outerbound, outerbound, 45, 135, black)
Draw.FillArc (midx, midy, radius, radius, 45, 135, black)
Draw.FillArc (midx, midy, radius, radius, 45, 135, white)

%left
Draw.FillArc (midx, midy, outerbound, outerbound, 135, 225, yellow)
Draw.FillArc (midx, midy, radius, radius, 135, 225, yellow)
Draw.FillArc (midx, midy, radius, radius, 135, 225, white)

%bottom
Draw.FillArc (midx, midy, outerbound, outerbound, 225, 315, black)
Draw.FillArc (midx, midy, radius, radius, 225, 315, black)
Draw.FillArc (midx, midy, radius, radius, 225, 315, white)

%right
Draw.FillArc (midx, midy, outerbound, outerbound, 315, 45, yellow)
Draw.FillArc (midx, midy, radius, radius, 315, 45, yellow)
Draw.FillArc (midx, midy, radius, radius, 315, 45, white)

%Radius Oval.  I just think this looks better with an outline.
Draw.Oval(midx,midy,radius,radius,black)

View.Update
delay(5)
end for
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  [ 11 Posts ]
Jump to:   


Style:  
Search: