Git Product home page Git Product logo

c4labs / c4ios Goto Github PK

View Code? Open in Web Editor NEW
979.0 51.0 75.0 66.53 MB

C4 is an open-source creative coding framework that harnesses the power of native iOS programming with a simplified API that gets you working with media right away. Build artworks, design interfaces and explore new possibilities working with media and interaction.

Home Page: www.c4ios.com

License: MIT License

Swift 99.39% Objective-C 0.35% Ruby 0.26%
swift uikit creative-coding

c4ios's Introduction

C4

Code, Creatively.

C4 is an open-source creative coding framework that harnesses the power of native iOS programming with a simplified API that gets you working with media right away. Build artworks, design interfaces and explore new possibilities working with media and interaction.

Built on top of Swift, C4 puts the power of UIKit and Core Animation at your disposal, allowing you to create inventive digital interactions with far less time and effort. Plus, you get all the interactivity, fun and expressiveness of Swift. Your apps will run lightning-fast.

The API of C4 is simple and streamlined allowing beginners to get into programming very easily. For seasoned developers, C4 can be dropped into any existing project with as little effort as linking any other native framework. With C4, you’ll save a ton of time when working with interactions, animation and media.

Expressive

C4 brings your ideas to life by allowing you to focus on experimenting, designing, visualizing and building rather than on learning low-level technologies. Objects are consistent and intuitive—they all essentially work the same way. C4's language has been designed to be as simple and expressive as possible.

For example, C4 compresses the access of properties:

let m = movie.width

Instead of this:

let m = movie.frame.size.width

Animating both view and property changes in C4 is much cleaner, and looks like this:

ViewAnimation(duration: 0.5) {
  shape.center = self.canvas.center
  shape.lineWidth = 5
}.animate()

Whereas using UIKit + Core Animation you'd have to do something like this:

UIView.animate(withDuration: 0.5) {
    v.center = self.view.center
}

CATransaction.begin()
CATransaction.setValue(0.5, forKey: kCATransactionAnimationDuration)
if let shapeLayer = v.layer as? CAShapeLayer {
    shapeLayer.lineWidth = 5
}
CATransaction.commit()

C4 takes advantage of all of Swift’s modernity: closures, tuples, generics, interaction, structs, error handling. And, YES, you can even do this:

let bananaName = "Jimmy".banana

Check the Swift Overview for more.

Easy To Learn

Through both its simplified API and consistent objects, C4 is incredibly easy to learn compared to the frameworks it’s built upon: UIKit, Core Animation, etc. C4’s language has been designed to make it easy for both novice and experienced programmers to pick up and use right away.

Well Supported

The C4 team has always been highly committed to publishing excellent documentation, examples and tutorials for learning how to program with C4.

The current release of C4 also includes a full end-to-end tutorial that will walk you through the design, creation and publication of a full-blown app: COSMOS

Get COSMOS from the App Store

Build COSMOS from start to finish

We’re currently converting over 200 code examples and 30 tutorials to C4's new modern syntax. These examples and tutorials (coming soon) guide new users through core concepts and provide seasoned developers with the reference they need to keep up the pace.

Powerful

Originally based on Objective-C, C4 now takes entire advantage of the Swift programming language — which itself was built to be fast and powerful. Where Swift has been tuned to make intuitive, natural coding perform best, the guts of each component in C4 — every class, every method and every structure –  make that performance sing.

Through C4 you are able to work with media, animations and interactions in a way that dissolves the differences between the many frameworks you need to create beautiful user experiences. It seamlessly combines many important components of UIKit, Core Animation, Core Graphics, AVFoundation and QuartzCore.

Multipurpose

C4 is built for anyone who wants to build beautiful user experiences for iOS and has been designed to reach an incredibly broad set of possible uses. This flexibility is one of the most important aspects of C4, demonstrating its strength across a variety of different use cases and disciplines.

C4 has been used for:

  • Prototyping
  • Mobile Applications
  • Data Visualization
  • Interactive Artworks
  • Computational Design Education
  • Communication Design
  • Print Design

Simplicity

Simplicity is a major accomplishment for C4. Across the board, C4 is simple to learn, to use, to read and to adopt. C4 reduces the amount of code you need to the most powerful essentials.

Take movies, for example. Instead of needing to AVQueuePlayer, AVPlayerItem, navigating asset tracks and learning how to load files through NSBundle, you only have to create a movie from its file name and add it to the canvas:

func setup() {
  let movie = Movie("halo.mp4")
  canvas.add(movie)
  movie?.play()
}

Using UIKit + AVFoundation, you'd have to construct the movie object from scratch like this:

func viewDidLoad() {
  guard let url = Bundle.main.url(forResource: "halo.mp4", withExtension: nil) else {
      fatalError("File not found")
  }

  let asset = AVAsset(url: url)
  let player = AVQueuePlayer(playerItem: AVPlayerItem(asset: asset))
  player.actionAtItemEnd = .pause

  let movieLayer = AVPlayerLayer(player: player)
  movieLayer.videoGravity = .resize

  let tracks = asset.tracks(withMediaType: .video)

  let movieTrack = tracks[0]
  let size = movieTrack.naturalSize

  movieLayer.frame = CGRect(x: 0,y: 0,width: size.width,height: size.height)
  self.view.layer.addSublayer(movieLayer)
  player.play()
}

… And a whole lot more.

Open Source

C4 is an open-source project licensed under the MIT License. It can be used freely in educational, artistic and even professional settings. The project is open to anyone who wants to contribute, and the project’s code, documentation, and process are completely available for you to read through, learn from and take advantage of. Ongoing commitment by our core team and other developers guarantees that C4 will be constantly updated and focused on user’s interests.

Contributing

There are many ways to contribute to C4 and we really appreciate any contributions. It can be anything from better documentation to a brand new feature. To get started take a look at our Contribution Guidelines.

Community

Join our Slack channel to ask for help, show off your app, suggest change, or just chat.

c4ios's People

Contributors

3lvis avatar alejandro-isaza avatar buza avatar c4code avatar ha1f avatar ic-64 avatar jancassio avatar jbloit avatar luketurvey avatar mikeocasio avatar ollstar avatar raburski avatar schwarrrtz avatar sebastianvarela avatar tnantoka avatar traviskirton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

c4ios's Issues

addition: constant rotation...

not sure how to implement this
many students have asked how-to... but i'm not sure yet...
the implicit transforms rotate to the nearest angle, (i.e. they will treat TWO_PI as if it were 0)

Points inside a C4Shape / Polygon

It's possible to access the points inside a C4Shape which is a line... using shape.pointA and shape.pointB

Is it possible to have access to all the points in a polygon?
Or, at least return an array of the points inside the polygon?
There should also be a reference to the number of points inside the shape as well.

Video Frame/Orientation Issue

If I import a video and it's in "portrait" orientation, c4movie squishes it into "landscape" orientation without rotating it. I used my ipod to capture the video.

Here is a work around:

CGRect newFrame = newMovie.frame;
CGSize newSize = CGSizeMake(newFrame.size.height, newFrame.size.width);
newFrame.size = newSize;
newMovie.frame = newFrame;

newMovie.center = CGPointMake(384,512);

Can't pause / stop an animation

The ability to pause / stop an animation should be added in the coming design phase.
And, the ability to resume as well...

mpeg

C4Movie crashed when creating with an mpeg..
Should check this, or any other file types...

addition: easier rotations

The following is awkward, we should make this easier...

polygon.transform = CGAffineTransformMakeRotation(-PI/2);

Gesture settings not taking effect

for the following code:

myCustomShape = [CustomShape new];
[myCustomShape rect:CGRectMake(284, 412, 200, 200)];

[myCustomShape addGesture:TAP name:@"singleTap" action:@"methodA"];
[myCustomShape addGesture:TAP name:@"doubleTap" action:@"methodB"];

[myCustomShape numberOfTapsRequired:1 forGesture:@"singleTap"];
[myCustomShape numberOfTapsRequired:2 forGesture:@"doubleTap"];

[self.canvas addShape:myCustomShape];

the gestures aren't setting the right number of taps...

the @"doubleTap" gesture triggers only with a single tap

Initial animations on shapes...

There is an initial animation with shapes when they are added to the canvas...
Try to get rid of these....

This may have to do with where Setup is called in the application launch hierarchy, and to guarantee that the animation time is set to 0, rather than the implicit 0.25

self.canvas doesn't have gestures

you can't easily add gestures to the canvas, like adding them to objects...
it would be nice if gestures were incorporated into this as well...

documentation: add short examples?

michael wylegly suggested adding short examples to the documentation writeup for each method...
a lot of work, but probably very useful

PointA, PointB issue

setting pointA for a line seems to work fine, but setting pointB results in a weird movement of the line...

addition: remove / delete object

there should be remove / delete object methods...
remove would take something off the canvas
delete would take something off the canvas and then delete the object from memory

listenfor ... OBJECTS?

is it possible to include a method for listening to multiple objects at the same time?

example:

listenFor:@"something" fromObjects:(NSArray *)anArrayOfObjects andRunMethod: ...

Might be handy...

addition: complex shapes

should add functionality to create complex shapes...

C4Shape *complex = [C4Line ...];
[complex addEllipse:]
[complex appendEllipse];
etc...

image.width, image.height?

You should be able to set the image.width property, like working with movies.
perhaps there should also be a image.constrainsProportions = YES property

C4Movie interaction issue?

I had to pause the movie before playing again after changing the rate... should this be the way it works????
Maybe setting rate should pause, then play?

General Animation Issue

People keep asking "how do i animate from here, to here and when the first animation is done, trigger a second animation?"

this is a serious design consideration for the coming development phase

strange habit with assigning shapes

myshape =
followed by
myshape =
invalidates the shape...

not sure exactly what is happening here...
will have to test this after the workshops are done and i can focus better.

