This site requires JavaScript, please enable it in your browser!
Greenfoot back

Discussions

You need to login to take part
Rss

Current Discussions

saya123

hm1

By saya123, with no replies.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author (your name) * @version (a version number or a date) */ public class MyWorld extends World { /** * Constructor for objects of class MyWorld. * */ public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(800, 400, 1); getBackground().setColor(Color.BLACK); drawBranch(200, 390, 100, -90, -10); drawBranch(400, 390, 100, -90, 0); drawBranch(600, 390, 100, -90, +10); } public void drawBranch(int x, int y, int length, int degree, int angin){ if (length <= 20 && Greenfoot.getRandomNumber(100) < 25){ getBackground().setColor(Color.RED); getBackground().fillOval(x,y,3,3); } if(length <=15){ return; } int x2 = x + (int) (Math.cos(Math.toRadians(degree)) * length); int y2 = y + (int) (Math.sin(Math.toRadians(degree)) * length); int random = Greenfoot.getRandomNumber(100); if (length > 60){ getBackground().setColor(Color.BLACK); } else if (length > 30){ getBackground().setColor(Color.BLUE); } else { getBackground().setColor(Color.GREEN); } getBackground().drawLine(x,y,x2,y2); if (random<25){ drawBranch(x2,y2,(int) (length*0.75), degree+7+angin, angin); drawBranch(x2,y2,(int) (length*0.75), degree-7+angin, angin); } else if (random<50){ drawBranch(x2,y2,(int) (length*0.75), degree+angin, angin); } drawBranch(x2,y2,(int) (length*0.75), degree+15+angin, angin); drawBranch(x2,y2,(int) (length*0.75), degree-15+angin, angin); } }
1
2
3
4