Thread: Question about C++ Graphics...

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    13

    Question about C++ Graphics...

    So far I've gotten my program to display a bunch of pixels in varying colors that appear randomly on a screen. I was wondering if it is possible to have the pixels move downward, kind of like you're moving forward in space in a spaceship. This is my program so far, it's very simplistic but does what I need it to.

    Code:
    #include <conio.h>
    #include <graphics.h>
    #include <dos.h>
    #include <stdlib.h>
    
    int main() {
        int gd = DETECT, gm;
        int i, x, y;
        initgraph(&gd, &gm, "C:\\TC\\BGI");
        initwindow(1200, 768);
    
          /* color 500 random pixels on screen */
       for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,1);
          }
    
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,2);
          }
    
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,3);
          }
    
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,4);
          }
    
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,5);
          }
    
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,6);
          }
    
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,7);
          }
    
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,8);
          }
    
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,9);
          }
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,9);
          }
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,10);
          }
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,11);
          }
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,12);
          }
          for(i=0; i<=125; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,13);
          }
          for(i=0; i<=100; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,14);
          }
    
          for(i=0; i<=900; i++) {
           x=rand()%getmaxx();
              y=rand()%getmaxy();
              putpixel(x,y,15);
          }
    
        getch();
        closegraph();
        return 0;
    }
    Any help would be greatly appreciated.
    Last edited by Nick Ryder; 01-11-2018 at 11:04 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    Code:
    struct point {
        int x,y,colour;
    };
    Create an array of those.
    Use a loop to fill the array.
    Use a loop to draw it.
    Use a loop to move points in some manner.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Graphics Question
    By kas2002 in forum C Programming
    Replies: 0
    Last Post: 05-24-2006, 12:38 PM
  2. graphics question
    By fatoomi in forum Game Programming
    Replies: 0
    Last Post: 07-26-2004, 02:02 PM
  3. Graphics question.
    By BlueWizard in forum C++ Programming
    Replies: 1
    Last Post: 01-21-2004, 02:03 PM
  4. graphics card question
    By dP munky in forum Tech Board
    Replies: 4
    Last Post: 01-09-2003, 09:05 PM
  5. Graphics.h question
    By Paninaro in forum Game Programming
    Replies: 2
    Last Post: 06-28-2002, 11:39 AM

Tags for this Thread