60 likes | 186 Views
This guide introduces the use of Crayon objects in Java for creating geometric shapes. You'll learn the fundamental methods to move, turn, and draw using Crayons, providing a foundation for drawing squares, triangles, and other figures. Sample code demonstrates how to use Crayon methods effectively, helping you create visually appealing drawings. Exercises encourage experimentation and artistic creation, making it suitable for beginners in programming and graphical design. Get started with your artistic journey in Java programming today!
E N D
Grafik – Crayon-objekter IntroJava2006 - AAU
Model (0,0) • Position: (x,y) • Vinkel: v • Farve: color • Bredde: positivt tal 270 Tavle 0 (360) 180 90 (400,500) ... En pens tilstand: - (position, vinkel, farve, bredde) - starttilstand: ((0, 0), 0, Color.black, 1) Eller ((midt, midt), 0, Color.black, down) IntroJava2006 - AAU
Metoder • public void move(double d) Flyt d enheder i aktuel tegneretning, mens der tegnes • public void moveto(double x, double y)Flyt til position (x,y), mens der tegnes • public void jump(double d)Flyt d enheder i aktuel tegneretning uden at tegne • public void jumpto(double x, double y)Flyt til (x,y) uden at tegne • public void turn(double a)Drej a grader med uret • public void turnto(double a) Drej til tegneretning a (x-aksens retning er 0 grader) • public void erase()Slet alt på tavlen IntroJava2006 - AAU
I BlueJ Skal bruges – ikke ændres Skal kodes IntroJava2006 - AAU
Eksempel import java.awt.*; public class CrayonSquares { public void main() { Crayon blue_pencil = new Crayon(Color.BLUE, 1); Crayon red_pencil = new Crayon(Color.RED, 1); //tegn det blå kvadrat: blue_pencil.jumpto(100, 100); blue_pencil.turnto(0); blue_pencil.move(100); blue_pencil.turn(90); blue_pencil.move(100); blue_pencil.turn(90); blue_pencil.move(100); blue_pencil.turn(90); blue_pencil.move(100); blue_pencil.turn(90); //Tegn det røde kvadrat: IntroJava2006 - AAU
Øvelser • Hent projektet opgCrayon. Åben det og kør det. • Tegn et grønt kvadrat uden om de to andre. • Tegn en ligesidet trekant inden i en ligesidet sekskant. • Eksperimenter med Crayon-objekter og lav nogle ”kunstneriske” tegninger. IntroJava2006 - AAU