arcs are broken

creating arcs doesn't work...
there's a bunch of problems with them...
they need to be thoroughly tested

Animation Interaction Bug ?

When an animation is in progress, and was triggered by touchesBegan, touching the canvas a second time really messes with the way the animation looks.

Perhaps there should be a way of blocking interaction when something is animating, or of being able to reset the animation more smoothly when this happens.

shape frames not set properly in setup{}

in the setup method, when a shape is created, it takes longer to build the path than to set its new center position...
so if i write

shape = [C4Shape rect:];
shape.center = CGPoint;

the shape stays in its original rect...

not sure how to get around this...

addition: animation control

We need to find a way to be able to get animations to slow down and/or stop mid-animation, as well as modify current animations and also to be able to set the current time of the animation (something akin to scrubbing in a movie).

chaining animations...

there should be an easy way of chaining animations...
like a callback or something... but a very simple way of triggering things

you should also look into setting multiple kinds of animation options in a row... this needs to be tested
i.e.

option
delay
set property
option
set property
option
duration
set property

in the same block of code for a single object...

for instance
duration = 1
move
duration = 2
change color

so the object moves for 1 second and changes color for 2 seconds...

lack of framerate?... need to think of a workaround

there is no framerate in C4iOS... on purpose.
the intention is to update things only when they need to be updated, and to let the system handle a lot of the animation implicitly.
this raises issues, though, because a lot of ideology (especially in creative coding languages) relies on the concept of a framerate and things being updated 30fps or whatever...
this impacts any kind of Vector class... because particle / physics / vector systems necessarily need some kind of update function.
also, the technique for rendering a lot of these systems uses a frame-based drawing technique (e.g. draw circle at X,Y now) and doesn't think about using some kind of implicit animations...
i am not sure how to get around this kind of thing, or if it needs to be got around at all...

NSView animations flicker...

Any time an NSView animation uses AUTOREVERSE, without repeating, the animation flickers at the end...
This happens no matter what... with moving the view, or even changing its alpha...
I think this is a problem with Apple's view animation... That is, I don't think I can work around this on my own with views themselves... which is too bad...

I tried a variety of different ways of setting things with completion handlers, but even some of the techniques in the O'Reilly book iOS5 Programming do not work... though the author says they should...

[image colorInvert] didn't work on one computer

Strangely, the [image colorInvert] method didn't do anything on one computer... but it generally works on all other computers...
Not sure why this would happen, if the computers have the same configuration

setup{} doesn't get called when initializing shapes with new

myCustomShape = [CustomShape new];

doesn't call (located in CustomShape.m):

-(void)setup {
    C4Log(@"setup");
    [self addGesture:TAP name:@"singleTap" action:@"methodA"];
    [self addGesture:TAP name:@"doubleTap" action:@"methodB"];

    [self numberOfTapsRequired:1 forGesture:@"singleTap"];
    [self numberOfTapsRequired:2 forGesture:@"doubleTap"];
}

Text Shapes have no frames?

When a shape is made using shapeFromString: it seems to not have a frame.
The origin is at the bottom-left of the object (instead of the typical top-right).

documentation: add short examples?

michael wylegly suggested adding short examples to the documentation writeup for each method...
a lot of work, but probably very useful

Begin from current value for CALayer transitions not working

When applying the BEGINCURRENT animation option to a C4Shape object, in the middle of an ongoing animation, the visible state of the object flicks back to its original state before initiating a new animation.

The expected behaviour for the following is to animate from C4GREY to C4RED over 5 seconds. At 2.5 seconds the current colour (mix of grey / red) should begin smoothly animating to C4BLUE.

@implementation C4WorkSpace {
    C4Shape *s;
}

- (void)setup {
    s = [C4Shape ellipse:CGRectMake(0, 0, 100, 100)];
    s.center = self.canvas.center;
    [self.canvas addShape:s];

    s.animationDuration = 5.0f;
    s.animationOptions = BEGINCURRENT;
    s.fillColor = C4RED;

    [self runMethod:@"test" afterDelay:2.5];
}

-(void)test {
    s.fillColor = C4BLUE;
}
@end

This causes the fillColor of the shape to flick back to C4GREY before animating to C4BLUE.

Masks & Animations

Add masks and make them animated, for images (first) and then for any other C4Control (if possible)

Global Settings? or, settings object?

There should be an easy way to set global settings for all objects of a particular class.
For instance, shapes... So that you don't have to individually change the colors of each shape as you create them.

whitespace truncation would be nice

would be nice to have some whitespace truncation for names in strings being passed to things...
just a small addition that might make things simpler...
perhaps not... who knows...

e.g. to handle things like: @" image.jpg", or @"image.jpg "

installer doesn't work for xcode 4.3 in osx 10.7.3

the installer doesn't work because the path to where template files should be located has changed...
i worked around this with greg, and his setup is now able to generate projects from the template, but i haven't yet added this to a 10.7.3 installer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.