#lang racket
(require racket/draw)
(require colors)

(define imageWidth 512)
(define imageHeight 288)
(define target (make-bitmap imageWidth imageHeight))
(define dc (new bitmap-dc% [bitmap target]))

; Set the background
(send dc set-pen "transparent" 1 'solid)
(send dc set-brush (make-color 50 0 100) 'solid)
(send dc draw-rectangle 0 0 imageWidth imageHeight)

; Define the original polygon
(define originalPolygon (new dc-path%))
(send originalPolygon move-to 30 30)
(send originalPolygon line-to -10 30)
(send originalPolygon line-to 10 30)
(send originalPolygon line-to 30 -30)
(send originalPolygon close)

; Set the pen and brush for the original polygon
(send dc set-pen "red" 1 'solid)
(send dc set-brush (make-color 255 0 0) 'solid)
(send dc draw-path originalPolygon)

; Define translation and scaling factors
(define dx 50)
(define dy 50)
(define sx 1.8)
(define sy 1.5)

; Translate and scale the original polygon
(define translatedPolygon (new dc-path%))
(send translatedPolygon append originalPolygon)
(send translatedPolygon translate dx dy)
(send dc draw-path translatedPolygon)

(define scaledPolygon (new dc-path%))
(send scaledPolygon append originalPolygon)
(send scaledPolygon scale sx sy)
(send dc draw-path scaledPolygon)

; Translate the scaled polygon
(define scaledDx 140)
(define scaledDy 100)
(define translatedScaledPolygon (new dc-path%))
(send translatedScaledPolygon append scaledPolygon)
(send translatedScaledPolygon translate scaledDx scaledDy)
(send dc draw-path translatedScaledPolygon)

; Function to convert HSV to RGB
(define (hsv-to-rgb h s v)
  (let-values ([(r g b) (hsv->rgb h s v)])
    (make-color r g b)))

; Main drawing loop for rotation and color cycling
(for ([i (in-range 0 360 4)]) ; Adjust the step for the number of polygons
  (define angle (* i (/ pi 180)))
  (define hue (/ i 360.0))
  (define rotatedPolygon (new dc-path%))
  (send rotatedPolygon append originalPolygon)
  (send rotatedPolygon rotate angle)
  (send dc set-pen "black" 1 'solid)
  (send dc set-brush (hsv-to-rgb hue 1 1) 'solid)
  (send dc draw-path rotatedPolygon))

; Save the image
(send target save-file "output.png" 'png)

; Display the image
(send (new bitmap% [bitmap target]) show #t)
 
by

Racket Online Compiler

Write, Run & Share Racket code online using OneCompiler's Racket online compiler for free. It's one of the robust, feature-rich online compilers for Racket language, running on the latest version 6.8. Getting started with the OneCompiler's Racket compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Racket and start coding.

Taking inputs (stdin)

OneCompiler's Racket online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Racket program which takes name as input and print your name with hello.

#lang racket/base
(define name (read))                
(printf "Hello ~a.\n" name)   

About Racket

Racket is a general-purpose programming language based on the Scheme dialect of Lisp. It is also used for scripting, computer science education, and research related applications.

Basics

ItemDecsription
;To comment a single line
;;to mark important comments
#;to comment the following s-expression

Data types

Data-typeDecsription
Numbersrepresents integers, float and complex numbers
Boolean#t and #f are the two boolean literals
StringsTo represent sequence of characters and double quotes("") are used to represent strings

Variables

let and define are used to declare variables

Syntax

(let ([id value-expression] ...) body ...+)

(let proc-id ([id init-expression] ...) body ...+)
define id expression

Example

> (let ([x 10]) x)
10

Loops and conditional statements

1. If family

If, If-else are used when you want to perform a certain set of operations based on conditional expressions.

If

(if cond-expr then-expr)

If-else

(if cond-expr then-expr else-expr)

2. For

For loop is used to iterate a set of statements based on a condition.

(for (for-clause ...) body-or-break ... body)
where 

for-clause = [id seq-expr] | [(id ...) seq-expr] | #:when guard-expr | #:unless guard-expr | break-clause
 	 	 	 	 
break-clause = #:break guard-expr | #:final guard-expr
 	 	 	 	 
body-or-break = body | break-clause

seq-expr : sequence?

Functions

A lambda expression is used to create a function.

(lambda (argument-id ...)
  body ...+)