Menu

EX1

Anonymous

Please note that the schematic.h and TVOlogo.h files link in the bitmaps which are not shown here.

#include <TVout.h>
#include <fontALL.h>
#include "schematic.h"
#include "TVOlogo.h"

TVout TV;

int zOff = 150;
int xOff = 0;
int yOff = 0;
int cSize = 50;
int view_plane = 64;
float angle = PI/60;

float cube3d[8][3] = {
  {xOff - cSize,yOff + cSize,zOff - cSize},
  {xOff + cSize,yOff + cSize,zOff - cSize},
  {xOff - cSize,yOff - cSize,zOff - cSize},
  {xOff + cSize,yOff - cSize,zOff - cSize},
  {xOff - cSize,yOff + cSize,zOff + cSize},
  {xOff + cSize,yOff + cSize,zOff + cSize},
  {xOff - cSize,yOff - cSize,zOff + cSize},
  {xOff + cSize,yOff - cSize,zOff + cSize}
};
unsigned char cube2d[8][2];

void setup() {
  TV.begin(NTSC,120,96);
  TV.select_font(font6x8);
  intro();
  TV.println("I am the TVout\nlibrary running on a freeduino\n");
  TV.delay(2500);
  TV.println("I generate a PAL\nor NTSC composite  video using\ninterrupts\n");
  TV.delay(2500);
  TV.println("My schematic:");
  TV.delay(1500);
  TV.bitmap(0,0,schematic);
  TV.delay(10000);
  TV.clear_screen();
  TV.println("Lets see what\nwhat I can do");
  TV.delay(2000);

  //fonts
  TV.clear_screen();
  TV.println(0,0,"Multiple fonts:");
  TV.select_font(font4x6);
  TV.println("4x6 font FONT");
  TV.select_font(font6x8);
  TV.println("6x8 font FONT");
  TV.select_font(font8x8);
  TV.println("8x8 font FONT");
  TV.select_font(font6x8);
  TV.delay(2000);

  TV.clear_screen();
  TV.print(9,44,"Draw Basic Shapes");
  TV.delay(2000);

  //circles
  TV.clear_screen();
  TV.draw_circle(TV.hres()/2,TV.vres()/2,TV.vres()/3,WHITE);
  TV.delay(500);
  TV.draw_circle(TV.hres()/2,TV.vres()/2,TV.vres()/2,WHITE,INVERT);
  TV.delay(2000);

  //rectangles and lines
  TV.clear_screen();
  TV.draw_rect(20,20,80,56,WHITE);
  TV.delay(500);
  TV.draw_rect(10,10,100,76,WHITE,INVERT);
  TV.delay(500);
  TV.draw_line(60,20,60,76,INVERT);
  TV.draw_line(20,48,100,48,INVERT);
  TV.delay(500);
  TV.draw_line(10,10,110,86,INVERT);
  TV.draw_line(10,86,110,10,INVERT);
  TV.delay(2000);

  //random cube forever.
  TV.clear_screen();
  TV.print(16,40,"Random Cube");
  TV.print(28,48,"Rotation");
  TV.delay(2000);

  randomSeed(analogRead(0));
}

void loop() {
  int rsteps = random(10,60);
  switch(random(6)) {
    case 0:
      for (int i = 0; i < rsteps; i++) {
        zrotate(angle);
        printcube();
      }
      break;
    case 1:
      for (int i = 0; i < rsteps; i++) {
        zrotate(2*PI - angle);
        printcube();
      }
      break;
    case 2:
      for (int i = 0; i < rsteps; i++) {
        xrotate(angle);
        printcube();
      }
      break;
    case 3:
      for (int i = 0; i < rsteps; i++) {
        xrotate(2*PI - angle);
        printcube();
      }
      break;
    case 4:
      for (int i = 0; i < rsteps; i++) {
        yrotate(angle);
        printcube();
      }
      break;
    case 5:
      for (int i = 0; i < rsteps; i++) {
        yrotate(2*PI - angle);
        printcube();
      }
      break;
  }
}

void intro() {
unsigned char w,l,wb;
  int index;
  w = pgm_read_byte(TVOlogo);
  l = pgm_read_byte(TVOlogo+1);
  if (w&7)
    wb = w/8 + 1;
  else
    wb = w/8;
  index = wb*(l-1) + 2;
  for ( unsigned char i = 1; i < l; i++ ) {
    TV.bitmap((TV.hres() - w)/2,0,TVOlogo,index,w,i);
    index-= wb;
    TV.delay(50);
  }
  for (unsigned char i = 0; i < (TV.vres() - l)/2; i++) {
    TV.bitmap((TV.hres() - w)/2,i,TVOlogo);
    TV.delay(50);
  }
  TV.delay(3000);
  TV.clear_screen();
}

void printcube() {
  //calculate 2d points
  for(byte i = 0; i < 8; i++) {
    cube2d[i][0] = (unsigned char)((cube3d[i][0] * view_plane / cube3d[i][2]) + (TV.hres()/2));
    cube2d[i][1] = (unsigned char)((cube3d[i][1] * view_plane / cube3d[i][2]) + (TV.vres()/2));
  }
  TV.delay_frame(1);
  TV.clear_screen();
  draw_cube();
}

void zrotate(float q) {
  float tx,ty,temp;
  for(byte i = 0; i < 8; i++) {
    tx = cube3d[i][0] - xOff;
    ty = cube3d[i][1] - yOff;
    temp = tx * cos(q) - ty * sin(q);
    ty = tx * sin(q) + ty * cos(q);
    tx = temp;
    cube3d[i][0] = tx + xOff;
    cube3d[i][1] = ty + yOff;
  }
}

void yrotate(float q) {
  float tx,tz,temp;
  for(byte i = 0; i < 8; i++) {
    tx = cube3d[i][0] - xOff;
    tz = cube3d[i][2] - zOff;
    temp = tz * cos(q) - tx * sin(q);
    tx = tz * sin(q) + tx * cos(q);
    tz = temp;
    cube3d[i][0] = tx + xOff;
    cube3d[i][2] = tz + zOff;
  }
}

void xrotate(float q) {
  float ty,tz,temp;
  for(byte i = 0; i < 8; i++) {
    ty = cube3d[i][1] - yOff;
    tz = cube3d[i][2] - zOff;
    temp = ty * cos(q) - tz * sin(q);
    tz = ty * sin(q) + tz * cos(q);
    ty = temp;
    cube3d[i][1] = ty + yOff;
    cube3d[i][2] = tz + zOff;
  }
}

void draw_cube() {
  TV.draw_line(cube2d[0][0],cube2d[0][1],cube2d[1][0],cube2d[1][1],WHITE);
  TV.draw_line(cube2d[0][0],cube2d[0][1],cube2d[2][0],cube2d[2][1],WHITE);
  TV.draw_line(cube2d[0][0],cube2d[0][1],cube2d[4][0],cube2d[4][1],WHITE);
  TV.draw_line(cube2d[1][0],cube2d[1][1],cube2d[5][0],cube2d[5][1],WHITE);
  TV.draw_line(cube2d[1][0],cube2d[1][1],cube2d[3][0],cube2d[3][1],WHITE);
  TV.draw_line(cube2d[2][0],cube2d[2][1],cube2d[6][0],cube2d[6][1],WHITE);
  TV.draw_line(cube2d[2][0],cube2d[2][1],cube2d[3][0],cube2d[3][1],WHITE);
  TV.draw_line(cube2d[4][0],cube2d[4][1],cube2d[6][0],cube2d[6][1],WHITE);
  TV.draw_line(cube2d[4][0],cube2d[4][1],cube2d[5][0],cube2d[5][1],WHITE);
  TV.draw_line(cube2d[7][0],cube2d[7][1],cube2d[6][0],cube2d[6][1],WHITE);
  TV.draw_line(cube2d[7][0],cube2d[7][1],cube2d[3][0],cube2d[3][1],WHITE);
  TV.draw_line(cube2d[7][0],cube2d[7][1],cube2d[5][0],cube2d[5][1],WHITE);
}

