본문으로 이동

파일:StarfieldSimulation.gif

문서 내용이 다른 언어로는 지원되지 않습니다.
위키백과, 우리 모두의 백과사전.

StarfieldSimulation.gif(500 × 400 픽셀, 파일 크기: 781 KB, MIME 종류: image/gif, 반복됨, 240 프레임, 7.2 s)

파일 설명

설명
English: Inspired by the "Starfield Simulation" Screensaver for Windows. (With more stars in the distance.)
Deutsch: Ähnlich zum "Starfield Simulation" Bildschirmschoner von Windows. (Mit mehr Sternen in weiter Entfernung.)
날짜
출처 자작
저자 Jahobr
다른 버전
GIF 발전
InfoField
 
다이어그램MATLAB(으)로 Jahobr에 의해서제작되었습니다.
소스 코드
InfoField

MATLAB code

function StarfieldSimulation
% Source code that produces a GIF.
% Inspired by the "Starfield Simulation" Screensaver for Windows.
%
% 2017-04-20 Jahobr (update 2019-02-07 Jahobr)

[pathstr,fname] = fileparts(which(mfilename)); % save files under the same name and at file location
 
uniqueDepth = 200;
nFrames = 240;
renderDist = 200; % should be smaller or equal then uniqueDepth
StarDensity = 0.0005;
imageMax = [400, 500]; % pixel (height width)
subsampPix = 10; % subsampling per pixel in x and y
starRenderLimInPixel = 0.4; % diameter at least a x% of a pixel % if too small it flickers

for currentCase = 1:2
    rng(1); % int rand generator to make GIF repeatable; If you dont like the GIF try a differnt value
    speed = uniqueDepth/nFrames;
    nStars = StarDensity*(2*renderDist * 2*renderDist * uniqueDepth);
    
    x0 = rand(1,nStars)*renderDist*2-renderDist;
    y0 = rand(1,nStars)*renderDist*2-renderDist;
    sizze = 60+rand(1,nStars)*60;
    sizze = [sizze sizze]; % copy space behind each other to loop the gif
    
    depth = rand(1,nStars)*uniqueDepth;
    depth = sort(depth); % makes later rendering more efficient
    depth = [depth depth+uniqueDepth]; % copy space behind each other to loop the gif
    
    switch currentCase
        case 1 % classic
            saveName = fname;
            x_y =     [x0 x0;y0 y0]; % copy space behind each other to loop the gif
            thetaList = zeros(1,nFrames); % rotation
        case 2 % rot 90° per gif loop
            saveName = [fname '_rot'];
            x_y =     [x0 y0;y0 -x0]; % copy space behind each other to loop the gif
            thetaList = linspace(0,pi/2,nFrames+1); % rotation
            thetaList = thetaList(1:nFrames);
    end

    rawImage.cdata = uint8(zeros([imageMax 3]));
    rawImage.colormap = [];
    tic
    for iFrame = 1:nFrames
        
        
        disp([num2str(iFrame) ' of ' num2str(nFrames)])
        image = zeros(imageMax);
        
        %% calculate perspective
        
        
        theta = thetaList(iFrame);
        R = [cos(theta) -sin(theta);
            sin(theta) cos(theta)];
        x_y_rot = R * x_y; % rotate
        
        plotImCoordX = (x_y_rot(1,:)./depth*imageMax(2))+imageMax(2)/2; % plane of view at depth 1;  focal point at [0 0 0]
        plotImCoordY = (x_y_rot(2,:)./depth*imageMax(1))+imageMax(1)/2; % plane of view at depth 1;  focal point at [0 0 0]
        
        distEuclid = sqrt( x_y_rot(1,:).^2 + x_y_rot(2,:).^2 + depth.^2 );%  euclidean distance focal point at [0 0 0]
        
        %% Rendering
        % It could be done with figure and plot functions but they are not
        % designed to display objects on the pixel and sub-pixel scale.
        % The result just looks bad.
        
        % So a own small rendering engine is used:
        % check if a particular star rendering is necessary
        % lay a grid over the star
        % find if grid-points are within the star circle
        % if yes, match the grid-point to a pixel and add its portion of
        % "brightness" to the image
        
        startIndex = find(depth>0,1,'first'); % depth was sorted
        stopIndex = find(depth<renderDist,1,'last'); % depth was sorted
        
        for k = startIndex:stopIndex % for all stars that would be in range
            
            radiusStar = sizze(k)/distEuclid(k)/2;
            
            if plotImCoordX(k)+radiusStar < 0  % outside to the left
                continue % next star
            end
            if plotImCoordX(k)-radiusStar > imageMax(2)+1  % outside to the right
                continue % next star
            end
            
            if plotImCoordY(k)+radiusStar < 0  % outside to the bottom
                continue % next star
            end
            if plotImCoordY(k)-radiusStar > imageMax(1)+1  % outside to the top
                continue % next star
            end
            
            if radiusStar*2>starRenderLimInPixel % diameter at least a defined part of a pixel
                window = ceil(radiusStar *subsampPix); % size of grid to map over stars
                
                inCircle = false(2*window,2*window);
                
                for ix = 1:window % grid-points in positive x
                    for iy = 1:window % grid-points in positive y
                        
                        distEuclidPixel = sqrt( ((ix-0.5)/subsampPix).^2 + ((iy-0.5)/subsampPix).^2);%  euclidian distance focal point at [0 0 0]
                        
                        % do a quarter of the circle and flip to -x,y  and -x,-y  and  x,-y (1/8 would be enough actually)
                        if  radiusStar>distEuclidPixel % is grid in reach of star
                            inCircle(window+ix  ,window+iy  ) = true; % 1 quadrant
                            inCircle(window+ix  ,window+1-iy) = true; % 2 quadrant
                            inCircle(window+1-ix,window+iy  ) = true; % 3 quadrant
                            inCircle(window+1-ix,window+1-iy) = true; % 4 quadrant
                            
                        end
                    end
                end
                xGrid = round((( (1:2*window)-0.5-window) /subsampPix)+plotImCoordX(k)); % create x-grid and round to nearest Image pixel
                yGrid = round((( (1:2*window)-0.5-window) /subsampPix)+plotImCoordY(k)); % create y-grid and round to nearest Image pixel
                
                for ix = 1:2*window % pixel grid in x
                    if and(xGrid(ix) >= 1, xGrid(ix) <= imageMax(2)) % if in image
                        for iy = 1:2*window % pixel grid in y
                            if and(yGrid(iy) >= 1, yGrid(iy) <= imageMax(1)) % if in image
                                if inCircle(ix,iy) % if in Circle
                                    image(yGrid(iy),xGrid(ix)) = image(yGrid(iy),xGrid(ix))+1/subsampPix^2; % add brightness to pixel
                                end
                            end
                        end
                    end
                end
            end
        end
        
        image(image>1) = 1; % fix "over exposure"
        
        depth = depth-speed; % move
        
        %% save animation
        f = rawImage;
        f.cdata(:,:,1) = uint8(image*255);
        f.cdata(:,:,2) = uint8(image*255);
        f.cdata(:,:,3) = uint8(image*255);
        
        map = gray(8); % self created map. Otherwise use; [im,map] = rgb2ind(f.cdata,4,'nodither')
        
        imtemp = rgb2ind(f.cdata,map,'nodither');
        im(:,:,1,iFrame) = imtemp;
        if iFrame == 1
            im(1,1,1,nFrames) = 0; % allocate
        end
        
    end
    
    toc
    imwrite(im,map,fullfile(pathstr, [saveName '.gif']),'DelayTime',1/30,'LoopCount',inf) %
    disp([saveName '.gif  has ' num2str(numel(im)/10^6 ,4) ' Megapixels']) % Category:Animated GIF files exceeding the 50 MP limit
