EOS 2  1.1.0
Einfache Objektbasierte Sprache
SystemFunctions.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.vm;
2 
3 import java.awt.Color;
4 import java.util.Calendar;
5 import java.util.Random;
6 
12 public abstract class SystemFunctions {
13  private static final Random random = new Random();
14 
15  public static Color colorFromRGBI(int r, int g, int b) {
16  return new Color(ri(r, 0, 255), ri(g, 0, 255), ri(b, 0, 255));
17  }
18 
19  private static int ri(int value, int min, int max) {
20  if (value < min)
21  return min;
22  if (value > max)
23  return max;
24  return value;
25  }
26 
27  public static Color colorFromRGBD(double r, double g, double b) {
28  return new Color(rf(r, 0f, 1f), rf(g, 0f, 1f), rf(b, 0f, 1f));
29  }
30 
31  private static float rf(double value, float min, float max) {
32  if (value < min)
33  return min;
34  if (value > max)
35  return max;
36  return (float) value;
37  }
38 
39  public static int round(double z) {
40  return (int) Math.round(z);
41  }
42 
43  public static int floor(double z) {
44  return (int) Math.floor(z);
45  }
46 
47  public static int random(int von, int bis) {
48  return random.nextInt(bis - von + 1) + von;
49  }
50 
51  public static double abs(double z) {
52  return Math.abs(z);
53  }
54 
55  public static double sqrt(double z) {
56  return Math.sqrt(z);
57  }
58 
59  public static double sin(double alpha) {
60  return Math.sin(alpha / 180 * Math.PI);
61  }
62 
63  public static double cos(double alpha) {
64  return Math.cos(alpha / 180 * Math.PI);
65  }
66 
67  public static double tan(double alpha) {
68  return Math.tan(alpha / 180 * Math.PI);
69  }
70 
71  public static double arctan(double m) {
72  return Math.atan(m) * 180 / Math.PI;
73  }
74 
75  public static double arcsin(double m) {
76  return Math.asin(m) * 180 / Math.PI;
77  }
78 
79  public static double arccos(double m) {
80  return Math.acos(m) * 180 / Math.PI;
81  }
82 
83  public static double phi(double x, double y) {
84  double phi = Math.atan(y / x);
85  if (x < 0) {
86  return phi * 180 / Math.PI + 180;
87  } else {
88  return phi * 180 / Math.PI;
89  }
90  }
91 
92  public static double r(double x, double y) {
93  return Math.sqrt(x * x + y * y);
94  }
95 
96  public static int hour() {
97  return Calendar.getInstance().get(Calendar.HOUR);
98  }
99 
100  public static int minute() {
101  return Calendar.getInstance().get(Calendar.MINUTE);
102  }
103 
104  public static int second() {
105  return Calendar.getInstance().get(Calendar.SECOND);
106  }
107 
108  public static int year() {
109  return Calendar.getInstance().get(Calendar.YEAR);
110  }
111 
112  public static int month() {
113  return Calendar.getInstance().get(Calendar.MONTH);
114  }
115 
116  public static int day() {
117  return Calendar.getInstance().get(Calendar.DATE);
118  }
119 
120  public SystemFunctions() {
121  }
122 }
static double tan(double alpha)
static double cos(double alpha)
static double r(double x, double y)
static Color colorFromRGBD(double r, double g, double b)
static double phi(double x, double y)
static int random(int von, int bis)
static double sin(double alpha)
static Color colorFromRGBI(int r, int g, int b)
Impressum