Related

Wiki: EXsketches
Wiki: TableOfContents

Discussion

  • Anonymous

    Anonymous - 2011-02-28

    Originally posted by: vb61...@gmail.com

    Can you make a code for arduino mega. i cant seem to be able to make mine work. im using arduino mega atmega1280

     
  • Anonymous

    Anonymous - 2012-08-16

    Originally posted by: iy...@hotmail.com

    I have the same problem...

     
  • Anonymous

    Anonymous - 2012-08-16

    Originally posted by: iy...@hotmail.com

    Also, it says that 'TVout' does not name a type

     
  • Anonymous

    Anonymous - 2012-10-13

    Originally posted by: queen.ra...@gmail.com

    Here is the arduino logo I've created if you want to use it.

    TV.draw_circle(TV.hres()/2-18,TV.vres()/2,20,WHITE,WHITE); TV.draw_circle(TV.hres()/2+18,TV.vres()/2,20,WHITE,WHITE); TV.draw_circle(TV.hres()/2-18,TV.vres()/2,17,WHITE,BLACK); TV.draw_circle(TV.hres()/2+18,TV.vres()/2,17,WHITE,BLACK); TV.draw_rect(TV.hres()/2-24,TV.vres()/2-2,12,4,WHITE,WHITE); TV.draw_rect(TV.hres()/2+12,TV.vres()/2-2,12,4,WHITE,WHITE); TV.draw_rect(TV.hres()/2+16,TV.vres()/2-6,4,12,WHITE,WHITE); TV.select_font(font8x8); TV.println(TV.hres()/2-28,TV.vres()/2+25,"ARDUINO");

     
  • Anonymous

    Anonymous - 2013-03-20

    Originally posted by: jonas.la...@gmail.com

    thx for the logo, works excellent

     
  • Anonymous

    Anonymous - 2014-01-01

    Originally posted by: dcurr...@gmail.com

    I got it to work but it is off-centered on the screen.... I see the beginning of each sentence on the far right then it continues from the far left. where do i adjust the output

     
  • Anonymous

    Anonymous - 2014-05-20

    Originally posted by: miggleli...@gmail.com

    I am also getting this error- is there a fix or a code repair?

    DemoPAL.pde:6: error: 'TVout' does not name a type DemoPAL.pde: In function 'void setup()': DemoPAL.pde:29: error: 'TV' was not declared in this scope DemoPAL.pde:29: error: 'PAL' was not declared in this scope DemoPAL.pde:30: error: 'font6x8' was not declared in this scope DemoPAL.pde:47: error: 'font4x6' was not declared in this scope DemoPAL.pde:51: error: 'font8x8' was not declared in this scope DemoPAL.pde:62: error: 'WHITE' was not declared in this scope DemoPAL.pde:64: error: 'INVERT' was not declared in this scope DemoPAL.pde: In function 'void intro()': DemoPAL.pde:142: error: 'TV' was not declared in this scope DemoPAL.pde:146: error: 'TV' was not declared in this scope DemoPAL.pde:150: error: 'TV' was not declared in this scope DemoPAL.pde: In function 'void printcube()': DemoPAL.pde:157: error: 'TV' was not declared in this scope DemoPAL.pde:160: error: 'TV' was not declared in this scope DemoPAL.pde: In function 'void draw_cube()': DemoPAL.pde:205: error: 'TV' was not declared in this scope DemoPAL.pde:205: error: 'WHITE' was not declared in this scope

     
  • Anonymous

    Anonymous - 2014-05-20

    Originally posted by: miggleli...@gmail.com

    This is using the PAL demo on an UNO board

     
  • Anonymous

    Anonymous - 2014-10-10

    Originally posted by: charlesv...@gmail.com

    TV.print does not work. How library you are using ?

     

    Last edit: Anonymous 2017-02-21

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.