wolframscience.com

A New Kind of Science: The NKS Forum : Powered by vBulletin version 2.3.0 A New Kind of Science: The NKS Forum > Pure NKS > k3 - run 2
Pages (2): « 1 [2]   Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
inhaesio zha


Registered: Oct 2005
Posts: 403

715

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:15 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

770

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:16 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

798

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:17 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

799

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:17 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

809

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:18 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

813

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:19 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

816

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:19 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

874

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:20 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

890

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:20 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

924

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:21 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

928

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:22 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

1015

inhaesio zha has attached this image:

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:22 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

#include <stdio.h>
#include <stdlib.h>

#include <jpeglib.h>

#define CELL_COUNT 256
#define ITERATION_COUNT 1024
#define STEP_COUNT 256

struct k3_cell_t {
unsigned char a;
unsigned char b;
unsigned char c;
};
typedef struct k3_cell_t k3_cell_t;

GLOBAL(void) write_JPEG_file(char *filename, int quality,
JSAMPLE *image_buffer, int image_height, int image_width)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE *outfile;
JSAMPROW row_pointer[1];
int row_stride;

cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);

if ((outfile = fopen(filename, "wb")) == NULL) {
fprintf(stderr, "can't open %s\n", filename);
exit(1);
}
jpeg_stdio_dest(&cinfo, outfile);

cinfo.image_width = image_width;
cinfo.image_height = image_height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);

jpeg_start_compress(&cinfo, TRUE);
row_stride = image_width * 3;

while (cinfo.next_scanline < cinfo.image_height) {
row_pointer[0] = &image_buffer[cinfo.next_scanline * row_stride];
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
}

jpeg_finish_compress(&cinfo);
fclose(outfile);

jpeg_destroy_compress(&cinfo);
}



int main(int argc, char *argv[])
{
unsigned long each_iteration;
k3_cell_t system[STEP_COUNT][CELL_COUNT];
unsigned short each_link;
k3_cell_t map[8];
unsigned short each_step;
unsigned short each_cell;
unsigned char in_a;
unsigned char in_b;
unsigned char in_c;
unsigned short previous_step;
unsigned char link_number;
unsigned int red;
unsigned int blue;
unsigned int green;

JSAMPLE *image_buffer;
char *filename;

image_buffer = malloc(sizeof(JSAMPLE) * CELL_COUNT * STEP_COUNT * 3);
filename = malloc(128);

srandom(128974);

for (each_iteration = 0; each_iteration < ITERATION_COUNT;
each_iteration++) {

for (each_link = 0; each_link < 8; each_link++) {
map[each_link].a = random() % 2;
map[each_link].b = random() % 2;
map[each_link].c = random() % 2;
}

if (0) {
for (each_cell = 0; each_cell < CELL_COUNT; each_cell++) {
system[0][each_cell].a = random() % 2;
system[0][each_cell].b = random() % 2;
system[0][each_cell].c = random() % 2;
}
} else {
for (each_cell = 0; each_cell < CELL_COUNT; each_cell++) {
system[0][each_cell].a = 0;
system[0][each_cell].b = 0;
system[0][each_cell].c = 0;
}
system[0][CELL_COUNT / 2].b = 1;
}

for (each_step = 1; each_step < STEP_COUNT; each_step++) {
previous_step = each_step - 1;
for (each_cell = 0; each_cell < CELL_COUNT; each_cell++) {
if (0 == each_cell) {
in_a = system[previous_step][CELL_COUNT - 1].c;
in_b = system[previous_step][each_cell].b;
in_c = system[previous_step][each_cell + 1].a;
} else if ((CELL_COUNT - 1) == each_cell) {
in_a = system[previous_step][each_cell - 1].c;
in_b = system[previous_step][each_cell].b;
in_c = system[previous_step][0].a;
} else {
in_a = system[previous_step][each_cell - 1].c;
in_b = system[previous_step][each_cell].b;
in_c = system[previous_step][each_cell + 1].a;
}
link_number = (in_a) + (in_b * 2) + (in_c * 4);
system[each_step][each_cell].a = map[link_number].a;
system[each_step][each_cell].b = map[link_number].b;
system[each_step][each_cell].c = map[link_number].c;
}
}

for (each_step = 0; each_step < STEP_COUNT; each_step++) {
for (each_cell = 0; each_cell < CELL_COUNT; each_cell++) {

/*
if (0 == system[each_step][each_cell].b) {
red = 4294967295;
green = 4294967295;
blue = 4294967295;
} else {
red = 0;
green = 0;
blue = 0;
}
*/

if (0 == system[each_step][each_cell].a) {
red = 4294967295;
} else {
red = 0;
}
if (0 == system[each_step][each_cell].b) {
green = 4294967295;
} else {
green = 0;
}
if (0 == system[each_step][each_cell].c) {
blue = 4294967295;
} else {
blue = 0;
}

image_buffer[(each_step * CELL_COUNT * 3)
+ (each_cell * 3) + 0] = red;
image_buffer[(each_step * CELL_COUNT * 3)
+ (each_cell * 3) + 1] = green;
image_buffer[(each_step * CELL_COUNT * 3)
+ (each_cell * 3) + 2] = blue;
}
}
sprintf(filename, "snapshots/k3.%04i.jpg", each_iteration);
write_JPEG_file(filename, 100, image_buffer, STEP_COUNT, CELL_COUNT);

}

free(filename);
}

Report this post to a moderator | IP: Logged

Old Post 02-08-2009 11:23 AM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
inhaesio zha


Registered: Oct 2005
Posts: 403

Attached, please find the source code from the previous post, as a .zip of a .c file...hopefully this eliminates mis-interpretation during browser text rendering, which seems may have been an issue (?).

Attachment: k3.zip
This has been downloaded 834 time(s).

Report this post to a moderator | IP: Logged

Old Post 02-09-2009 06:48 PM
inhaesio zha is offline Click Here to See the Profile for inhaesio zha Click here to Send inhaesio zha a Private Message Visit inhaesio zha's homepage! Edit/Delete Message Reply w/Quote
Post New Thread    Post A Reply
Pages (2): « 1 [2]   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread


 

wolframscience.com  |  wolfram atlas  |  NKS online  |  Wolfram|Alpha  |  Wolfram Science Summer School  |  web resources  |  contact us

Forum Sponsored by Wolfram Research

© 2004-14 Wolfram Research, Inc. | Powered by vBulletin 2.3.0 © 2000-2002 Jelsoft Enterprises, Ltd. | Disclaimer | Archives