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

Username:   Password: 
 RegisterRegister   
 Math Equation Fun
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Sean




PostPosted: Tue Apr 29, 2008 4:45 pm   Post subject: Math Equation Fun

After seeing Mackie do something in class today, I had the idea of creating my own.

This program is a basic program, one that uses many formulas such as: tan, cos, sin, and arctan.

However, if you try to use arcsin and arccos, you have a Quit #100 error. No idea what that is.

Turing:

%Sean McGregor

View.Set ("nobuttonbar")

var c : int
for x : 0 .. maxx
    randint (c, 0, 255)
    Draw.FillOval (x, round (arctan (tan (x)) * 200) + maxy div 2, 2, 2, c)
end for


You can play around with the arctan and tan part, changing it to what ever. and the 200 part to whatever dimension you see fit.
Made this in 5 minutes, off of the idea of Mackie.

Mackie, I'd like to see the archery project of mine that you are doing. Wink

Posted Image, might have been reduced in size. Click Image to view fullscreen.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Sponsor
Sponsor
Sponsor
sponsor
Nick




PostPosted: Tue Apr 29, 2008 4:58 pm   Post subject: RE:Math Equation Fun

do you know what the arc does?

it makes it use the Quenent identity of the function which basacally means 1/sin or 1/cos or 1/tan

why this causes an error?

what's 1 divided by 0?
Sean




PostPosted: Tue Apr 29, 2008 5:00 pm   Post subject: Re: RE:Math Equation Fun

nick @ Tue Apr 29, 2008 4:58 pm wrote:
do you know what the arc does?

it makes it use the Quenent identity of the function which basacally means 1/sin or 1/cos or 1/tan

why this causes an error?

what's 1 divided by 0?


What error are you speaking of? You mean of arccos and arcsin?
Nick




PostPosted: Tue Apr 29, 2008 5:01 pm   Post subject: RE:Math Equation Fun

that I am
Sean




PostPosted: Tue Apr 29, 2008 5:03 pm   Post subject: RE:Math Equation Fun

Arccos finds the arc cosine of a value and displays it in radiants. I don't believe I would be able to minipulate it into what I have done.

However arctan is usable.

It's just something I quickly came up with. Not that serious of a project.
Nick




PostPosted: Tue Apr 29, 2008 5:08 pm   Post subject: RE:Math Equation Fun

I'm saying that 1/0 is undoable and since arc creates a recipocal, there is division, so if your cos/sin/tan value results in a 0 you get an error
Saad




PostPosted: Tue Apr 29, 2008 5:10 pm   Post subject: Re: Math Equation Fun

Sean wrote:

However, if you try to use arcsin and arccos, you have a Quit #100 error. No idea what that is.

arccos, and arcsin of x has the restrictions that -1 >= x <= 1. This is by definition what the trig ratios give. Furthermore I hope you realise that trig functions are not just trippy things.

Sean wrote:

Turing:

View.Set ("nobuttonbar")

var c : int
for x : 0 .. maxx
    randint (c, 0, 255)
    Draw.FillOval (x, round (arctan (tan (x)) * 200) + maxy div 2, 2, 2, c)
end for



This program is quite boring and the quote can be improved.

First of all, why is c global and why is randint being used. You should be using Rand.Int which returns a random integer


Turing:

for x : 0 .. maxx
    Draw.FillOval (x, round (arctan (tan (x)) * 200) + maxy div 2, 2, 2, Rand.Int (0, 255))
end for


Now for a little more advanced stuff. Looking at the code we can easily say that that code requires us to change quite a bit if we want to use the function. So what should we do? The answer is passing functions as parameters. This allows us to make a function that graphs any given function. But before I go there you should have knowledge on functions (Tutorial here).


So without much delay some code.

Turing:
proc DrawGraphForFunction (myFunctionToGraph : fcn _ (x : real) : real, graphColor : int)
    for x : 0 .. maxx
        Draw.FillOval (x, round (myFunctionToGraph (x)), 2, 2, graphColor)
    end for
end DrawGraphForFunction

fcn SinWave (x : real) : real
    result sind (x) * 50 + maxy div 2
end SinWave

DrawGraphForFunction (SinWave, black)


Woah Shocked, thats weird code so let me explain it part by part.

Turing:
proc DrawGraphForFunction (myFunctionToGraph : function _ (x : real) : real, graphColor : int)

