Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define main
- // CONSTANTS
- WIDTH = 720;
- HEIGHT = 720;
- xpos = 32;
- ypos = 32;
- RADIUS = 256;
- BASE_HUE = 120; // blue-ish
- HUE_SCALAR = 0.1; // how much of the gradient to show? 0 = solid color
- // Finally make the clock
- clock = make_clock(RADIUS, BASE_HUE, HUE_SCALAR);
- #define draw
- var seconds_rad = degtorad((current_second * 6) - 90);
- var sx = xpos + RADIUS + SECOND_HAND_LENGTH * cos(seconds_rad);
- var sy = ypos + RADIUS + SECOND_HAND_LENGTH * sin(seconds_rad);
- var minutes_rad = degtorad((current_minute * 6) - 90);
- var mx = xpos + RADIUS + MINUTE_HAND_LENGTH * cos(minutes_rad);
- var my = ypos + RADIUS + MINUTE_HAND_LENGTH * sin(minutes_rad);
- var hours_rad = degtorad((current_hour * 30) - 90);
- var hx = xpos + RADIUS + HOUR_HAND_LENGTH * cos(hours_rad);
- var hy = ypos + RADIUS + HOUR_HAND_LENGTH * sin(hours_rad);
- // Draw clock background
- draw_surface(clock, xpos, ypos);
- // Draw the hands of the clock
- line(xpos + RADIUS, ypos + RADIUS, sx, sy, SECOND_HAND_WIDTH, c_black);
- line(xpos + RADIUS, ypos + RADIUS, mx, my, MINUTE_HAND_WIDTH, c_black);
- line(xpos + RADIUS, ypos + RADIUS, hx, hy, HOUR_HAND_WIDTH, c_black);
- /* FUNCTIONS */
- #define circle(x, y, radius, outline, color)
- draw_set_color(color);
- draw_circle(x, y, radius, outline);
- #define line(x1, y1, x2, y2, width, color)
- draw_set_color(color);
- draw_line_width(x1, y1, x2, y2, width);
- #define distance(x1, y1, x2, y2)
- return sqrt(power(x2 - x1, 2) + power(y2 - y1, 2));
- #define in_circle(x, y, radius, dx, dy)
- return distance(x, y, dx, dy) < radius;
- #define make_clock(radius, hue, hue_scalar)
- /* The following are all a function of the arguments above */
- OUTER_RING_RADIUS = radius;
- INNER_RING_RADIUS = radius / 1.05;
- CENTER_RING_RADIUS = radius / 32;
- SECOND_HAND_LENGTH = radius / 1.3;
- SECOND_HAND_WIDTH = max(1, radius / 128);
- MINUTE_HAND_LENGTH = radius / 1.46;
- MINUTE_HAND_WIDTH = max(2, radius / 64);
- HOUR_HAND_LENGTH = radius / 2.32;
- HOUR_HAND_WIDTH = max(3, radius / 51);
- DOT_OFFSET = radius / 21;
- NUM_OFFSET = radius / 8;
- SMALL_DOT_RADIUS = max(1, radius / 85);
- BIG_DOT_RADIUS = max(2, radius / 43);
- NUM_SCALE = radius / 256;
- COLOR_SCALAR = (256 / radius) * HUE_SCALAR;
- var clock = surface_create(radius * 2, radius * 2);
- surface_set_target(clock);
- circle(radius, radius, OUTER_RING_RADIUS, false, c_black);
- // Draw the gradient :D
- for(var dx = -INNER_RING_RADIUS; dx <= INNER_RING_RADIUS; dx++) {
- for(var dy = -INNER_RING_RADIUS; dy <= INNER_RING_RADIUS; dy++) {
- var ax = radius + dx, ay = radius + dy;
- var dist = distance(radius, radius, ax, ay);
- var color = c_teal;
- color = make_color_hsv((hue + (dist * COLOR_SCALAR)) % 360, 255, 255);
- if(in_circle(radius, radius, INNER_RING_RADIUS, ax, ay))
- draw_point_color(ax, ay, color);
- }
- }
- circle(radius, radius, CENTER_RING_RADIUS, false, c_black);
- // Draw the numbers and the points to the edge of the circle
- draw_set_color(c_black);
- draw_set_halign(fa_center);
- draw_set_valign(fa_middle);
- for(var i = 0; i < 360; i += 6) {
- var dot_x = radius + (INNER_RING_RADIUS - DOT_OFFSET) * cos(degtorad(i));
- var dot_y = radius + (INNER_RING_RADIUS - DOT_OFFSET) * sin(degtorad(i));
- var num_x = radius + (INNER_RING_RADIUS - NUM_OFFSET) * cos(degtorad(i - 60));
- var num_y = radius + (INNER_RING_RADIUS - NUM_OFFSET) * sin(degtorad(i - 60));
- // Draw the point
- if(i % 5 != 0)
- draw_circle(dot_x, dot_y, SMALL_DOT_RADIUS, true);
- else
- draw_circle(dot_x, dot_y, BIG_DOT_RADIUS, false);
- // Draw the number
- if(i % 5 == 0)
- draw_text_transformed(
- num_x, num_y,
- string((i / 30) + 1),
- NUM_SCALE, NUM_SCALE, 0
- );
- }
- surface_reset_target();
- return clock;
Add Comment
Please, Sign In to add comment