# Java Experiment

**URL:** https://forum.kirupa.com/t/java-experiment/48453
**Category:** design
**Created:** [April 13, 2004, 6:58pm UTC](https://forum.kirupa.com/t/java-experiment/48453 "2004-04-13T18:58:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![955](https://avatars.discourse-cdn.com/v4/letter/9/4bbf92/32.png) [@955](https://forum.kirupa.com/u/955)
#### Post date: [April 13, 2004, 6:58pm UTC](https://forum.kirupa.com/t/java-experiment/48453/1 "2004-04-13T18:58:48Z")

</div>

Really basic little Java experiment I just wrote… messing around with cos and sin

[http://skehin.com/misc/CycleExperiment](http://skehin.com/misc/CycleExperiment)

```php

import java.awt.*;
import java.applet.*;
public class CycleExperiment extends Applet {

    public void paint(Graphics g) {
        this.setBackground(new Color(0,0,0));
        int height = this.getHeight();
        int width = this.getWidth();
        for(int i = 0; i < width; i+=3){
            for(int j = 0; j < height; j+=3){
                float red = Math.abs(round(5, Math.cos(i + j)));
                float green = Math.abs(round(5, Math.sin(i * j)));
                float blue = Math.abs(round(5, Math.cos(i * (j/(i+0.1)))));
                System.out.println("Red: " + red + " Green: " + green + " Blue: "+ blue);
                g.setColor(new Color(red, green, blue));
                g.drawRect(i, j, 1, 1);
            }
        }
    }
    private static float round(int numPlaces, double num){
        return (float) Math.round(num*(numPlaces*10))/(numPlaces*10);
    }
}
//Copyright njs 2004

```

(it’s Java, but the PHP mode provides alright highlighting for C style languages like Java)
