|
Post by matchy on Jan 20, 2014 20:58:58 GMT -8
It's been a couple of days and I'm try to get to grips with GD2.
When I try to plot pixels on the screen, the screen blanks after 1000 GD.Vertex2ii calls. Without clear, the whole screen vertical column fills up.
Q. How to keep the background bmp like with sketch but with points and text instead of touch? Q. How to plot each 480x272 pixel like for a Mandelbrot?
|
|
jls
Junior Member

Posts: 14
|
Post by jls on Jan 21, 2014 4:32:22 GMT -8
Yes good question.
I´m same problem for other fractal drawing.
Please example how to do.
Thanks Kamil
|
|
|
Post by jasonharper on Jan 21, 2014 4:54:31 GMT -8
Keep in mind that there are only 2K drawing commands allowed in the display list - you'll come nowhere near filling the screen, if you try to write each individual pixel with a separate command. Instead, you need to write your pixels into memory (in any of the many supported bitmap formats), set up one of the bitmap handles 0..14 to specify the address/size/format you chose for the bitmap data, then draw that bitmap to the screen with a single Vertex call. This is basically the same setup as the "sketch" demo uses, you'd just be using direct memory writes instead of cmd_sketch() to create pixels in the bitmap.
|
|
|
Post by matchy on Jan 21, 2014 5:42:16 GMT -8
Thanks for the explanation and but there are no source examples in the manual apart from the sketch demo.
|
|
|
Post by jamesbowman on Jan 21, 2014 8:13:26 GMT -8
Right.. here is a small sample I just wrote that sets up the whole screen as a framebuffer, in PALETTED mode, which should be good for the fractals. setpal() sets palette entry 'i' to a 32-bit ARGB color, and plot(x, y, i) sets a single pixel to index 'i'.
This approach uses about half of the available graphics memory, and you can still draw anything 'on top' of the framebuffer bitmap using regular drawing commands.
#include <EEPROM.h> #include <SPI.h> #include <GD2.h>
static void setpal(byte i, uint32_t argb) { GD.wr32(RAM_PAL + 4 * i, argb); }
static void plot(uint16_t x, uint16_t y, uint32_t i) { GD.wr(x + (480UL * y), i); }
void setup() { GD.begin(0); GD.cmd_memset(0, 0, 480UL * 272UL); GD.Clear(); GD.BitmapLayout(PALETTED, 480, 272); GD.BitmapSize(NEAREST, BORDER, BORDER, 480, 272); GD.BitmapSource(0); GD.Begin(BITMAPS); GD.Vertex2ii(0, 0); GD.swap(); GD.finish();
setpal(0, 0x00000000UL); for (int i = 1; i < 256; i++) setpal(i, 0xff000000UL | random(0x1000000)); }
void loop() { plot(random(480), random(272), GD.random(256)); }
|
|
jls
Junior Member

Posts: 14
|
Post by jls on Jan 21, 2014 10:29:40 GMT -8
Many thanks James
Working great :-)
My simple test - hopalong orbit fractal.
#include <EEPROM.h> #include <SPI.h> #include <GD2.h>
float a = 0.5; float b = -0.6; float c = 0.7; float x = 1; float y = 0;
int cnt,col;
static void setpal(byte i, uint32_t argb) { GD.wr32(RAM_PAL + 4 * i, argb); }
static void plot(uint16_t x, uint16_t y, uint32_t i) { GD.wr(x + (480UL * y), i); }
void setup() { GD.begin(0); GD.cmd_memset(0, 0, 480UL * 272UL); GD.Clear(); GD.BitmapLayout(PALETTED, 480, 272); GD.BitmapSize(NEAREST, BORDER, BORDER, 480, 272); GD.BitmapSource(0); GD.Begin(BITMAPS); GD.Vertex2ii(0, 0); GD.swap(); GD.finish();
setpal(0, 0x00000000UL); for (int i = 1; i < 256; i++) setpal(i, 0xff000000UL | random(0x1000000)); }
void loop() { float oldx = x; float oldy = y; x = oldy-(oldx/abs(oldx))*sqrt(abs(b*oldx-c)); y = a-oldx; if (cnt == 1500) { col = GD.random(256); cnt = 0; } cnt ++;
plot(239+(7*x), 136+(7*y), col); }
|
|
|
Post by jamesbowman on Jan 21, 2014 12:23:15 GMT -8
OK, added a check for offscreen coordinates in plot... looks good!
#include <EEPROM.h> #include <SPI.h> #include <GD2.h>
float a = 0.5; float b = -0.6; float c = 0.7; float x = 1; float y = 0;
int cnt; byte col = 1;
static void setpal(byte i, uint32_t argb) { GD.wr32(RAM_PAL + 4 * i, argb); }
static void plot(uint16_t x, uint16_t y, uint32_t i) { if ((x < 480) && (y < 272)) GD.wr(x + (480UL * y), i); }
void setup() { GD.begin(0); GD.cmd_memset(0, 0, 480UL * 272UL); GD.Clear(); GD.BitmapLayout(PALETTED, 480, 272); GD.BitmapSize(NEAREST, BORDER, BORDER, 480, 272); GD.BitmapSource(0); GD.Begin(BITMAPS); GD.Vertex2ii(0, 0); GD.swap(); GD.finish();
setpal(0, 0x00000000UL); for (int i = 1; i < 256; i++) setpal(i, 0xff000000UL | random(0x1000000)); }
void loop() { float oldx = x; float oldy = y;
x = oldy-(oldx/abs(oldx))*sqrt(abs(b*oldx-c)); y = a-oldx;
if (cnt++ == 1500) { col++; cnt = 0; }
plot(239 + (7 * x), 136 + (7 * y), col); }
|
|
jls
Junior Member

Posts: 14
|
Post by jls on Jan 21, 2014 12:40:03 GMT -8
Some questions
1. Is possible use vertex and bitmap drawing same time ?
2. Planning add other new function like bitmat plot(x,y,color) to your next GD2.h library ? Or support only original FTDI commands ?
Many thanks info
|
|
|
Post by matchy on Jan 22, 2014 7:49:49 GMT -8
Very useful example so thank-you! Now how about displaying lots of text, such as to be able to print like 60x24 or so fixed text (font 16 or 18) like for a screen terminal log?
Oh and a nice and interesting brot algo and different from the one I have.
#include <EEPROM.h> #include <SPI.h> #include <GD2.h>
byte brot_type = 0;
static void setpal(byte i, uint32_t argb) { GD.wr32(RAM_PAL + 4 * i, argb); }
static void plot(uint16_t x, uint16_t y, uint32_t i) { GD.wr(x + (480UL * y), i); }
void setup() { GD.begin(0); GD.cmd_memset(0, 0, 480UL * 272UL); GD.Clear(); GD.BitmapLayout(PALETTED, 480, 272); GD.BitmapSize(NEAREST, BORDER, BORDER, 480, 272); GD.BitmapSource(0); GD.Begin(BITMAPS); GD.Vertex2ii(0, 0); GD.swap(); GD.finish(); setpal(0, 0x00000000UL); for (int i = 1; i < 256; i++) setpal(i, 0xff000000UL | random(0x1000000)); }
void draw_mandlebrot() { float x0 = 0.0; float y0 = 0.0; float x = 0.0; float y = 0.0; float xtemp = 0.0; int iteration = 0; uint16_t plot_x; uint16_t plot_y; uint32_t plot_color;
brot_type++; if (brot_type > 1) brot_type = 0; for (plot_y = 0; plot_y < 272; plot_y++) { for (plot_x = 0; plot_x < 480; plot_x++) { x0 = plot_x; y0 = plot_y; x0 = (x0 / 100) - 2.5; y0 = (y0 / 60) - 2; x = 0.0; y = 0.0; xtemp = 0.0; iteration = 0; while ( x*x + y*y <= 4 && iteration < 9 ) { switch (brot_type) { case 0: xtemp = x*x - y*y + x0; y = 2*x*y + y0; break; case 1: xtemp = x*x*x - 3*x*y*y + x0; y = 3*x*x*y - y*y*y + y0; break; } x = xtemp; iteration++; } if ( x*x + y*y < 4 ) { plot_color = ((iteration % 8) * 16); } else { plot_color = (iteration % 8) * 16 + 128; } plot(plot_x, plot_y, plot_color); } } }
void loop() { draw_mandlebrot(); }
|
|
|
Post by legacy on Mar 22, 2014 8:06:39 GMT -8
i'd like to have these both features, too
|
|