# Black/White Stripes again

Hi.

A couple of weeks ago I asked you how to generate black and white stripes
which are moving from right to left.

I did this “quest” with some help, but there are still some problems.

My professor wants the stripes more efficient.

The problem to solve is:

How can I generate black and white stripes without doing this with
rectangles.

This is necessary, because the stripes have to move as fast as possible so
that the stripes blur to gray.

He told me to do this something with sinus-waves or so, but I didn’t
understand him yet.

I would be very glad, if someone of you know how to do it.

Thanks.

Walter

Just out of curiosity, why don’t you ask the professor? Isn’t that what
he’s there for?

walter wrote:> Hi.

A couple of weeks ago I asked you how to generate black and white stripes
which are moving from right to left.

I did this “quest” with some help, but there are still some problems.

My professor wants the stripes more efficient.

The problem to solve is:

How can I generate black and white stripes without doing this with
rectangles.

This is necessary, because the stripes have to move as fast as possible so
that the stripes blur to gray.

He told me to do this something with sinus-waves or so, but I didn’t
understand him yet.

I would be very glad, if someone of you know how to do it.

Thanks.

Walter

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

Yes, that is what he’s there for, but some profs are a little bit
"particular".On the other hand, he is a biologist, so that he is not very familiar with this material. greetings, walter Leo Cabrera schrieb: Just out of curiosity, why don’t you ask the professor? Isn’t that what he’s there for? walter wrote:

Hi.

A couple of weeks ago I asked you how to generate black and white
stripes
which are moving from right to left.

I did this “quest” with some help, but there are still some problems.

My professor wants the stripes more efficient.

The problem to solve is:

How can I generate black and white stripes without doing this with
rectangles.

This is necessary, because the stripes have to move as fast as
possible so
that the stripes blur to gray.

He told me to do this something with sinus-waves or so, but I didn’t
understand him yet.

I would be very glad, if someone of you know how to do it.

Thanks.

Walter

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

Given a sinewave with the peaks describing white and the troughs
describing black, you don’t get black and white stripes, but instead you
get varying shades of grey that briefly touch on white and black.

Why not create a single surface that’s one wavelength wider than the
screen. Display this surface so that the excess width hangs off the
right side of the screen. In your animation loop, you move it to the
left until all the excess is now off the left side of the screen. At
this point you will have moved one wavelength such that the display will
look identical to the starting point. Now in your animation loop you
jump it back so that the excess is on the right, and your loop
continues. To someone watching, it appears that the picture is moving
steadily to the left. Now to speed things up, you either loop faster, or
you move in greater numbers of pixels at a time. The quality of your
result will depend on the quality of your hardware, but that’s a
limitation everyone must deal with.

The alternative using a sinusoidal function to paint the screen will be
much slower since you’ll have to map each pixel by hand.

CWC

Walter Linzenbold wrote:> Yes, that is what he’s there for, but some profs are a little bit

“particular”.

On the other hand, he is a biologist, so that he is not very familiar with this material. greetings, walter Leo Cabrera schrieb: Just out of curiosity, why don’t you ask the professor? Isn’t that what he’s there for? walter wrote:

Hi.

A couple of weeks ago I asked you how to generate black and white
stripes
which are moving from right to left.

I did this “quest” with some help, but there are still some problems.

My professor wants the stripes more efficient.

The problem to solve is:

How can I generate black and white stripes without doing this with
rectangles.

This is necessary, because the stripes have to move as fast as
possible so
that the stripes blur to gray.

He told me to do this something with sinus-waves or so, but I didn’t
understand him yet.

I would be very glad, if someone of you know how to do it.

Thanks.

Walter

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

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

If you don’t mind a “slower” solution, you can plot pixels.
Something like this should do the trick
http://sol.gfxile.net/gp/ch02.html
just play with the equation being plotted.
Something like sin(j+tick) should do it (experiment with sin, i, j and
tick).

-p-------- Original Message --------
Subject: Re: [SDL] Black/White Stripes again
From: Walter Linzenbold
Date: Thu, June 26, 2008 3:52 pm
To: “A list for developers using the SDL library. (includes
SDL-announce)” sdl@lists.libsdl.org

Yes, that is what he’s there for, but some profs are a little bit
"particular".

On the other hand, he is a biologist, so that he is not very familiar with this material. greetings, walter Leo Cabrera schrieb: Just out of curiosity, why don’t you ask the professor? Isn’t that what he’s there for? walter wrote:

Hi.

A couple of weeks ago I asked you how to generate black and white
stripes
which are moving from right to left.

I did this “quest” with some help, but there are still some problems.

My professor wants the stripes more efficient.

The problem to solve is:

How can I generate black and white stripes without doing this with
rectangles.

This is necessary, because the stripes have to move as fast as
possible so
that the stripes blur to gray.

He told me to do this something with sinus-waves or so, but I didn’t
understand him yet.

I would be very glad, if someone of you know how to do it.

Thanks.

Walter

Doing this with rectangles is the fastest way to go. If you need more speed, you should look into getting a hardware surface. That will accelerate your calls to SDL_FillRect (which is probably called by most primitives libraries when drawing rects). You might be able to squeeze a bit more speed by using horizontal lines. Maybe a dirty rect technique would work, too. Making your stripes thinner would make them blur easier as well.

Jonny D> Date: Thu, 26 Jun 2008 21:12:49 +0200

From: sdl at jokawalli.de
To: sdl at lists.libsdl.org
Subject: [SDL] Black/White Stripes again

Hi.

A couple of weeks ago I asked you how to generate black and white stripes
which are moving from right to left.

I did this “quest” with some help, but there are still some problems.

My professor wants the stripes more efficient.

The problem to solve is:

How can I generate black and white stripes without doing this with
rectangles.

This is necessary, because the stripes have to move as fast as possible so
that the stripes blur to gray.

He told me to do this something with sinus-waves or so, but I didn’t
understand him yet.

I would be very glad, if someone of you know how to do it.

Thanks.

Walter

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

Or even OpenGL, if you’re allowed to take a hardware approach. It’s
certainly going to help get the dither effect going if you can get the
image drawing rate way over your monitor refresh rate such that you
get vertical tearing.

Peter

2008/6/27 Jonathan Dearborn :> Doing this with rectangles is the fastest way to go. If you need more

speed, you should look into getting a hardware surface. That will
accelerate your calls to SDL_FillRect (which is probably called by most
primitives libraries when drawing rects). You might be able to squeeze a
bit more speed by using horizontal lines. Maybe a dirty rect technique
would work, too. Making your stripes thinner would make them blur easier as
well.

Jonny D

Date: Thu, 26 Jun 2008 21:12:49 +0200
From: sdl at jokawalli.de
To: sdl at lists.libsdl.org
Subject: [SDL] Black/White Stripes again

Hi.

A couple of weeks ago I asked you how to generate black and white stripes
which are moving from right to left.

I did this “quest” with some help, but there are still some problems.

My professor wants the stripes more efficient.

The problem to solve is:

How can I generate black and white stripes without doing this with
rectangles.

This is necessary, because the stripes have to move as fast as possible so
that the stripes blur to gray.

He told me to do this something with sinus-waves or so, but I didn’t
understand him yet.

I would be very glad, if someone of you know how to do it.

Thanks.

Walter

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

Hi Walter,

Actually, I’ve written a little demo doing a wave effect on an image recently,
using either SDL_Rects or a direct access to pixels. Performances are equal
as long as you convert your surfaces to the display format.
I’ve tried a loop for writing data, and using memcpy. Those two methods
have equivalent performances with SDL_BlitSurface when there is no
surface format mismatch.

You can download it and see the source code if you want, at:

If your machine is fast, add a “-DDELAY=16” to the definition of the "config"
variable at the beginning of the makefile.

Regards,

Julien

----- Message d’origine ----De : walter
? : sdl at lists.libsdl.org
Envoy? le : Jeudi, 26 Juin 2008, 21h12mn 49s
Objet : [SDL] Black/White Stripes again

Hi.

A couple of weeks ago I asked you how to generate black and white stripes
which are moving from right to left.

I did this “quest” with some help, but there are still some problems.

My professor wants the stripes more efficient.

The problem to solve is:

How can I generate black and white stripes without doing this with
rectangles.

This is necessary, because the stripes have to move as fast as possible so
that the stripes blur to gray.

He told me to do this something with sinus-waves or so, but I didn’t
understand him yet.

I would be very glad, if someone of you know how to do it.

Thanks.

Walter

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

``````  _____________________________________________________________________________
``````

Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr

I would code this using a mixed approach:

• render a “line” using a sin function with amplitude, frequency and
offset control
width=round(2PI/frequency)
for x=0…width-1 do
line(x)=amplitude
abs(sin(x*frequency+offset))

• if you need black and white only, binarize your values based on a
amplitude_cutoff
for x=0…width-1 do
if line(x)>amplitude_cutoff line(x)=white else line(x)=black

• pre-render a “tile” surface of arbitrary (reasonable) height filling
it with line data
height=16
for y=0…height-1do
tile(0…width,y)=line(0…width)

• render the screen by blitting tiles over it
for x=0…screen_width,step width do
for y=0…screen_height,step height do
screen(x,y)=tile()

• create animation of moving lines by changing the value of offset in
the loop
offset+=step
if offset>2PI offset-=2PI
delay_and_loop

Note: If your width is too small, you’ll probably get some visible
aliasing on the tiles right edge.

walter wrote:

Hi.

A couple of weeks ago I asked you how to generate black and white stripes
which are moving from right to left.

I did this “quest” with some help, but there are still some problems.

My professor wants the stripes more efficient.

The problem to solve is:

How can I generate black and white stripes without doing this with
rectangles.

This is necessary, because the stripes have to move as fast as possible so
that the stripes blur to gray.

He told me to do this something with sinus-waves or so, but I didn’t
understand him yet.

I would be very glad, if someone of you know how to do it.

Thanks.

Walter

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

-------------- next part --------------
A non-text attachment was scrubbed…
Name: aschiffler.vcf
Type: text/x-vcard
Size: 135 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080627/6031c13a/attachment.vcf

Thanks @all.

I will do my best and try to implement some of your ideas .
Hope, I will be able to do this at the weekend.
If some of you have more ideas, please, don’t hesitate to write it here

Regards
Walter

Andreas Schiffler schrieb:>

I would code this using a mixed approach:

• render a “line” using a sin function with amplitude, frequency and
offset control
width=round(2PI/frequency)
for x=0…width-1 do
line(x)=amplitude
abs(sin(x*frequency+offset))

• if you need black and white only, binarize your values based on a
amplitude_cutoff
for x=0…width-1 do
if line(x)>amplitude_cutoff line(x)=white else line(x)=black

• pre-render a “tile” surface of arbitrary (reasonable) height filling
it with line data
height=16
for y=0…height-1do
tile(0…width,y)=line(0…width)

• render the screen by blitting tiles over it
for x=0…screen_width,step width do
for y=0…screen_height,step height do
screen(x,y)=tile()

• create animation of moving lines by changing the value of offset in
the loop
offset+=step
if offset>2PI offset-=2PI
delay_and_loop

Note: If your width is too small, you’ll probably get some visible
aliasing on the tiles right edge.

walter wrote:

Hi.

A couple of weeks ago I asked you how to generate black and white
stripes
which are moving from right to left.

I did this “quest” with some help, but there are still some problems.

My professor wants the stripes more efficient.

The problem to solve is:

How can I generate black and white stripes without doing this with
rectangles.

This is necessary, because the stripes have to move as fast as
possible so
that the stripes blur to gray.

He told me to do this something with sinus-waves or so, but I didn’t
understand him yet.

I would be very glad, if someone of you know how to do it.

Thanks.

Walter

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