Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
42
Task/Polyspiral/Rebol/polyspiral.rebol
Normal file
42
Task/Polyspiral/Rebol/polyspiral.rebol
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
Rebol [
|
||||
title: "Rosetta code: Polyspiral"
|
||||
file: %Polyspiral.r3
|
||||
url: https://rosettacode.org/wiki/Polyspiral
|
||||
needs: 3.10.2
|
||||
note: [
|
||||
https://github.com/Oldes/Rebol3/releases
|
||||
https://github.com/Siskin-framework/Rebol-Blend2D
|
||||
]
|
||||
]
|
||||
import blend2d ;; Import Blend2D extension used to draw
|
||||
|
||||
incr: 0.0 ;; Initialize increment variable to 0.0
|
||||
image: make image! 800x800 ;; Create an 800x800 pixel image canvas
|
||||
pi2: 2 * PI ;; Calculate 2π (full circle in radians), for angle calculations
|
||||
random/seed 4
|
||||
|
||||
;; animation loop (repeats 4 times to create progressive spiral states)
|
||||
loop 4 [
|
||||
x: image/size/x / 2 ;; Set x to center of image (horizontal)
|
||||
y: image/size/y / 2 ;; Set y to center of image (vertical)
|
||||
length: 5 ;; Starting length/step for spiral arms
|
||||
incr: (incr + 5) % pi2 ;; Increment the angle step (modulo 2π to ensure it wraps correctly)
|
||||
angle: incr
|
||||
commands: clear [] ;; Clear previous drawing commands
|
||||
color: 100.100.100 + random 155.155.155
|
||||
append commands [line-width 1 pen :color line] ;; Start a new line with width 1 and random pen color
|
||||
|
||||
;; spiral loop (generates points for the spiral)
|
||||
loop 150 [
|
||||
x: x + (length * (cos angle)) ;; Move x along the current angle by current length
|
||||
y: y + (length * (sin angle)) ;; Move y along the current angle by current length
|
||||
append commands as-pair x y ;; Add the new (x, y) point to the command list
|
||||
length: length + 5 ;; Increase the step size for spiral effect
|
||||
angle: (angle + incr) % pi2 ;; Progress the angle for the spiral's curvature (modulo 2π)
|
||||
]
|
||||
|
||||
draw image commands ;; Render the spiral on the image with the accumulated commands
|
||||
]
|
||||
|
||||
try [save %polyspiral.png image] ;; Save the image as PNG
|
||||
try [view image] ;; Display the final image window with drawn spirals
|
||||
81
Task/Polyspiral/V-(Vlang)/polyspiral.v
Normal file
81
Task/Polyspiral/V-(Vlang)/polyspiral.v
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
import gg
|
||||
import gx
|
||||
import math
|
||||
|
||||
struct Polyspiral {
|
||||
mut:
|
||||
width int
|
||||
height int
|
||||
inc f64
|
||||
}
|
||||
fn hsv_to_rgb(h f32, s f32, v f32) gx.Color {
|
||||
c := v * s
|
||||
h_prime := h / 60.0
|
||||
x := c * (1 - math.abs(math.fmod(f64(h_prime), 2) - 1))
|
||||
m := v - c
|
||||
mut r, mut g, mut b := 0.0, 0.0, 0.0
|
||||
match int(h_prime) {
|
||||
0 { r, g, b = c, x, 0 }
|
||||
1 { r, g, b = x, c, 0 }
|
||||
2 { r, g, b = 0, c, x }
|
||||
3 { r, g, b = 0, x, c }
|
||||
4 { r, g, b = x, 0, c }
|
||||
5, 6 { r, g, b = c, 0, x }
|
||||
else { r, g, b = 0, 0, 0 }
|
||||
}
|
||||
rrr := u8(math.min((r + m) * 255, 255))
|
||||
ggg := u8(math.min((g + m) * 255, 255))
|
||||
bbb := u8(math.min((b + m) * 255, 255))
|
||||
return gx.rgb(rrr, ggg, bbb)
|
||||
}
|
||||
|
||||
fn (mut poly Polyspiral) draw_spiral(mut ctx gg.Context, length f64, angle_increment f64) {
|
||||
mut x1 := f64(poly.width) / 2
|
||||
mut y1 := f64(poly.height) / 2
|
||||
mut len := length
|
||||
mut angle := angle_increment
|
||||
for i in 0 .. 150 {
|
||||
hue := f32(i) / 150 * 360
|
||||
col := hsv_to_rgb(hue, 1, 1)
|
||||
x2 := x1 + math.cos(angle) * len
|
||||
y2 := y1 - math.sin(angle) * len
|
||||
ctx.draw_line(
|
||||
f32(x1), f32(y1),
|
||||
f32(x2), f32(y2),
|
||||
col
|
||||
)
|
||||
x1 = x2
|
||||
y1 = y2
|
||||
len += 3
|
||||
angle = math.mod(angle + angle_increment, math.pi * 2)
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut poly Polyspiral) update() {
|
||||
poly.inc = math.mod(poly.inc + 0.05, 360)
|
||||
}
|
||||
|
||||
fn frame(mut poly Polyspiral) {
|
||||
mut ctx := gg.Context{}
|
||||
angle_radians := poly.inc * math.pi / 180
|
||||
ctx.begin()
|
||||
poly.update()
|
||||
poly.draw_spiral(mut ctx, 5, angle_radians)
|
||||
ctx.end()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut poly := Polyspiral{
|
||||
width: 640
|
||||
height: 640
|
||||
inc: 0
|
||||
}
|
||||
mut context := gg.new_context(
|
||||
width: poly.width
|
||||
height: poly.height
|
||||
window_title: 'Polyspiral'
|
||||
frame_fn: frame
|
||||
user_data: &poly
|
||||
)
|
||||
context.run()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue