We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys,
I try to realize some pattern out of the logo of my University. This is a small project for a programming class we have in our design degree. But since I'm a designer I encounter some problems to realize the idea. So I got the anchor points from our logo and made it to draw it out of an array with all the coordinates. That works quite well.
My next step now should be to draw the shape again but in smaller size inside the first one. That step I want to repeat several times. My professor suggested me something with the scale command and a variable to do this, but I can't figure out how to do it properly. Always I put the code in the resizing works, but I can't get it do display in the shape in smaller.
I would appreciate any help with code or idea what to do! :)
float[] rightshape = {111.8, 5.9, 111.8, 5.9, 62.8, 70.80000000000001, 62.8, 70.80000000000001, 62.8, 70.80000000000001, 62.8, 70.80000000000001, 62.599999999999994, 171.20000000000002, 62.599999999999994, 171.20000000000002, 62.599999999999994, 171.20000000000002, 62.599999999999994, 177.50000000000003, 67.6, 182.50000000000003, 73.89999999999999, 182.50000000000003, 73.89999999999999, 182.50000000000003, 73.89999999999999, 182.50000000000003, 73.89999999999999, 182.50000000000003, 73.89999999999999, 182.50000000000003, 73.89999999999999, 182.50000000000003, 80.1, 182.50000000000003, 85.19999999999999, 177.50000000000003, 85.19999999999999, 171.20000000000002, 85.19999999999999, 171.20000000000002, 85.19999999999999, 171.20000000000002, 85.39999999999999, 78.40000000000002, 85.39999999999999, 78.40000000000002, 85.39999999999999, 78.40000000000002, 85.39999999999999, 78.40000000000002, 111.79999999999998, 43.40000000000002, 111.79999999999998, 43.40000000000002, 111.79999999999998, 43.40000000000002, 111.79999999999998, 43.40000000000002, 111.79999999999998, 5.9, 111.79999999999998, 5.9, 111.79999999999998, 5.9, 111.79999999999998, 5.9, 111.8, 5.9, 111.8, 5.9};
float[] leftshape = {34.685, 136.132, 34.685, 136.132, 34.685, 59.888, 34.685, 59.888, 34.685, 59.888, 34.685, 59.888, 8.371, 27.128, 8.371, 27.128, 8.371, 27.128, 4.465, 22.253, 5.239000000000001, 15.152, 10.114, 11.239, 10.114, 11.239, 14.978, 7.329, 22.087, 8.111, 26, 12.97, 26, 12.97, 26, 12.97, 57.292, 51.942, 57.292, 51.942, 57.292, 51.942, 57.292, 51.942, 57.292, 136.132, 57.292, 136.132, 57.292, 136.132, 57.292, 142.36700000000002, 52.222, 147.434, 45.986000000000004, 147.434, 45.986000000000004, 147.434, 39.743, 147.433, 34.685, 142.367, 34.685, 136.132};
void setup() {
size(800, 600);
background(255);
println(rightshape);
//println(leftshape);
}
int size = 10;
float s = 1;
void draw() {
scale(s);
//s = s-0.3;
strokeWeight(2);
//translate(-50, -60);
translate(width/2, height/2);
//Draw the left part of the logo
//
for (int countleft = 0; countleft < 63; countleft = countleft+8) {
stroke(53, 37, 92);
bezier(leftshape[countleft], leftshape[countleft+1], leftshape[countleft+2], leftshape[countleft+3], leftshape[countleft+4], leftshape[countleft+5], leftshape[countleft+6], leftshape[countleft+7]);
}
//Draw the right part of the logo
for (int countright = 0; countright < 71; countright = countright+8) {
stroke(29, 112, 183);
bezier(rightshape[countright], rightshape[countright+1], rightshape[countright+2], rightshape[countright+3], rightshape[countright+4], rightshape[countright+5], rightshape[countright+6], rightshape[countright+7]);
}
}
Here is a small scribble how it should go together, in case you don't get from my description what I mean. http://www.dropbox.com/s/k78wv5s3lkqddkg/Foto 22.01.17, 14 04 17.jpg
Answers
remove the comment from line 18 and you'll see that there is repetition happening...
however, you'll notice that it's getting closer to the top left of the screen every time. this is because the position is also being scaled. (think about it, half of 111.8 is 55.9...). the way around this is to define the shape centred on the origin and translate the origin to the position you want. or you can leave it as is, and translate to the origin before scaling, translate back when done.
without line 18 it's just redrawing the same shape over and over again. and repeats forever, 60 times a second, because you haven't told it to ever stop.
this is terrible btw
@kr1schii -- you should read this related recent discussion thread:
It has many similar issues, including the need to find the center point of the shape before scaling.
thank you guys, helped me a lot to get something to work :)
@koogs I'm not a programmer, so I have no idea what exactly to change, I guess the way I get to the coordinates is not the best or most efficient structure? :P
bezier(leftshape[countleft], leftshape[countleft+1], leftshape[countleft+2], leftshape[countleft+3], leftshape[countleft+4], leftshape[countleft+5], leftshape[countleft+6], leftshape[countleft+7]);
Indeed it's ugly! :-& But it's the best efficient cache-friendly way to access an array! \m/
Haha okay, guess I can live with the ugly code haha :D But how would you make it in a nicer way?
it's more that you just got a lump of 72 numbers and are referring to them by their positions in clumps of 8. there's real no clue as to what you're doing that way.
even just defining the numbers in a more structured way as
would help (and there's no need to define those values to 8 decimal places!)
but they are actually pairs of coords, with duplicates, so you could use a PVector[] which would be clearer.
and don't forget to call noLoop() when you've done. no need to keep redrawing the same shape 60 times a second.
I see that the numbers are strangely repetitive. Maybe there is a pattern.
Right Shape clearly does show very high repetitiveness.
it's a bezier loop. for it to be continuous the starts of the one must be the ends of the previous. it also contains straight lines, which he's chosen to do by making the control points equal to the starts and / or ends.
Just posted it online using Pjs Mode @ https://OpenProcessing.org/sketch/400921. :bz
And here's the corresponding p5.js version using JS' Float32Array in place of Java's
float[]
: O:-)https://OpenProcessing.org/sketch/400949
https://developer.Mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
The method is very cache and cpu efficient, but not the easiest to understand. However, it still works, and that's enough I guess.
That looks indeed cleaner now and I think I could follow the advancements you made :)
Thank you all very much for the help! Much appreciated.