semesterarbeit cc1

Filed under uncategorized

Hey Jungs, es zeigt uns nicht das gewünschte Bild an. Was haben wir falsch gemacht?
danke und einen schönen sonntag noch

String textToDraw = “And through it all she offers me protection a lot of love and affection whether I‘m right or wrong and down the waterfall wherever it may take me I know that life won‘t break me when I come to call she won‘t forsake me I‘m loving angels instead”;
PImage bild;
PFont schrift;

void setup(){

size(1273, 900);

bild = loadImage(“flügel.jpg”);

schrift = loadFont(“Didot-Bold-20.vlw”);

textFont(schrift, 20);

noLoop();

}

void draw(){
background(255);

for (int y = 0; y < bild.height; y += textAscent()) {
for (int x = 0; x < bild.width; x++) {

// get the color at the current pixel
color c = bild.get(x, y);
// if the color is something else than a pure white
if (red(c) != 255 && green(c) != 255 && blue(c) != 255) {
// draw something at this position
fill(c);
text(textToDraw, x, y);
x += textWidth(textToDraw);
}
}
}

}

Antwort:

Hey, versucht mal diesen Code. An der Stele x += textWidth(textToDraw) wird immer die breite des kompletten Textes genommen. Das ist natürlich zu lang und breit. Versucht einmal, Textteile aus dem Text zu nehmen.

String textToDraw = “And through it all she offers me protection a lot of love and affection whether I‘m right or wrong and down the waterfall wherever it may take me I know that life won‘t break me when I come to call she won‘t forsake me I‘m loving angels instead”;
PImage bild;
PFont schrift;

void setup(){

size(1273, 900);

bild = loadImage(“flügel11.jpg”);

schrift = loadFont(“Serif-48.vlw”);

textFont(schrift, 20);

noLoop();

}

void draw(){
background(255);
// image(bild,0,0);
for (int y = 0; y < bild.height; y += textAscent()) {
for (int x = 0; x < bild.width; x++) {

// get the color at the current pixel
color c = bild.get(x, y);
// if the color is something else than a pure white
if (red(c) != 255 && green(c) != 255 && blue(c) != 255) {
// draw something at this position
fill(0);
text(“test”, x, y);
}
x += textWidth(“test”);
}
}

}

One Comment

  1. Posted 18/07/2010 at 17:55 | Permalink

    ihr müsst buchstabenweise durch den text gehen. wie das geht findet anbei.

    String textToDraw = “And through it all she offers me protection a lot of love and affection whether ” +
    “I‘m right or wrong and down the waterfall wherever it may take me I know that life won‘t break me when I come to call she won‘t forsake me I‘m loving angels instead”;

    PImage bild;
    PFont schrift;

    int i = 0; // we’ll use this to jump over each character for drawing individually

    void setup() {

    size(1273, 900);

    bild = loadImage(“flügel.jpg”);

    schrift = loadFont(“Didot-Bold-20.vlw”);

    textFont(schrift, 10);

    noLoop();
    }

    void draw() {
    background(255);
    // image(bild, 0, 0);
    for (int y = 0; y < bild.height; y += textAscent()) {
    for (int x = 0; x < bild.width; x++) {

    // get the color at the current pixel
    color c = bild.get(x, y);
    // if the color is something else than a pure white
    if (brightness(c) == 0) {
    // draw something at this position
    fill(c);

    // String.charAt gives you the character at a specific position in the String
    // i.e. "Hallo" -> charAt(2) -> ‘a’
    text(textToDraw.charAt(i), x, y);

    x += textWidth(textToDraw.charAt(i));
    i++; // increment i by 1 -> go to the next character
    i %= textToDraw.length(); // the ‘modulo’ operation makes sure values for ‘i’ are only within range of the number of characters in our string
    }
    }
    }
    }

    nun könnt ihr versuchen das prinzip zu verstehen und an der lesbarkeit zu arbeiten. das bild solltet ihr auch nochmal ein bisschen überarbeiten, da die schwarzen stellen ausserhalb der flügel dazu führen, dass dort auch buchstaben auftauchen.

    viel erfolg

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*