In this procedure declaration we are defining a function to take 2 parameters. One is a function to graph and one is the color. However lets take a closer look at the following
Turing:
myFunctionToGraph : fcn _ (x : real) : real

Note that this is really similar to just regular parameters passed into procedures/functions but more specifically we declare myFunctionToGraph as a function that takes 1 real number and returns a real number. The _ in the thing is that Turing requires a name after a function for some reason.

Now since myFunctionToGraph is a function, that means we can use it to give us our Y-Values
Turing:

Draw.FillOval (x, round (myFunctionToGraph (x)), 2, 2, graphColor)


The last part is the call to DrawGraphForFunction. We just pass it as a regular parameter.
Turing:

DrawGraphForFunction (SinWave, black)


Now this may have been a bit much but This covers up what I just talked about which is passing functions.
Nick




PostPosted: Tue Apr 29, 2008 5:17 pm   Post subject: RE:Math Equation Fun

oh and that part about -1 < x < 1 is a probable cause for that error as well Wink

also, Saad's method is much better (I even changed my sine wave program to almost the same thing too, just never submitted it)
Sponsor
Sponsor
Sponsor
sponsor
Sean




PostPosted: Tue Apr 29, 2008 7:16 pm   Post subject: RE:Math Equation Fun

I really could careless if it is boring, or not. I made this program in five minutes, and it was just playing around with cos, tan, sin, and arctan.

There is no need to go and point out that you don't like it or not like that. And plus, don't speak to me as if I am some person who can't understand coding.
zylum




PostPosted: Tue Apr 29, 2008 7:30 pm   Post subject: RE:Math Equation Fun

Sean, there is no need to get defensive. No one said your program is boring or that they don't like it. nick suggested a reason as to why arcsin and arccos give you an error and Saad gave you some ways to improve your program as well as give a brief intro to functional programming which might inspire you to make more interesting programs.
Sean




PostPosted: Tue Apr 29, 2008 7:38 pm   Post subject: Re: Math Equation Fun

Saad @ Tue Apr 29, 2008 5:10 pm wrote:

arccos, and arcsin of x has the restrictions that -1 >= x <= 1. This is by definition what the trig ratios give. Furthermore I hope you realise that trig functions are not just trippy things.

This program is quite boring and the quote can be improved.


Never once did I want this to be trippy. I don't do drugs, neither will I ever. Furthermore, I was doing graphic styles using trig formulas. Nothing More, Nothing Less.

Oh, and there is the boring section.

Rolling Eyes
Saad




PostPosted: Tue Apr 29, 2008 7:43 pm   Post subject: Re: Math Equation Fun

Sean @ Tue Apr 29, 2008 7:38 pm wrote:
Saad @ Tue Apr 29, 2008 5:10 pm wrote:

arccos, and arcsin of x has the restrictions that -1 >= x <= 1. This is by definition what the trig ratios give. Furthermore I hope you realise that trig functions are not just trippy things.

This program is quite boring and the quote can be improved.


Never once did I want this to be trippy. I don't do drugs, neither will I ever. Furthermore, I was doing graphic styles using trig formulas. Nothing More, Nothing Less.

Oh, and there is the boring section.

Rolling Eyes


Sorry for some misunderstanding. It seemed like your program was one of your trippy programs that I've seen. My diction was probably a poor choice and sorry for that too.

As for the "boring section", I just tried to give some constructive criticism and a small introduction into some functional programming. If you find it boring then I'm sorry about the long post.
Sean




PostPosted: Tue Apr 29, 2008 7:46 pm   Post subject: Re: Math Equation Fun

Please link me to a trippy post of mine. Never created one.

And your introduction was appreciated, however, would of been better not to include the boring part, as that tends to rally people against you.
Saad




PostPosted: Tue Apr 29, 2008 7:47 pm   Post subject: Re: Math Equation Fun

Sean @ Tue Apr 29, 2008 7:46 pm wrote:
Please link me to a trippy post of mine. Never created one.


I never said your trippy flashes. I was referring to trippy flashes that have been already posted (not by you)

Sean @ Tue Apr 29, 2008 7:46 pm wrote:
And your introduction was appreciated, however, would of been better not to include the boring part, as that tends to rally people against you.


Again I'm sorry for my choice of words.
Tony




PostPosted: Tue Apr 29, 2008 8:38 pm   Post subject: RE:Math Equation Fun

It was all misunderstanding, lets leave it at that.

Posted Image, might have been reduced in size. Click Image to view fullscreen.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: