Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup() {
- // make it so sketch is the size of browser window
- size(window.innerWidth, window.innerHeight);
- // Generate 90
- circle_things;
- }
- class Color_struct{
- int red;
- int blue;
- int green;
- // Colors based on seperate RGB vals.
- Color_struct(int _red, int _green, int _blue){
- red = _red;
- green = _green;
- blue = _blue;
- }
- // Base color with just one input.
- Color_struct(int base_color){
- red = green = blue = base_color;
- }
- }
- // Holds a blinking thing
- class Circle_thing{
- Color_struct base_color = new Color_struct(50);
- Color_struct end_color = new Color_struct(150);
- Color_struct current_color = new Color_struct(51);
- // How fast things update. For now, just the color.
- final int speed = 3;
- // Which direction we are changing colors too.
- boolean to_color_1 = false;
- // Current rotation in degrees
- int rotation = 0;
- boolean rotation_direction = true;
- // Width of the circle.
- final int max_circle_width = 150;
- int current_circle_width = 0;
- Circle_thing(int _rotation, int _current_color){
- rotation = _rotation;
- curent_color = new Color_struct(_current_color);
- }
- // Updates the scene.
- void update(){
- // Check if we need to change the color direction.
- if (current_color.red + speed > end_color.red && !to_color_1){
- to_color_1 = true;
- }
- // And the other direction.
- if (current_color.red - speed < base_color.red && to_color_1){
- to_color_1 = false;
- }
- // Now change the color in the approriate direction.
- if (!to_color_1) {
- current_color.red = current_color.blue = current_color.green = current_color.red + speed;
- } else {
- current_color.red = current_color.blue = current_color.green = current_color.red - speed;
- }
- // Flip use negative speed for rotating in other direction.
- if (rotation > 180) { rotation_direction = !rotation_direction };
- if (rotation < 0) { rotation_direction = !rotation_direction };
- // Increment the rotation by speed;
- if (rotation_direction) {rotation = rotation + speed; } else { rotation = rotation - speed; }
- // Do some rotation to width conversion.
- current_circle_width = map(rotation, 0, 180, 0, max_circle_width);
- }
- // Draws this circle thing.
- void display(){
- fill(current_color.red, current_color.blue, current_color.green);
- ellipse(mouseX, mouseY, current_circle_width, 150);
- }
- }
- Circle_thing circle_thing = new Circle_thing(30, 90);
- ArrayList<Circle_thing> circle_things;
- void draw() {
- background(50, 50, 50);
- circle_thing.update();
- circle_thing.display();
- // draw with mouse
- // fill(255,0,0);
- // ellipse(mouseX, mouseY, 20, 20);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement