Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Help with a programming problem

Name: Anonymous 2007-09-22 1:38 ID:b7ylIByJ

I've been trying to do this for ages now, and it seems like it should be something with a really simple and elegant solution, but i can't find it. 

The problem:  I have a series of images, all with the same dimensions.  I am using two templates in order to combine these images into 1 overall image.  The two templates are as such, one combines them horizontally, one vertically. As images are combined, they are scaled appropriately to fit the canvas, and a number of iterations of these templates can take place. Link is to visual example of this.

http://img230.imageshack.us/img230/4391/templateexamplewa6.jpg

I've managed to somewhat acheive this through image manipulation, but i need to do it via sheer maths (processing speed).  An added problem is that like in iteration 3, there are 3 images in the row. They should all be 33% of the canvas width each, and image 2 should be 66%. 

Any help would be greatly appreciated, it has made my head hurt.  It's also possible my explanation blows, so feel free to ask questions.

Name: Anonymous 2007-09-22 3:29 ID:1FrTAxla

Damnit, now my head hurts too.

I'll be back in a bit after I get some aspirin.

Name: Anonymous 2007-09-22 3:35 ID:TD7lJb2T

Read SICP, section 2.2.4.

Name: Anonymous 2007-09-22 3:57 ID:1FrTAxla

Alright, here's the deal. Start with a canvas C containing an image. You will also have two variables W and H to keep track of how many times you've applied template 0 (increments W) and 1 (increments H). The pseudocode:

X <- 1
Y <- 1

C <- Canvas
W <- width of C
H <- height of C

function Template0(newImage):
    X <- X + 1
    copy C to tempImage
    scale tempImage width by (X-1)/X
    paste tempImage on C at (0,0)
    scale newImage width by 1/X
    paste newImage on C at (0,W-1/X)

Template1 is the same, just swap X for Y, H for W, etc.

I *think* that's what you wanted, anyway.

Name: Anonymous 2007-09-22 3:58 ID:1FrTAxla

... I'm an idiot. s/W/X/ and s/H/Y/ in the initial paragraph.

Name: Anonymous 2007-09-22 4:03 ID:Heaven

>>4
>>5
Wow, you're a fucking idiot. How about nested templates, like those in the OP's example image?

Name: Anonymous 2007-09-22 4:57 ID:b7ylIByJ

>>4

What you seem to be suggesting there is what I initially first tried - the image manipulation route.  Unfortunately this is impractical due to the time it takes to process, copy, paste, etc.  That is, if I've understood you correctly.

But thanks for trying anyways.

>>3

Just read it, and I'm not 100% clear on how this solves my problem.  I found it pretty hard to follow in general actually, could you elaborate on how this fits in?

Name: Anonymous 2007-09-22 5:06 ID:TD7lJb2T

>>7
Which part you don't understand? The picture language described in SICP does exactly what you're after and quite a bit more. You just need to supply your own low-level painter function that paints a specified single image in the given frame.

Name: Anonymous 2007-09-22 5:07 ID:Gt5fW6B5

In some bastardized ECMAScript:


// Read final dimensions
var pixel_width = input("Width: ");
var pixel_height = input("Height: ");

var templates = [];
var rows = 1;
var columns = 1;
templates.push({x:0, y:0, r:1, c:1});

// Read in templates
while (!eof(stdin)) {
  if (input("Template: ") == 0)
    columns++;
  else
    rows++;
  templates.push({x:columns, y:rows, r:rows, c:columns});
}

// Figure out dimensions for each cell
var cells = [];
for (var t = 0; t < templates.length; t++) {
  var c = {};
  c.pixel_x = templates[t].x / columns * pixel_width;
  c.pixel_y = templates[t].y / rows * pixel_height;
  c.pixel_w = templates[t].c / columns * pixel_width;
  c.pixel_h = templates[t].r / rows * pixel_height;
  cells.push(c);
}

// _Now_ worry about scaling and positioning images
// for each cell in the cells list.
// ...


How you want to scale things inside the cells is up to you.

Name: Anonymous 2010-12-17 1:31

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Anonymous 2010-12-17 1:40

This post brought to you by the Gay Nigger Association of America

Name: Anonymous 2011-02-04 12:09


Don't change these.
Name: Email:
Entire Thread Thread List