 # FEZ Cobra and graphics

Hi,

For one project, I need to display a sinusoid on the screen and then, move a point inside this sinusoid to explain of the alternative power is working.

To achieve so, I will not redraw the sinusoid each frame, but only will move the point inside the sinusoid.

Using a Cobra with TFT 4"3:

Question 1:
Time to draw a sinusoid ? (Knowing I could change the frequency, I could need to redraw the sinusoid)

Question 2:
Is cobra the right choice for moving a point at a speed, lets say, 1 second to go from the beginning to the end “of” the screen ?

Question 3:
If not the right choice, what alternative could I take ? (Hydra ? Chipworks)…

Thanks,

Nicolas, Toulouse, France

I"ve made a quick example of a moving sine (so not a moving point, but the whole sine, moving a point is peanuts compared to that 8) ) on a FEZ Cobra.

I create a “tile” of the sine once, then the tile is drawn many times after eachother to fill the screen. For a different amplitude or frequency, just re-render the tile once again.

``````
using System;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.System;
using Microsoft.SPOT.Presentation.Media;

namespace CobraSineTest
{
public class Program
{
public static Bitmap RenderSine(int width, int height)
{
Bitmap tile = new Bitmap(width, height);

double angle = 0;
double increment = (2 * MathEx.PI) / width;
int prevY = height / 2;

for (int x = 0; x < tile.Width; x++)
{
int y = (tile.Height + (int)(MathEx.Sin(angle) * (height - 2))) / 2;

tile.DrawLine(ColorUtility.ColorFromRGB(0xA0, 0xC0, 0xFF), 1, x - 1, prevY, x, y);
prevY = y;

angle += increment;
}

return tile;
}

public static void Main()
{
Bitmap lcd = new Bitmap(320, 240);

Bitmap sine = RenderSine(100, 100);

int offset = 0;

while (true)
{
lcd.Clear();

int x = -offset;
while (x < lcd.Width)
{
lcd.DrawImage(x, (lcd.Height - sine.Height) / 2, sine, 0, 0, sine.Width, sine.Height);
x += sine.Width;
}

offset += 2;
if (offset >= sine.Width)
offset = 0;

lcd.DrawLine(Color.White, 1, 0, lcd.Height / 2, lcd.Width, lcd.Height / 2);
lcd.DrawLine(Color.White, 1, lcd.Width / 2, 0, lcd.Width / 2, lcd.Height);

lcd.Flush();