[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[epsilon-devel] Re: draw regular poligons

From: Luca Saiu
Subject: [epsilon-devel] Re: draw regular poligons
Date: Wed, 03 Dec 2003 18:24:51 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.3a) Gecko/20021212

Matteo Golfarini wrote:
sorry ...... now i start to implemented generic poligon .....

Don't mind; your work has been useful as an exercise. I see you are becoming good at epsilon programming.

  Some comments on your code:

define colore = (100 , 100 , 100);
  This could have been a parameter.

// server soltanto per farlo visualizzare usando una visualizzazione del primo 
define c_y = \ y .
        max_y - y;
For the other graphic primitives the origin is top-left, with x growing to the right and y growing downwards (like in SDL, X and most other graphic environments); however you have decided to use a bottom-left origin (like in OpenGL) for this exercise. Ok. This function *is the right way* to do what you want. It's always good to modularize.

// mi sono dimenticato se il compilatore e' furbo e si calcola una
> // sola volta angle +f etc.
define draw_poligon_with_angle = \ x . \ y . \ num . \ len . \ angle .
        draw_poligon_ugly x y (next_xy x y len  (angle +f pi +f angle)) num len 
 (angle +f pi +f angle) angle 1 (x , y) ;

You asked whether the compiler is smart enough to compute (angle +f pi +f angle) just once. The answer is no, not yet. The optimization you are talking about is called "common subexpressions elimination", and it will be quite easy to implement it in the meta-compiler (but we need epsilonyacc before... my fault :-)). You can safely assume that the optimizer exists; you could have used a let to compute the subexpression just once, but in general it's better to write the code so that it's easy to read/modify for *you*, not for the machine. Nonetheless *in this case* I would have used a let (for readability, not for speed):
  let new_angle be
    angle +f pi +f angle

Ok. You wrote your draw_polygon in 'turtle-graphics' style, starting from a vertex, drawing a line and rotating. This has advantages and disadvantages: what if you wanted to draw a triangle like this?
    \ /
  With your code the base must always be below:

Well done. Your solution is nice; I would have named the functions in a more comprehensible way, but, oh well :-).


Luca Saiu, maintainer of GNU epsilon

reply via email to

[Prev in Thread] Current Thread [Next in Thread]