Praks 11 kood mingine

This commit is contained in:
2015-11-11 13:31:30 +02:00
parent b3cd529139
commit 24304c93b3
3 changed files with 126 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package praktikum11;
import java.applet.Applet;
import java.awt.*;
public class PudeliHari extends Applet {
/*
* Ringjoone võrrand parameetrilisel kujul
* x = r * cos(t)
* y = r * sin(t)
* t = -PI..PI
*/
public void paint(Graphics g) {
// Küsime kui suur aken on?
int w = getWidth();
int h = getHeight();
int r = 100; // Raadius
int x0 = w/2; // Keskpunkt
int y0 = h/2;
int x, y;
double t;
// Täidame tausta
g.setColor(Color.white);
g.fillRect(0, 0, w, h);
// Joonistame
g.setColor(Color.black);
for (t = -Math.PI; t < Math.PI; t = t + Math.PI / 16) {
x = (int) (r * Math.cos(t) + x0);
y = (int) (r * Math.sin(t) + y0);
g.drawLine(x0, y0, x, y);
}
}
}

View File

@@ -0,0 +1,67 @@
package praktikum11;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
/**
* Ringjoone valemi järgi ringi joonistamise näide
* @author Mikk Mangus
*/
@SuppressWarnings("serial")
public class Spiraal extends Applet {
private Graphics g;
public void paint(Graphics g) {
this.g = g;
joonistaTaust();
joonistaSpiraal();
}
public void joonistaSpiraal() {
g.setColor(Color.black);
int keskkohtX = getWidth() / 2;
int keskkohtY = getHeight() / 2;
int raadius = 50;
double pikkus = 30;
double tihedus = 30;
int lastX = keskkohtX;
int lastY = keskkohtY;
for (double nurk = 0; nurk <= Math.PI * pikkus; nurk = nurk + .03) {
int x = (int) (raadius * Math.cos(nurk)*(nurk/tihedus));
int y = (int) (raadius * Math.sin(nurk)*(nurk/tihedus));
//g.fillRect(keskkohtX + x, keskkohtY + y, 2, 2);
g.drawLine(lastX, lastY, keskkohtX + x, keskkohtY + y);
lastX = keskkohtX + x;
lastY = keskkohtY + y;
}
}
/**
* Katab tausta valgega
*/
public void joonistaTaust() {
int w = getWidth();
int h = getHeight();
g.setColor(Color.white);
g.fillRect(0, 0, w, h);
}
/**
* Joonistab ringi
*/
public void joonistaRing() {
g.setColor(Color.black);
int keskkohtX = getWidth() / 2;
int keskkohtY = getHeight() / 2;
int raadius = 50;
for (double nurk = 0; nurk <= Math.PI * 2; nurk = nurk + .03) {
int x = (int) (raadius * Math.cos(nurk));
int y = (int) (raadius * Math.sin(nurk));
g.fillRect(keskkohtX + x, keskkohtY + y, 2, 2);
}
}
}

View File

@@ -0,0 +1,22 @@
package praktikum11;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class Yleminek extends Applet {
public void paint(Graphics g) {
gradient(g, new Color(255,0,0), new Color(1,0,0));
}
public void gradient(Graphics g, Color c1, Color c2) {
for (int i = 0; i <= this.getHeight(); i++) {
//int red = (i*(c1.getRed()/c2.getRed()))/this.getHeight(); // jagab 255 värvi akna kõrguse peale ära
int color = (i*255/this.getHeight());
g.setColor(new Color(color, color, color));
g.drawLine(0, i, this.getWidth(), i);
}
}
}