end
rng('shuffle'); % reset rand

라이선스

나는 아래 작품의 저작권자로서, 이 저작물을 다음과 같은 라이선스로 배포합니다:
Creative Commons CC-Zero 이 파일은 크리에이티브 커먼즈 CC0 1.0 보편적 퍼블릭 도메인 귀속에 따라 이용할 수 있습니다.
저작물에 본 권리증서를 첨부한 자는 법률에서 허용하는 범위 내에서 저작인접권 및 관련된 모든 권리들을 포함하여 저작권법에 따라 전 세계적으로 해당 저작물에 대해 자신이 갖는 일체의 권리를 포기함으로써 저작물을 퍼블릭 도메인으로 양도하였습니다. 저작권자의 허락을 구하지 않아도 이 저작물을 상업적인 목적을 포함하여 모든 목적으로 복제, 수정·변경, 배포, 공연·실연할 수 있습니다.

설명

이 파일이 나타내는 바에 대한 한 줄 설명을 추가합니다

이 파일에 묘사된 항목

다음을 묘사함

20 4월 2017

파일 역사

날짜/시간 링크를 클릭하면 해당 시간의 파일을 볼 수 있습니다.

날짜/시간섬네일크기사용자설명
현재2017년 4월월 20일 (목) 20:082017년 4월월 20일 (목) 20:08 판의 섬네일500 × 400 (781 KB)Jahobr{{Information |Description ={{en|1=Inpired by the "Starfield Simulation" Screensaver for Windows. (With more stars in the distance.)}} {{de|1=Ählich zum "Starfield Simulation" Bildschirmschoner von Windows. (Mit mehr Sternen in weiter Entfernung)}}...

이 파일을 사용하는 문서가 없습니다.

이 파일을 사용하고 있는 모든 위키의 문서 목록

다음 위키에서 이 파일을 사용하고 있습니다: