Plotting

Hello all

Actually I wanted to ask how can I get more precision in plotting pixels.
Like I am using sin function to generate a floating value and I want it to
map on the screen.
How should I plot it?

Simply adding in the pixel column of the screen does’nt work.

Similarly like plotting a random curve how can I plot them

Thanxx

Naman

What are you doing currently? Are you able to plot curves? If you just
want more precision (and the appropriate representation on the screen), then
you should use anti-aliasing to draw the curve.

Jonny DOn Thu, Apr 29, 2010 at 9:16 AM, naman kohli wrote:

Hello all

Actually I wanted to ask how can I get more precision in plotting pixels.
Like I am using sin function to generate a floating value and I want it to
map on the screen.
How should I plot it?

Simply adding in the pixel column of the screen does’nt work.

Similarly like plotting a random curve how can I plot them

Thanxx

Naman


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

No am not able to plot curves.

What I want to ask is that the value will always be floating. So how should
i introduce correct mapping to the pixel integer.On Thu, Apr 29, 2010 at 10:31 PM, Jonathan Dearborn wrote:

What are you doing currently? Are you able to plot curves? If you just
want more precision (and the appropriate representation on the screen), then
you should use anti-aliasing to draw the curve.

Jonny D

On Thu, Apr 29, 2010 at 9:16 AM, naman kohli <@naman_kohli>wrote:

Hello all

Actually I wanted to ask how can I get more precision in plotting pixels.
Like I am using sin function to generate a floating value and I want it to
map on the screen.
How should I plot it?

Simply adding in the pixel column of the screen does’nt work.

Similarly like plotting a random curve how can I plot them

Thanxx

Naman


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Naman

Are you using a graphics library like SDL_gfx or Sprig? That’s the easiest
way to go. They both have anti-aliased primitives too. 2D parametric
curves are easy to plot and so are simple (i.e. nonsingular) functions,
using connecting lines between data points. Both libraries have bezier
curves as well, in case you’re interested.

Jonny DOn Thu, Apr 29, 2010 at 10:06 AM, naman kohli wrote:

No am not able to plot curves.

What I want to ask is that the value will always be floating. So how should
i introduce correct mapping to the pixel integer.

On Thu, Apr 29, 2010 at 10:31 PM, Jonathan Dearborn <@Jonathan_Dearborn>wrote:

What are you doing currently? Are you able to plot curves? If you just
want more precision (and the appropriate representation on the screen), then
you should use anti-aliasing to draw the curve.

Jonny D

On Thu, Apr 29, 2010 at 9:16 AM, naman kohli wrote:

Hello all

Actually I wanted to ask how can I get more precision in plotting pixels.
Like I am using sin function to generate a floating value and I want it
to map on the screen.
How should I plot it?

Simply adding in the pixel column of the screen does’nt work.

Similarly like plotting a random curve how can I plot them

Thanxx

Naman


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Naman


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I don’t think I can use extra libraries to make a sin x type of
plotting…I mean like I looked SDL_gfx but I can use it for drawing
curves.

Can anyone help with making a sin x type of a graph with pixel plotting.On Thu, Apr 29, 2010 at 10:49 PM, Jonathan Dearborn wrote:

Are you using a graphics library like SDL_gfx or Sprig? That’s the easiest
way to go. They both have anti-aliased primitives too. 2D parametric
curves are easy to plot and so are simple (i.e. nonsingular) functions,
using connecting lines between data points. Both libraries have bezier
curves as well, in case you’re interested.

Jonny D

On Thu, Apr 29, 2010 at 10:06 AM, naman kohli <@naman_kohli>wrote:

No am not able to plot curves.

What I want to ask is that the value will always be floating. So how
should i introduce correct mapping to the pixel integer.

On Thu, Apr 29, 2010 at 10:31 PM, Jonathan Dearborn wrote:

What are you doing currently? Are you able to plot curves? If you just
want more precision (and the appropriate representation on the screen), then
you should use anti-aliasing to draw the curve.

Jonny D

On Thu, Apr 29, 2010 at 9:16 AM, naman kohli <@naman_kohli>wrote:

Hello all

Actually I wanted to ask how can I get more precision in plotting
pixels.
Like I am using sin function to generate a floating value and I want it
to map on the screen.
How should I plot it?

Simply adding in the pixel column of the screen does’nt work.

Similarly like plotting a random curve how can I plot them

Thanxx

Naman


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Naman


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Naman

You need to update the screen after plotting the pixels. Have you tried the
code I sent you?

JeffOn Thursday 29 April 2010 09:16, naman kohli wrote:

Hello all

Actually I wanted to ask how can I get more precision in plotting pixels.
Like I am using sin function to generate a floating value and I want it to
map on the screen.
How should I plot it?

Simply adding in the pixel column of the screen does’nt work.

yeah but what i am asking is that lets say i calculate a sin x value which
is floating.Now i need it to be mapped to a pixel.What should I do. Like if
I simply round it all values would be the same.
I need a function that simply does this so i can use it in a recursive
manner to calculate sin(cos(x)) etc…On Fri, Apr 30, 2010 at 12:19 AM, Jeff Post <j_post at pacbell.net> wrote:

On Thursday 29 April 2010 09:16, naman kohli wrote:

Hello all

Actually I wanted to ask how can I get more precision in plotting pixels.
Like I am using sin function to generate a floating value and I want it
to
map on the screen.
How should I plot it?

Simply adding in the pixel column of the screen does’nt work.

You need to update the screen after plotting the pixels. Have you tried the
code I sent you?

Jeff


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi,

you can use Cairo for your plotting since cairo operates on floating point coordinates and is able to do subpixel antialiasing (simulating more pixels in one pixel using shades of color) for all primitives. That would do what you need.

On a Mac you could do the same with Quartz 2D.

PavelOn 29.4.2010, at 21:50, naman kohli wrote:

yeah but what i am asking is that lets say i calculate a sin x value which is floating.Now i need it to be mapped to a pixel.What should I do. Like if I simply round it all values would be the same.
I need a function that simply does this so i can use it in a recursive manner to calculate sin(cos(x)) etc…

On Fri, Apr 30, 2010 at 12:19 AM, Jeff Post <j_post at pacbell.net> wrote:
On Thursday 29 April 2010 09:16, naman kohli wrote:

Hello all

Actually I wanted to ask how can I get more precision in plotting pixels.
Like I am using sin function to generate a floating value and I want it to
map on the screen.
How should I plot it?

Simply adding in the pixel column of the screen does’nt work.

You need to update the screen after plotting the pixels. Have you tried the
code I sent you?

Jeff


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You need to scale coordinates before you use them. You had me confused for
a while there :slight_smile: Here’s an example:
float x = M_PI/2; // Raw math coord
float y = sin(x); // Raw math coord

// Set your on-screen origin
float myOriginX = 50; // screen coords (pixels)
float myOriginY = screen->h - 70; // screen coords

// Set your conversion from math coords to screen coords
float scaleX = fabs(screen->w - myOriginX)/10.0f; // 10 x-units will cross
the width of the screen
float scaleY = -fabs(screen->h - myOriginY)/20.0f; // 20 y-units will cross
the height of the screen, y-coord is inverted

// Plot the point
SPG_Pixel(screen, myOriginX + xscaleX, myOrigin + yscaleY,
SDL_MapRGB(screen->format, 255, 0, 0));

I haven’t tested this, but I hope you get the idea. You have to choose the
scaling.

Jonny DOn Thu, Apr 29, 2010 at 12:50 PM, naman kohli wrote:

yeah but what i am asking is that lets say i calculate a sin x value which
is floating.Now i need it to be mapped to a pixel.What should I do. Like if
I simply round it all values would be the same.
I need a function that simply does this so i can use it in a recursive
manner to calculate sin(cos(x)) etc…

On Fri, Apr 30, 2010 at 12:19 AM, Jeff Post <j_post at pacbell.net> wrote:

On Thursday 29 April 2010 09:16, naman kohli wrote:

Hello all

Actually I wanted to ask how can I get more precision in plotting
pixels.
Like I am using sin function to generate a floating value and I want it
to
map on the screen.
How should I plot it?

Simply adding in the pixel column of the screen does’nt work.

You need to update the screen after plotting the pixels. Have you tried
the
code I sent you?

Jeff


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

As Jonny D said, scale it according the the size of your display area. As for
anti-aliasing, I’ve found no need to do that for plotting math functions.
Look at the display output of polygraph, especially the splash screen with
sines. Mathematica does it better, presumably with anti-aliasing, but I think
you’d have to be pretty nit-picky to complain about the difference.

JeffOn Thursday 29 April 2010 12:50, naman kohli wrote:

