2012-09-19 16 views
5

मेरे पास निम्न कोड है जो पाठ को घुमाने के लिए ऑनलाइन उदाहरण से अनुकूलित किया गया है। कोड ठीक काम करता है कि यह पाठ को सही कोण पर घुमाता है, लेकिन मुझे पता चलेगा कि घुमावदार पाठ की सटीकता और कुरकुरापन में सुधार करने का कोई तरीका है या नहीं। मेरे प्रदर्शन पर ऐसा लगता है कि घुमावदार पाठ चिकनी के बजाय 'stepped' है।घुमावदार पाठ के प्रदर्शन में सुधार

PFont f; 
String message = "abcdefghijklmnopqrstuvwxyz"; 
float theta, x; 

void setup() { 
    size(800, 200); 
    f = createFont("Arial",20,true); 
} 

void draw() { 
// background(255); 
    fill(0); 
    textFont(f); // Set the font 
    translate(x,height/2); // Translate to the center 
    rotate(theta);    // Rotate by theta 
    textAlign(LEFT);    
    text(message,0,0);    
    theta += 0.1;    // Increase rotation 
    x += textWidth(message); 
    if (x>800){noLoop(); } 
} 

मैंने अंतर प्रदर्शित करने में मदद के लिए उदाहरण के साथ संशोधन किया है। नए कोड में मैंने पाठ को अंडरस्कोर की स्ट्रिंग में बदल दिया है और लाल रंग में रेफरेंस लाइन भी खींची है। यदि यह आपकी मशीन पर समान काम करता है तो आपको अंडरस्कोर द्वारा बनाई गई ब्लैक लाइन में एक चौंकाने वाला दिखना चाहिए।

String message = "________"; 
float theta, x; 
PFont f; 

void setup() { 
    size(800, 200); 
    f = loadFont("ArialMT-20.vlw"); 
    smooth(); 
} 

void draw() { 
    fill(0); 
    textFont(f); // Set the font 

    translate(x,height/2); // Translate to the center 
    rotate(theta);    // Rotate by theta 

    text(message,0,0); 

    stroke(255,0,0); 
    strokeWeight(2); 
    line(0,0,textWidth(message),0); 

    theta += 0.1;    // Increase rotation 
    x += textWidth(message); 
    if (x>800){noLoop(); } 
} 

मेरे लिए यह निम्न उत्पादन देता है, लेकिन मैं जानता हूँ कि किसी Mac चलाने अगर यह अलग होगा:

enter image description here

+1

जल्द से जल्द बेहतर सहायता के लिए, एक [एसएससीसीई] (http://sscce.org/) पोस्ट करें। –

+1

शायद आप एंटी-एलिसिंग की तलाश में हैं? http://www.universalwebservices.net/web-programming-resources/java/anti-aliasing-creating-anti-alias-text-in-java – dbalakirev

+0

मुझे यह उल्लेख करना चाहिए था कि यह प्रसंस्करण.org कोड है इसलिए कॉपी करना संभव है और आईडीई में पेस्ट करें और चलाएं। आप सही हैं, मैं टेक्स्ट को एंटी-एलाइज्ड होने की तलाश में हूं और जैसा कि मैं समझता हूं कि यह होना चाहिए। जब मैं फ़ॉन्ट बनाता हूं तो 'सत्य' विकल्प एंटी-एलियासिंग का चयन करता है। – user1682655

उत्तर

0

एक यह करने के लिए जिस तरह से एक BufferedImage में पाठ (नहीं घुमाया) प्लॉट करने के लिए है, और फिर छवि को घुमाने। इस तरह कुछ:

BufferedImage buff = getGraphicsConfiguration().createCompatibleImage(textWidth, textHeight); //create an image with the dimensions of the text 
Graphics2D g2d = buff.createGraphics(); 
g2d.drawString(yourText); //draw the text without transformations 
g2d.dispose(); 

//apply the rotation transform to g, the Graphics from your component 
g.drawImage(buff, textPosX, textPosY, null); //there you go 
संबंधित मुद्दे