Re: [QUIZ] Equation Graphing (#176)



On Fri, Sep 5, 2008 at 10:01 AM, Matthew Moss <matthew.moss@xxxxxxxxx> wrote:
whip out your favourite graphics toolkit or library and write a
program that

1. Asks for a function of one variable, x
2. Asks for the region of the graph to display (xmin, xmax, ymin, ymax)
3. Plots the graph

I didn't follow the requirements, but inspired by the quiz did a
little bit using my favorite graphics (none;-):

def grapher xmin, ymin, xmax, ymax, &function
ymax.downto(ymin) do |y|
xmin.upto(xmax) do |x|
begin
print (function.call(x, y) ? '#' : '+')
rescue
print "X"
end
end
print "\n"
end
print "\n"
end

grapher(0, 0, 40, 10){|x,y| x == y}
grapher(0, 0, 40, 10){|x,y| 2 >= y**2 / x}
grapher(0, -5, 60, 10){|x,y| y == (5 + Math.sin(x) * 5).to_i}
grapher(-10, -5, 70, 10){|x,y| y**2 == x}

Output:

++++++++++#++++++++++++++++++++++++++++++
+++++++++#+++++++++++++++++++++++++++++++
++++++++#++++++++++++++++++++++++++++++++
+++++++#+++++++++++++++++++++++++++++++++
++++++#++++++++++++++++++++++++++++++++++
+++++#+++++++++++++++++++++++++++++++++++
++++#++++++++++++++++++++++++++++++++++++
+++#+++++++++++++++++++++++++++++++++++++
++#++++++++++++++++++++++++++++++++++++++
+#+++++++++++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++

X+++++++++++++++++++++++++++++++++#######
X+++++++++++++++++++++++++++#############
X+++++++++++++++++++++###################
X++++++++++++++++########################
X++++++++++++############################
X++++++++################################
X+++++###################################
X+++#####################################
X+#######################################
X########################################
X########################################

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+##+++++#+++++#+++++##+++++#+++++#+++++#+++++##+++++#+++++#++
+++++++#+++++++#++++++++++#+++++++++++++#++++++++++#+++++++#+
+++++++++#+++#++++++++++++++++++#+#++++++++++++++++++++++#+++
++++++++++++++++++++++++++++#+++++++++#++++++++++++++#+++++++
#++#+++++++++++++++#++++++++++++++++++++++++#++#+++++++++++++
++++++++++++++++++++++#++#+++++++++++++++#+++++++++++++++++++
++++++#+++++++++#+++++++++++++++++++++++++++++++++#+++++++++#
++++++++++#+#++++++++++++++++++#+++#++++++++++++++++++#+#++++
++++#+++++++++++++#++++++++++#+++++++#++++++++++#++++++++++++
+++++#+++++#+++++#+++++##+++++#+++++#+++++##+++++#+++++#+++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#+++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++#++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++#+++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++#++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++#++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++#+++++++++++++++++++++++++++++++++++++++++++++

http://github.com/fjc/rubyquiz/tree/master/176.rb

.



Relevant Pages

  • Re: How to simplify long syntax
    ... Xmax = Xmin + 500000 ... Ymin = 0 ... Ymax = 500000 ...
    (microsoft.public.vb.general.discussion)
  • How to simplify long syntax
    ... Dim Xmin As Double ... Dim Ymin As Double ... Dim Xmax As Double ... Dim Ymax As Double ...
    (microsoft.public.vb.general.discussion)
  • Re: How to rotate a bitmap?
    ... if x < xMin then ... if x> xMax then ... if y < yMin then ... if y> yMax then ...
    (alt.comp.lang.borland-delphi)
  • Re: How to rotate a bitmap?
    ... if x < xMin then ... if x> xMax then ... if y < yMin then ... if y> yMax then ...
    (alt.comp.lang.borland-delphi)
  • Re: How to simplify long syntax
    ... Xmin = Xmin ... Xmax = Xmin + 12500 ... Ymin = Ymin ... Ymax = Ymin + 12500 ...
    (microsoft.public.vb.general.discussion)