2006/09/12(Tue)触発

はてブ数 2006/09/12 0:21 プログラミング::HSP3 つーさ
20060909184157.png

 きりがなくなってきたからこの辺で終わりにしよう。

 二種類のサイクロイドをつかって描く曲線。

#define PATTERN 1 // 0,1,2

#if PATTERN!=0!=1 // PATTERN 0
    #define scale 10.0f // 図の大きさ
    #define ratio 1.0f // 周回ごとの大きさ補正値
    #define clearance 4 // 角形の間隔
    #define resolution 1536 // 一周あたりの分解能 
    #define laps 6 // 周回数
    #define pcolor hsvcolor 192f*p, 64, 255 // 色
    #define PenR1 3.00f // 外サイクロイドの外接円半径に対するペン半径の割合
    #define PenR2 1.50f // 内サイクロイドの内接円半径に対するペン半径の割合
#endif

#if PATTERN!=1!=1 // PATTERN 1 : 花
    #define scale 11.0f
    #define ratio 1.0f
    #define clearance 2
    #define resolution 8192
    #define laps 8
    #define PenR1 3.00f
    #define PenR2 0.50f
#endif

#if PATTERN!=2!=1 // PATTERN 2 : なんか模様
    #define scale 0.8f
    #define ratio 0.0f
    #define clearance 4
    #define resolution 512
    #define laps 357
    #define PenR1 2.00f
    #define PenR2 0.50f
#endif

#module // antialiased pset(てきとーw)
#deffunc apset int x,int y
    r=ginfo_r:g=ginfo_g:b=ginfo_b
    pset x, y
    pget x+1,y : color (r+ginfo_r)/2,(g+ginfo_g)/2,(b+ginfo_b)/2 : pset x+1,y
    pget x-1,y : color (r+ginfo_r)/2,(g+ginfo_g)/2,(b+ginfo_b)/2 : pset x-1,y
    pget x,y+1 : color (r+ginfo_r)/2,(g+ginfo_g)/2,(b+ginfo_b)/2 : pset x,y+1
    pget x,y-1 : color (r+ginfo_r)/2,(g+ginfo_g)/2,(b+ginfo_b)/2 : pset x,y-1
    color r,g,b
    return
#global

#define PI 3.14159265358979f
#define wPI 6.28318530717959f
#const waitsw 0

#ifndef pcolor
    #define pcolor
#endif
    bgscr ,ginfo_dispx,ginfo_dispy,,0,0 : cls 4

    repeat laps, 0
        n = (cnt+1)*clearance+1 // n角形 
        r = double(scale)*(double(ratio)/(cnt+1)*cnt+1) // とりあえず半径基準値
    
        // エピサイクロイド(外サイクロイド)
        a = r*n // 円半径
        b = r // 外接円半径
        c = b*PenR1 // ペン半径
        repeat resolution
            p = 1f * cnt/resolution // 周に対する割合
            t = wPI*p+n
            x = 1f* (a+b)*cos(t)-c*cos(((a+b)/b)*t)
            y = 1f* (a+b)*sin(t)-c*sin(((a+b)/b)*t)
            hsvcolor 192f*cnt/resolution, 255f*n*p+64, 255f*n*p+64
            pcolor
            apset x + ginfo_winx/2, y + ginfo_winy/2
            await waitsw
        loop
    
        // ハイポサイクロイド(内サイクロイド)
        a = r*n // 円半径
        b = r*2 // 内接円半径
        c = b*PenR2 // ペン半径
        repeat resolution
            p = 1f * cnt/resolution // 周に対する割合
            t = wPI*p*2+n
            x = 1f* (a-b)*cos(t)+c*cos(((a-b)/b)*t)
            y = 1f* (a-b)*sin(t)-c*sin(((a-b)/b)*t)
            hsvcolor 192f*cnt/resolution, 255f*n*p-64, 255f*n*p-64
            pcolor
            apset x + ginfo_winx/2, y + ginfo_winy/2
            await waitsw
        loop
    loop