Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
st3fan committed Oct 22, 2017
1 parent fbd5789 commit 08b78b1
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 45 deletions.
50 changes: 47 additions & 3 deletions Mozilla.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,39 @@
/* Begin PBXBuildFile section */
F84D98EA1F9D1FD1006F8331 /* MozillaView.h in Headers */ = {isa = PBXBuildFile; fileRef = F84D98E91F9D1FD1006F8331 /* MozillaView.h */; };
F84D98EC1F9D1FD1006F8331 /* MozillaView.m in Sources */ = {isa = PBXBuildFile; fileRef = F84D98EB1F9D1FD1006F8331 /* MozillaView.m */; };
F84D98F51F9D2052006F8331 /* MozillaScene.h in Headers */ = {isa = PBXBuildFile; fileRef = F84D98F31F9D2052006F8331 /* MozillaScene.h */; };
F84D98F61F9D2052006F8331 /* MozillaScene.m in Sources */ = {isa = PBXBuildFile; fileRef = F84D98F41F9D2052006F8331 /* MozillaScene.m */; };
F84D98FF1F9D2350006F8331 /* SpriteKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F84D98FE1F9D2350006F8331 /* SpriteKit.framework */; };
F84D99001F9D2457006F8331 /* firefox-logo-developer-edition.png in Resources */ = {isa = PBXBuildFile; fileRef = F84D98F71F9D22C5006F8331 /* firefox-logo-developer-edition.png */; };
F84D99011F9D2457006F8331 /* firefox-logo-focus.png in Resources */ = {isa = PBXBuildFile; fileRef = F84D98FA1F9D22C5006F8331 /* firefox-logo-focus.png */; };
F84D99021F9D2457006F8331 /* firefox-logo-nightly.png in Resources */ = {isa = PBXBuildFile; fileRef = F84D98F91F9D22C5006F8331 /* firefox-logo-nightly.png */; };
F84D99031F9D2457006F8331 /* firefox-logo.png in Resources */ = {isa = PBXBuildFile; fileRef = F84D98F81F9D22C5006F8331 /* firefox-logo.png */; };
F84D99041F9D2457006F8331 /* mozilla-mask.png in Resources */ = {isa = PBXBuildFile; fileRef = F84D98FB1F9D22C5006F8331 /* mozilla-mask.png */; };
F84D99051F9D2457006F8331 /* mozilla.png in Resources */ = {isa = PBXBuildFile; fileRef = F84D98FC1F9D22C6006F8331 /* mozilla.png */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
F84D98E61F9D1FD1006F8331 /* Mozilla.saver */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Mozilla.saver; sourceTree = BUILT_PRODUCTS_DIR; };
F84D98E91F9D1FD1006F8331 /* MozillaView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MozillaView.h; sourceTree = "<group>"; };
F84D98EB1F9D1FD1006F8331 /* MozillaView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MozillaView.m; sourceTree = "<group>"; };
F84D98ED1F9D1FD1006F8331 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F84D98F31F9D2052006F8331 /* MozillaScene.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MozillaScene.h; sourceTree = "<group>"; };
F84D98F41F9D2052006F8331 /* MozillaScene.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MozillaScene.m; sourceTree = "<group>"; };
F84D98F71F9D22C5006F8331 /* firefox-logo-developer-edition.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "firefox-logo-developer-edition.png"; path = "../../ScreenSaverExperiments/MozillaSaver2/SaverPlayground/Assets.xcassets/firefox-logo-developer-edition.imageset/firefox-logo-developer-edition.png"; sourceTree = "<group>"; };
F84D98F81F9D22C5006F8331 /* firefox-logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "firefox-logo.png"; path = "../../ScreenSaverExperiments/MozillaSaver2/SaverPlayground/Assets.xcassets/firefox-logo.imageset/firefox-logo.png"; sourceTree = "<group>"; };
F84D98F91F9D22C5006F8331 /* firefox-logo-nightly.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "firefox-logo-nightly.png"; path = "../../ScreenSaverExperiments/MozillaSaver2/SaverPlayground/Assets.xcassets/firefox-logo-nightly.imageset/firefox-logo-nightly.png"; sourceTree = "<group>"; };
F84D98FA1F9D22C5006F8331 /* firefox-logo-focus.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "firefox-logo-focus.png"; path = "../../ScreenSaverExperiments/MozillaSaver2/SaverPlayground/Assets.xcassets/firefox-logo-focus.imageset/firefox-logo-focus.png"; sourceTree = "<group>"; };
F84D98FB1F9D22C5006F8331 /* mozilla-mask.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "mozilla-mask.png"; path = "../../ScreenSaverExperiments/MozillaSaver2/SaverPlayground/Assets.xcassets/mozilla-mask.imageset/mozilla-mask.png"; sourceTree = "<group>"; };
F84D98FC1F9D22C6006F8331 /* mozilla.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = mozilla.png; path = ../../ScreenSaverExperiments/MozillaSaver2/SaverPlayground/Assets.xcassets/mozilla.imageset/mozilla.png; sourceTree = "<group>"; };
F84D98FE1F9D2350006F8331 /* SpriteKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SpriteKit.framework; path = System/Library/Frameworks/SpriteKit.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
F84D98E21F9D1FD1006F8331 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F84D98FF1F9D2350006F8331 /* SpriteKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -34,6 +53,7 @@
children = (
F84D98E81F9D1FD1006F8331 /* Mozilla */,
F84D98E71F9D1FD1006F8331 /* Products */,
F84D98FD1F9D2350006F8331 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand All @@ -48,20 +68,37 @@
F84D98E81F9D1FD1006F8331 /* Mozilla */ = {
isa = PBXGroup;
children = (
F84D98ED1F9D1FD1006F8331 /* Info.plist */,
F84D98E91F9D1FD1006F8331 /* MozillaView.h */,
F84D98EB1F9D1FD1006F8331 /* MozillaView.m */,
F84D98ED1F9D1FD1006F8331 /* Info.plist */,
F84D98F31F9D2052006F8331 /* MozillaScene.h */,
F84D98F41F9D2052006F8331 /* MozillaScene.m */,
F84D98F71F9D22C5006F8331 /* firefox-logo-developer-edition.png */,
F84D98FA1F9D22C5006F8331 /* firefox-logo-focus.png */,
F84D98F91F9D22C5006F8331 /* firefox-logo-nightly.png */,
F84D98F81F9D22C5006F8331 /* firefox-logo.png */,
F84D98FB1F9D22C5006F8331 /* mozilla-mask.png */,
F84D98FC1F9D22C6006F8331 /* mozilla.png */,
);
path = Mozilla;
sourceTree = "<group>";
};
F84D98FD1F9D2350006F8331 /* Frameworks */ = {
isa = PBXGroup;
children = (
F84D98FE1F9D2350006F8331 /* SpriteKit.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
F84D98E31F9D1FD1006F8331 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
F84D98F51F9D2052006F8331 /* MozillaScene.h in Headers */,
F84D98EA1F9D1FD1006F8331 /* MozillaView.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -124,6 +161,12 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F84D99031F9D2457006F8331 /* firefox-logo.png in Resources */,
F84D99001F9D2457006F8331 /* firefox-logo-developer-edition.png in Resources */,
F84D99021F9D2457006F8331 /* firefox-logo-nightly.png in Resources */,
F84D99041F9D2457006F8331 /* mozilla-mask.png in Resources */,
F84D99051F9D2457006F8331 /* mozilla.png in Resources */,
F84D99011F9D2457006F8331 /* firefox-logo-focus.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -135,6 +178,7 @@
buildActionMask = 2147483647;
files = (
F84D98EC1F9D1FD1006F8331 /* MozillaView.m in Sources */,
F84D98F61F9D2052006F8331 /* MozillaScene.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -189,7 +233,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -238,7 +282,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
Expand Down
14 changes: 14 additions & 0 deletions Mozilla/MozillaScene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#import <SpriteKit/SpriteKit.h>
#import <Cocoa/Cocoa.h>

@interface MozillaScene : SKScene {
BOOL _isPreview;
}
@property NSInteger logoIndex;
@property SKSpriteNode *logo;
- (instancetype) initWithSize:(CGSize)size isPreview: (BOOL) isPreview;
@end
144 changes: 144 additions & 0 deletions Mozilla/MozillaScene.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

@import SpriteKit;

#import "MozillaScene.h"

CGFloat RandomScaleFactor() {
u_int32_t r = random() % 1000;
if (r > 900) {
return 0.5; // * (isPreview ? PreviewScaleFactor : 1.0);
} else if (r > 450) {
return 0.125; // * (isPreview ? PreviewScaleFactor : 1.0);
} else {
return 0.25; // * (isPreview ? PreviewScaleFactor : 1.0);
}
}

CGSize RandomSize() {
u_int32_t r = random() % 100;
if (r < 75) {
return CGSizeMake(64, 64);
}
return CGSizeMake(96, 96);
}

CGFloat RandomAngularVelocity() {
CGFloat v = -35.0 + (random() % 70);
return v / 100.0;
}

CGVector RandomVelocity() {
return CGVectorMake(-250 + (random() % 500), -50 + (random() % 100));
}

NSString *RandomIconName() {
switch (random() % 4) {
case 0:
return @"firefox-logo";
break;
case 1:
return @"firefox-logo-focus";
break;
case 2:
return @"firefox-logo-nightly";
break;
case 3:
return @"firefox-logo-developer-edition";
break;
}
return @"firefox-logo";
}

@implementation MozillaScene

- (id) initWithSize:(CGSize)size isPreview: (BOOL) isPreview {
if (self = [super initWithSize: size]) {
_isPreview = isPreview;
}
return self;
}

-(void)didMoveToView:(SKView *)view {
[super didMoveToView: view];

self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect: NSInsetRect(self.frame, -200, -200)];
self.physicsBody.categoryBitMask = 0x01;
self.physicsWorld.contactDelegate = self;

self.backgroundColor = NSColor.blackColor;

self.logo = [SKSpriteNode spriteNodeWithImageNamed: [[NSBundle bundleForClass: [self class]] pathForImageResource: @"mozilla"]];
if (self.logo != nil) {
self.logo.position = CGPointMake(view.frame.size.width / 2, view.frame.size.height / 2);

CGFloat offsetX = self.logo.frame.size.width * self.logo.anchorPoint.x;
CGFloat offsetY = self.logo.frame.size.height * self.logo.anchorPoint.y;

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 3 - offsetX, 103 - offsetY);
CGPathAddLineToPoint(path, NULL, 479 - offsetX, 96 - offsetY);
CGPathAddLineToPoint(path, NULL, 496 - offsetX, 146 - offsetY);
CGPathAddLineToPoint(path, NULL, 577 - offsetX, 146 - offsetY);
CGPathAddLineToPoint(path, NULL, 568 - offsetX, 95 - offsetY);
CGPathAddLineToPoint(path, NULL, 631 - offsetX, 100 - offsetY);
CGPathAddLineToPoint(path, NULL, 661 - offsetX, 87 - offsetY);
CGPathAddLineToPoint(path, NULL, 664 - offsetX, 63 - offsetY);
CGPathAddLineToPoint(path, NULL, 673 - offsetX, 5 - offsetY);
CGPathAddLineToPoint(path, NULL, 3 - offsetX, 1 - offsetY);
CGPathCloseSubpath(path);

self.logo.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromPath: path];
//logo.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath: path]; Gives odd results - maybe the path is incorrect?
self.logo.physicsBody.dynamic = NO;
self.logo.physicsBody.density = 10.0;
self.logo.physicsBody.mass = 1000;

[self addChild: self.logo];
}

SKAction *createIconAction = [SKAction runBlock:^{
SKSpriteNode *icon = [SKSpriteNode spriteNodeWithImageNamed: [[NSBundle bundleForClass: [self class]] pathForImageResource: RandomIconName()]];
icon.position = CGPointMake(random() % (u_int32_t) CGRectGetWidth(self.frame), 700);
icon.size = RandomSize();
icon.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius: icon.size.width / 2];
icon.physicsBody.dynamic = YES;
icon.physicsBody.restitution = 0.33;
icon.physicsBody.angularDamping = 0.5;
icon.physicsBody.friction = 0.5;
icon.physicsBody.density = 2.5;
icon.physicsBody.angularVelocity = RandomAngularVelocity();
icon.physicsBody.velocity = RandomVelocity();
icon.physicsBody.categoryBitMask = 0x02;
icon.physicsBody.contactTestBitMask = 0x01;
[self addChild: icon];
}];

SKAction *loopAction = [SKAction sequence: @[[SKAction waitForDuration: 0.25], createIconAction]];

[self runAction: [SKAction repeatActionForever: loopAction]];

//

SKAction *sequence = [SKAction sequence: @[[SKAction waitForDuration: 5.0], [SKAction runBlock:^{
if (self.scene.children.count >= 20) {
SKAction *rotate = [SKAction rotateByAngle: 2*3.14 * (random() % 2 ? 1 : -1) duration: 5.0];
rotate.timingMode = SKActionTimingEaseInEaseOut;
[self.logo runAction: rotate];
}
}]]];
[self runAction: [SKAction repeatActionForever: sequence]];
}

-(void)didBeginContact:(SKPhysicsContact *)contact {
if (contact.bodyA.categoryBitMask == 0x02 && contact.bodyB.categoryBitMask == 0x01) {
[contact.bodyA.node removeFromParent];
}
if (contact.bodyB.categoryBitMask == 0x02 && contact.bodyA.categoryBitMask == 0x01) {
[contact.bodyB.node removeFromParent];
}
}

@end
21 changes: 13 additions & 8 deletions Mozilla/MozillaView.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
//
// MozillaView.h
// Mozilla
//
// Created by Stefan Arentz on 2017-10-22.
// Copyright © 2017 Stefan Arentz. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#import <SpriteKit/SpriteKit.h>
#import <ScreenSaver/ScreenSaver.h>

@interface MozillaView : ScreenSaverView
@class MozillaScene;

@interface MozillaView : ScreenSaverView {
SKView *_sceneView;
MozillaScene *_scene;
}

@property SKView *sceneView;
@property MozillaScene *scene;

@end
57 changes: 23 additions & 34 deletions Mozilla/MozillaView.m
Original file line number Diff line number Diff line change
@@ -1,51 +1,40 @@
//
// MozillaView.m
// Mozilla
//
// Created by Stefan Arentz on 2017-10-22.
// Copyright © 2017 Stefan Arentz. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#import "MozillaScene.h"
#import "MozillaView.h"

@implementation MozillaView

- (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
self = [super initWithFrame:frame isPreview:isPreview];
if (self) {
[self setAnimationTimeInterval:1/30.0];
}
return self;
@interface MySKView: SKView {
}
@end

- (void)startAnimation
{
[super startAnimation];
@implementation MySKView
-(BOOL)acceptsFirstResponder {
return NO;
}
@end

- (void)stopAnimation
{
[super stopAnimation];
}
#pragma mark -

- (void)drawRect:(NSRect)rect
{
[super drawRect:rect];
}
@implementation MozillaView

- (void)animateOneFrame
{
return;
- (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview {
if (self = [super initWithFrame:frame isPreview:isPreview]) {
self.sceneView = [[MySKView alloc] initWithFrame: self.frame];
self.sceneView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
[self addSubview: self.sceneView];
self.scene = [[MozillaScene alloc] initWithSize: self.frame.size isPreview: NO]; // TODO _isPreview?
[self.sceneView presentScene: self.scene];
}
return self;
}

- (BOOL)hasConfigureSheet
{
- (BOOL)hasConfigureSheet {
return NO;
}

- (NSWindow*)configureSheet
{
- (NSWindow*)configureSheet {
return nil;
}

Expand Down

0 comments on commit 08b78b1

Please sign in to comment.