Allegro.cc Forums » Programming Questions » Math graph plot

 This thread is locked; no one can reply to it.
 Math graph plot
 Alexandre Bencz Member #15,257 August 2013 How can develop a system to draw on the screen the graph of a function?I already have the analysis system of mathematical expression, now I want to draw the graph of expression.How is the best way to implement this ?At now, I'm thinking of doing the this..:( this is just a ideia of code... ) #SelectExpand 1while(y <= 500) 2{ 3x = computeX("1+x", y); 4al_put_pixel(x, y, al_map_rgb(0,0,0)) 5y++; 6}
 StevenVI Member #562 July 2000 Using al_put_pixel at each sample point is one approach, but what you'll get is a series of dots. You might have better luck using a line between each sample point to fill in the in-between spaces.Also note that in Allegro, the origin is in the upper-left corner with x increasing to the right and y increasing to the bottom. The y coordinate is likely the inverse of how you typically think of the Cartesian plane. __________________________________________________Skoobalon Software[ Lander! v2.5 ] [ Zonic the Hog v1.1 ] [ Raid 2 v1.0 ]
 Alexandre Bencz Member #15,257 August 2013 Hi StevenVI About coordinates, I know that..., I will make a simple calculus to fix this...About use a line... if I need to drawn a parabola, or drawn a sine wave, I believe that for these cases, it would be better to put pixel by pixel, or would have some more efficient approach?
 StevenVI Member #562 July 2000 Sorry -- I'm not trying to confuse you, but I may be misunderstanding your intentions. If you want to draw a continuous curve, you'd want to use a line, because what you're actually doing is drawing a polygon that approximates the function using the finite pixels in your bitmap. Thus you'd use lines for each segment in the polygon.If you want to just see each sample point rather than an approximate curve, then you'd want to use pixels. __________________________________________________Skoobalon Software[ Lander! v2.5 ] [ Zonic the Hog v1.1 ] [ Raid 2 v1.0 ]
 Go to: Allegro Development Installation, Setup & Configuration Allegro.cc Comments Off-Topic Ordeals The Depot Game Design & Concepts Programming Questions Recent Threads