Activeworlds Forums

Go Back   Activeworlds Forums > World Management Zone > Terrain and Landscapes

Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old 10-21-2009, 07:24 PM
Talisan's Avatar
Talisan Talisan is offline
Spherical
 
Join Date: Mar 1999
Location: Winter
Posts: 2,192
Blog Entries: 7
Send a message via AIM to Talisan Send a message via MSN to Talisan
Default

Quote:
Originally Posted by Byte View Post
...
Code:
int myRandom(int range_min, int range_max)
{
    return (rand() % ((range_max - range_min) + 1)) + range_min;
}
Not only do you eliminate the costly, and useless cast to a double type, but you remove the multiplication and division.
Hey thanks Its a small program, but saving ticks is always welcome. I changed it in my common library as well.

...waiting for the other shoe to drop...
__________________
Everyone can build in Winter and all citizens have v4 rights!
Begin your own Winter village, secret hideout, nature preserve or your hearts desire!
There is a vast array of open land in this unique building environment.
All the familiar objects of Alpha, with the unique objects of Winter.
Don't like blinding snow? Just click on some Shades and find quick access to Ladybunnys OY and MaXPolys new OY.
Need a more current list of assets? Just visit virlands.com/winter/materials.php
Reply With Quote
  #12  
Old 10-21-2009, 08:22 PM
Byte's Avatar
Byte Byte is offline
Codemancer
 
Join Date: Mar 1998
Location: Wyoming
Posts: 970
Blog Entries: 3
Default

Quote:
Originally Posted by Talisan View Post
Hey thanks Its a small program, but saving ticks is always welcome. I changed it in my common library as well.

...waiting for the other shoe to drop...
I always enjoy seeing how compactly I can write something in C/C++. Most of it isn't readable, but I've learned a lot in the process.
__________________
Become a fan of AWGames on Facebook today!

--

http://www.theenginerd.com/ - Random programming stuff and tools for AW
Reply With Quote
  #13  
Old 10-22-2009, 03:51 AM
Talisan's Avatar
Talisan Talisan is offline
Spherical
 
Join Date: Mar 1999
Location: Winter
Posts: 2,192
Blog Entries: 7
Send a message via AIM to Talisan Send a message via MSN to Talisan
Default Goofy, but it works!

Well, finally figured it out and got a Times font to work. Made it much nicer. Thanks for the ideas and help!

I hardcoded Y to 85 because I was getting really odd results, but it didn't matter since Y shouldn't change anyways for a given font size. This uses the Windows GD lib, the Windows Freetype Lib, and I used the DEV C++ IDE/gcc compiler.

Code:
 
#include <stdio.h>
#include <stdlib.h>
#include <gd.h>
#define IMG_DIMENSION 128
#define FONT_SIZE      50.0
#define MAX_TERRAIN   501
int myRandom(int range_min, int range_max)
{return (rand() % ((range_max - range_min) + 1)) + range_min;}
int main(int argc, char *argv[])
{
    gdImagePtr im;
    FILE  *fp;
    int   imgcount =0;
    int   imgcolor =0;
    int   black    =0;
    int   white    =0;
    int   numc     =0;
    int   offset   =0;
    int   *err;
    int   brect[8];
    int   x, y     =0;
    char  text[10];
    char  filename[32];
    char  *f = "times.ttf";
 
    srand(time(NULL));
    rand();
 
    im = gdImageCreateTrueColor(IMG_DIMENSION,IMG_DIMENSION); //create image space
    if (!im) {printf("Cannot create image.\n");return 1;}
    black = gdImageColorAllocate(im, 12, 12, 12); //shadow
    white = gdImageColorAllocate(im, 255, 255, 255); //foreground
 
    do { //***Main Loop
      imgcolor = gdImageColorAllocate(im,myRandom(16,64),myRandom(100,222),myRandom(16,64));
      gdImageFilledRectangle(im,0,0,IMG_DIMENSION,IMG_DIMENSION,imgcolor);
      imgcolor = gdImageColorAllocate(im,myRandom(16,222),myRandom(16,222),myRandom(16,222));
      gdImageFilledRectangle(im,13,13,IMG_DIMENSION-14,IMG_DIMENSION-14,imgcolor);
 
      sprintf(text,"%d",imgcount); //change int to string
 
      err = gdImageStringFT(NULL,&brect[0],0,f,FONT_SIZE,0.0,0,0,text); //NULL, we only want to fill brect[]!
      if (err) {printf("Cannot create font image.\n");return 1;}
 
      x = 2+(IMG_DIMENSION-(brect[2]-brect[6]))/2;
      y = 85; //(IMG_DIMENSION-(brect[3]-brect[7]))/2; <---GOOOFY results!
      err = gdImageStringFT(im,&brect[0],black,f,FONT_SIZE,0.0,x,y,text); //shadow
      if (err) {printf("Cannot create font image.\n");return 1;}
      err = gdImageStringFT(im,&brect[0],white,f,FONT_SIZE,0.0,x-1,y-1,text); //white
      if (err) {printf("Cannot create font image.\n");return 1;}
 
      sprintf(filename,"terrain%d.jpg",imgcount);
      fp = fopen(filename, "wb");
      if (!fp) {
               printf("Cannot open terrain%d.jpg for writing.\n",imgcount);
               return 1;
               }
      gdImageJpeg(im, fp, 100);
      fclose(fp);
      imgcount++;
    } while(imgcount < MAX_TERRAIN); //***End Main Loop
 
    gdImageDestroy(im); //destroy image space
 
    printf("done.");
    system("PAUSE");
    return 0;
}
__________________
Everyone can build in Winter and all citizens have v4 rights!
Begin your own Winter village, secret hideout, nature preserve or your hearts desire!
There is a vast array of open land in this unique building environment.
All the familiar objects of Alpha, with the unique objects of Winter.
Don't like blinding snow? Just click on some Shades and find quick access to Ladybunnys OY and MaXPolys new OY.
Need a more current list of assets? Just visit virlands.com/winter/materials.php
Reply With Quote
  #14  
Old 10-22-2009, 03:59 AM
Talisan's Avatar
Talisan Talisan is offline
Spherical
 
Join Date: Mar 1999
Location: Winter
Posts: 2,192
Blog Entries: 7
Send a message via AIM to Talisan Send a message via MSN to Talisan
Default

An idea of what they look like from that code.
500 generic numbered terrain Download 3.4Mb

__________________
Everyone can build in Winter and all citizens have v4 rights!
Begin your own Winter village, secret hideout, nature preserve or your hearts desire!
There is a vast array of open land in this unique building environment.
All the familiar objects of Alpha, with the unique objects of Winter.
Don't like blinding snow? Just click on some Shades and find quick access to Ladybunnys OY and MaXPolys new OY.
Need a more current list of assets? Just visit virlands.com/winter/materials.php
Reply With Quote
  #15  
Old 10-22-2009, 06:51 PM
S E V E N S S E V E N S is offline
Banned
 
Join Date: Jun 2005
Location: ‹^› ‹(•¿•)› ‹^›
Posts: 4,705
Blog Entries: 49
Send a message via MSN to S E V E N S Send a message via Yahoo to S E V E N S
Default

Nice Work
Reply With Quote
Reply

Tags
talisan, terrain, terrain tools

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -3. The time now is 07:18 PM.