Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | bilsch <king621@comcast.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: strange problem |
| Date | 2015-03-23 21:21 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <meq04j$be9$1@dont-email.me> (permalink) |
| References | <mensmn$rrs$1@dont-email.me> <menvoi$t61$1@dont-email.me> <meoivf$rrs$2@dont-email.me> <meol0s$r1n$2@dont-email.me> |
Here's the whole program. It uses SDL2 library for graphics.
/* program sinexx.cpp 3/22/15. compile: g++ sinexx.cpp -o sinexx -std=c+
+11 -Wall -lSDL2 */
#include <SDL2/SDL.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#define PI 3.14159
static int display_in_use = 0; // Only using first display
SDL_DisplayMode vmode; // display mode structure
int maxx=0, maxy=0, delay, lcount=1, restart=0, n1=0, n2=0, flag1=0,
flag2=0;
int glength, mode, x2, y2, c1=0, c2=0, c3=255;
float f1, f2, f3, y, a1=0.003, a2=4.1946, t, k1=1.0;
int rgb[12]={0,0,255,204,0,204,255,0,153,204,0,204}; //color rgb
triplets
int main(int argc, char *argv[]){
if(argv[1] == NULL)
//if(argc < 2)
{ delay=1;
glength = 666;
mode = 2;
k1 = 1.0; }
else
x200:; {
printf("delay between pixel plotting: ");
scanf("%d", &delay);
printf("graph length in pixels x 111: ");
scanf("%d", &glength);
glength = 111 * glength;
printf("enter 1 for window, enter 2 for full screen: ");
scanf("%d", &mode);
if (mode < 1)
mode = 1; //accepts any integer, converts to range
if (mode > 1)
mode = 2;
printf("scaling factor: ");
scanf("%f", &k1);
}
SDL_Init(SDL_INIT_VIDEO);
//SDL_GetDisplayMode(display_in_use, 0, &vmode);
//vmode.w = maxx; //max x pixel
//vmode.h = maxy; //max y pixel
//if (mode == 1)
//SDL_Window *win1 = SDL_CreateWindow("", 0, 0, 640, 480,
SDL_WINDOW_SHOWN);
//if (mode == 2)
//SDL_Window *win1 = SDL_CreateWindow("", 0, 0, maxx, maxy,
SDL_WINDOW_SHOWN);
SDL_Window *win1 = NULL;
if (mode == 1)
win1 = SDL_CreateWindow("", 0, 0, 640, 480, SDL_WINDOW_SHOWN);
if (mode == 2)
win1 = SDL_CreateWindow("", 0, 0, 1366, 768, SDL_WINDOW_SHOWN);
// win1 = SDL_CreateWindow("", 0, 0, maxx, maxy, SDL_WINDOW_SHOWN);
SDL_Renderer* ren = NULL;
ren = SDL_CreateRenderer( win1, 0, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor( ren, 0, 0, 0, 255 ); //set render to black for
background
SDL_RenderClear( ren ); // Clear window
SDL_Event event; // The event structure
while(1)
{
if(SDL_PollEvent(&event) != 0 ) //SDL_PE = 1 if key hit
{ const Uint8 *state = SDL_GetKeyboardState(NULL);
if (state[SDL_SCANCODE_RETURN])
goto x100; // quit if return key hit
if (state[SDL_SCANCODE_BACKSLASH])
{ restart = 1; //restart flag
goto x100;
}
}
flag1 = 0;
flag2 = 0;
while (flag1 == 0) // flag1=1 black pxl plotted glength
pxl behind color pxl
{if (flag2 == 0) // flag2=1 means color pxl plotted
{t = k1*(lcount+glength);
// c3 = 255;
flag2 = 1;
}
else
{ t = k1*lcount;
c1 = 0;
c2 = 0;
c3 = 0;
flag1 = 1;
}
f1 = sin(a1*PI*t);
f2 = sin(a2*a1*PI*t);
f3 = f1 + f2;
y = exp(-f3);
if(mode==1)
{ x2 = (int)((200 * f1)+350);
y2 = (int)(60 * y);
}
else
{
x2 = (int)((500 * f1)+650); // scale up for full
screen
y2 = (int)(80 * y)+80;
}
SDL_SetRenderDrawColor(ren,c1,c2,c3,255); // plot pixels
SDL_RenderDrawPoint(ren,x2,y2);
SDL_RenderPresent(ren);
} // end of while(flag1) loop
SDL_Delay(delay); // delay between pixels
lcount++;
if (lcount == 10000)
{lcount=1;
SDL_SetRenderDrawColor( ren, 0, 0, 0, 255 ); // clears the screen
after 10,000 pixels
SDL_RenderClear(ren);
}
c1=rgb[(3*n1)+0]; // gets shades from array
c2=rgb[(3*n1)+1];
c3=rgb[(3*n1)+2];
n2++;
if(n2==15) // 15 pixels per shade
{n2=0;
n1++;}
if(n1==4) // 4 shades in array
n1=0;
} // end of while(1) loop
x100:;
SDL_DestroyRenderer(ren); // clean up
SDL_DestroyWindow(win1);
SDL_Quit();
if(restart==1) // restart=0 goes to end
{restart=0;
goto x200;
}
}
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
strange problem bilsch <king621@comcast.net> - 2015-03-23 02:10 +0000
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 03:03 +0000
Re: strange problem Keith Thompson <kst-u@mib.org> - 2015-03-22 22:09 -0700
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 09:04 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 08:30 +0000
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 09:06 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 21:21 +0000
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 21:42 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 22:35 +0000
Re: strange problem Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-24 12:20 -0700
Re: strange problem Keith Thompson <kst-u@mib.org> - 2015-03-23 15:23 -0700
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 23:14 +0000
Re: strange problem Keith Thompson <kst-u@mib.org> - 2015-03-23 17:10 -0700
Re: strange problem glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-03-23 03:03 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 08:37 +0000
Re: strange problem raltbos@xs4all.nl (Richard Bos) - 2015-03-23 09:37 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 21:27 +0000
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 21:43 +0000
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 22:36 +0000
Re: strange problem Keith Thompson <kst-u@mib.org> - 2015-03-23 17:09 -0700
Re: strange problem JohnF <john@please.see.sig.for.email.com> - 2015-03-23 13:02 +0000
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-23 13:10 +0000
Re: strange problem Robert Wessel <robertwessel2@yahoo.com> - 2015-03-23 19:18 -0500
Re: strange problem Richard Heathfield <rjh@cpax.org.uk> - 2015-03-24 00:28 +0000
Re: strange problem Robert Wessel <robertwessel2@yahoo.com> - 2015-03-23 19:38 -0500
Re: strange problem jt@toerring.de (Jens Thoms Toerring) - 2015-03-24 01:12 +0000
Re: strange problem Keith Thompson <kst-u@mib.org> - 2015-03-23 08:10 -0700
Re: strange problem Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-03-23 11:28 -0400
Re: strange problem bilsch <king621@comcast.net> - 2015-03-23 21:47 +0000
Re: strange problem Kaz Kylheku <kaz@kylheku.com> - 2015-03-23 21:53 +0000
Re: strange problem Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-03-23 18:34 -0400
Re: strange problem James Kuyper <jameskuyper@verizon.net> - 2015-03-23 18:58 -0400
Re: strange problem raltbos@xs4all.nl (Richard Bos) - 2015-03-23 09:54 +0000
Re: strange problem Kaz Kylheku <kaz@kylheku.com> - 2015-03-23 21:47 +0000
csiph-web