// Work in PRogress - todo put image map data into a texture and draw to screen - test conversion. // #define MAPWIDTH 800 #define MAPHEIGHT 450 #include "raylib.h" #include static int mapr[MAPWIDTH][MAPHEIGHT]; static int mapg[MAPWIDTH][MAPHEIGHT]; static int mapb[MAPWIDTH][MAPHEIGHT]; void mapsetcolor(int r,int g,int b); static float Clamp(float value, float min, float max); static void makelines(void); static void makelinesolid(float x,float y,float dist,int r,int g,int b); static void makelineshade(float x,float y,float dist); static void lightenrange(int low,int high); static void highsmoothrange(int low,int high,float perc); static void darkenrange(int low,int high,int ranval); static void smooth(); int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib example. Please wait with Slow computer!!"); RenderTexture2D target = LoadRenderTexture(MAPWIDTH, MAPHEIGHT); BeginTextureMode(target); ClearBackground(BLANK); // Make the entire Sprite Transparent. EndTextureMode(); mapsetcolor(255,255,255); makelines(); highsmoothrange(150,255,10); darkenrange(0,71,50); lightenrange(100,256); smooth(); BeginTextureMode(target); for(int y=0;y4 && beh<8) { angle-=GetRandomValue(1,15-1); if(angle<0)angle = 360-angle; x+=cos(angle); y+=sin(angle); } else { angle+=GetRandomValue(1,15-1); if(angle>359)angle = 0+angle; x+=cos(angle); y+=sin(angle); } if(x>-1 && y>-1 && x4 && beh<8){ angle-=GetRandomValue(1,15-1); if(angle<0)angle= 360-angle; x+=cos(angle); y+=sin(angle); } else { angle+=GetRandomValue(1,15-1); if(angle>359) angle = 0+angle; x+=cos(angle); y+=sin(angle); } if(x>-1 && y>-1 && x low && mapr[x1+x][y1+y] < high){ if(mapg[x1+x][y1+y] > low && mapg[x1+x][y1+y] < high){ if(mapb[x1+x][y1+y] > low && mapb[x1+x][y1+y] < high) { cnt+=1; } } } }} if(cnt>7){ mapr[x1][y1] = Clamp(mapr[x1][y1] + 20,0,255); mapg[x1][y1] = Clamp(mapg[x1][y1] + 20,0,255); mapb[x1][y1] = Clamp(mapb[x1][y1] + 20,0,255); } } } void highsmoothrange(int low,int high,float perc){ for(int i=0;i<(MAPWIDTH*MAPHEIGHT)*perc;i++){ int x=GetRandomValue(1,MAPWIDTH-1); int y=GetRandomValue(1,MAPHEIGHT-1); int r1=mapr[x][y]; int g1=mapg[x][y]; int b1=mapb[x][y]; int r2=mapr[x+1][y]; int g2=mapg[x+1][y]; int b2=mapb[x+1][y]; int r3=mapr[x][y+1]; int g3=mapg[x][y+1]; int b3=mapb[x][y+1]; int r4=mapr[x+1][y+1]; int g4=mapg[x+1][y+1]; int b4=mapb[x+1][y+1]; if(r1low && g1>low && b1>low){ int valr=((r1+r2+r3+r4)/4)*1.2; int valg=((g1+g2+g3+g4)/4)*1.2; int valb=((b1+b2+b3+b4)/4)*1.2; valr = Clamp(valr,0,255); valg = Clamp(valg,0,255); valb = Clamp(valb,0,255); mapr[x][y] = valr; mapg[x][y] = valg; mapb[x][y] = valb; }} } } void darkenrange(int low,int high,int ranval){ for(int y=0;y low){ mapr[x][y] -= GetRandomValue(ranval/2,ranval-1); mapg[x][y] -= GetRandomValue(ranval/2,ranval-1); mapb[x][y] -= GetRandomValue(ranval/2,ranval-1); } if(mapg[x][y] > low){ mapr[x][y] -= GetRandomValue(ranval/2,ranval-1); mapg[x][y] -= GetRandomValue(ranval/2,ranval-1); mapb[x][y] -= GetRandomValue(ranval/2,ranval-1); } if(mapb[x][y] > low){ mapr[x][y] -= GetRandomValue(ranval/2,ranval-1); mapg[x][y] -= GetRandomValue(ranval/2,ranval-1); mapb[x][y] -= GetRandomValue(ranval/2,ranval-1); } mapr[x][y] = Clamp(mapr[x][y],0,255); mapg[x][y] = Clamp(mapg[x][y],0,255); mapb[x][y] = Clamp(mapb[x][y],0,255); }} } void smooth(){ for( int i=0;i< (MAPWIDTH*MAPHEIGHT);i++){ int x=GetRandomValue(1,MAPWIDTH-1); int y=GetRandomValue(1,MAPHEIGHT-1); int col1r=mapr[x+1][y]; int col1g=mapg[x+1][y]; int col1b=mapb[x+1][y]; int col2r=mapr[x+1][y+1]; int col2g=mapg[x+1][y+1]; int col2b=mapb[x+1][y+1]; int col3r=mapr[x][y+1]; int col3g=mapg[x][y+1]; int col3b=mapb[x][y+1]; int col4r=(col1r+col2r+col3r)/3; int col4g=(col1g+col2g+col3g)/3; int col4b=(col1b+col2b+col3b)/3; mapr[x][y] = col4r; mapg[x][y] = col4g; mapb[x][y] = col4b; mapr[x][y] = Clamp(mapr[x][y],0,255); mapg[x][y] = Clamp(mapg[x][y],0,255); mapb[x][y] = Clamp(mapb[x][y],0,255); } } // Clamp float value float Clamp(float value, float min, float max) { const float res = value < min ? min : value; return res > max ? max : res; }