for, while, or do-while, we can draw multiple shapes, apply different colors, and create moving effects.जावा एप्लेट में हम लूप कंट्रोल स्टेटमेंट का उपयोग करके एनीमेशन या दोहराए जाने वाले पैटर्न बना सकते हैं। for, while या do-while लूप का उपयोग करके हम एक ही आकृति को बार-बार विभिन्न रंगों में बनाकर मूविंग इफेक्ट तैयार कर सकते हैं।
🌈 Example: Color Changing Rectangles using For Loop
This example draws multiple rectangles in different shades of red using a for loop.
यह उदाहरण for लूप का उपयोग करके लाल रंग की विभिन्न शेड्स में कई आयतें बनाता है।
// File Name: ForLoopApplet.java
import java.awt.*;
import java.applet.*;
public class ForLoopApplet extends Applet {
public void paint(Graphics g) {
Color newColor = new Color(0,0,0);
for(int i=0; i<10; i++) {
newColor = new Color(i*20+55, 0, 0); // Different red shades
g.setColor(newColor);
g.fillRect(i * 40, i * 10, 30, 60); // Rectangles in a pattern
}
}
}
🔹 Output Description (आउटपुट विवरण)
-
10 Rectangles will appear in different shades of red. 10 आयतें लाल रंग के विभिन्न शेड्स में दिखाई देंगी।
-
Rectangles will appear diagonally, moving slightly downward. ये आयतें तिरछे (डायगोनल) रूप में बनेंगी।
-
Loop allows us to easily create repetitive patterns or animations. लूप की मदद से हम बार-बार दोहराए जाने वाले पैटर्न या एनीमेशन आसानी से बना सकते हैं।
No comments:
Post a Comment