yeah but what i am asking is that lets say i calculate a sin x value which
is floating.Now i need it to be mapped to a pixel.What should I do. Like if
I simply round it all values would be the same.
I need a function that simply does this so i can use it in a recursive
manner to calculate sin(cos(x)) etc…

Say you have a function like this (from SDL_Surface.h in hg):
int SDL_BlendPoint(SDL_Surface * dst, int x, int y, int blendMode,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);

… and you want to plot a point at a floating point position on a
surface, that is, you have a “double x” and “double y” which can have
values like x = 324.6, y = 287.3.

To plot such a point, plot the four pixels surrounding it and adjust
the alpha value according to the distance from the point to each
pixel. That is, for (324.6, 287.3), you would plot the following:
(324, 287) with alpha = 255 / (0.62 + 0.32),
(325, 287) with alpha = 255 / ((1 - 0.6)2 + 0.32),
(324, 288) with alpha = 255 / (0.6**2 + (1 - 0.3)**2), and
(325, 288) with alpha = 255 / ((1 - 0.6)**2 + (1 - 0.3)**2).

So you need a function like this:
#include <math.h>
void PlotPoint(SDL_Surface* dst, double x, double y, Uint8 r, Uint8 g,
Uint8 b, Uint8 a) {
double ix, rx, iy, ry;
rx = modf(x, &ix);
ry = modf(y, &iy);
SDL_BlendPoint(dst, (int) ix, (int) iy, SDL_BLENDMODE_BLEND, r, g,
b, a / (rxrx + ryry));
SDL_BlendPoint(dst, (int) ix+1, (int) iy, SDL_BLENDMODE_BLEND, r, g,
b, a / ((1-rx)(1-rx) + ryry));
SDL_BlendPoint(dst, (int) ix, (int) iy+1, SDL_BLENDMODE_BLEND, r, g,
b, a / (rxrx + (1-ry)(1-ry)));
SDL_BlendPoint(dst, (int) ix+1, (int) iy+1, SDL_BLENDMODE_BLEND, r,
g, b, a / ((1-rx)(1-rx) + (1-ry)(1-ry)));
}

And, of course, remember to scale your x and y values before passing
them to PlotPoint.

(324, 287) with alpha = 255 / (0.62 + 0.32),
(325, 287) with alpha = 255 / ((1 - 0.6)2 + 0.32),
(324, 288) with alpha = 255 / (0.6**2 + (1 - 0.3)**2), and
(325, 288) with alpha = 255 / ((1 - 0.6)**2 + (1 - 0.3)**2).

Or,
(324, 287) with alpha = 255 * (1 - 0.6 * 0.3),
(325, 287) with alpha = 255 * (1 - (1 - 0.6) * 0.3),
(324, 288) with alpha = 255 * (1 - 0.6 * (1 - 0.3)), and
(325, 288) with alpha = 255 * (1 - (1 - 0.6) * (1 - 0.3)).

?SDL_BlendPoint(dst, (int) ix, (int) iy, SDL_BLENDMODE_BLEND, r, g, b, a / (rxrx + ryry));
?SDL_BlendPoint(dst, (int) ix+1, (int) iy, SDL_BLENDMODE_BLEND, r, g, b, a / ((1-rx)(1-rx) + ryry));
?SDL_BlendPoint(dst, (int) ix, (int) iy+1, SDL_BLENDMODE_BLEND, r, g, b, a / (rxrx + (1-ry)(1-ry)));
?SDL_BlendPoint(dst, (int) ix+1, (int) iy+1, SDL_BLENDMODE_BLEND, r, g, b, a / ((1-rx)(1-rx) + (1-ry)(1-ry)));

SDL_BlendPoint(dst, (int) ix, (int) iy, SDL_BLENDMODE_BLEND, r, g,
b, a * (1 - rxry));
SDL_BlendPoint(dst, (int) ix+1, (int) iy, SDL_BLENDMODE_BLEND, r, g,
b, a * (1 - (1-rx)ry));
SDL_BlendPoint(dst, (int) ix, (int) iy+1, SDL_BLENDMODE_BLEND, r, g,
b, a * (1 - rx
(1-ry)));
SDL_BlendPoint(dst, (int) ix+1, (int) iy+1, SDL_BLENDMODE_BLEND, r,
g, b, a * (1 - (1-rx)
(1-ry)));

Since the other gives division by zero…
(this would be faster too)On 3 May 2010 19:48, Kenneth Bull <@Kenneth_Bull> wrote: